2018-10-15 16:37:21 -05:00
|
|
|
|
/*
|
|
|
|
|
* Tests of MFM
|
|
|
|
|
*/
|
|
|
|
|
|
2018-05-17 19:21:19 -05:00
|
|
|
|
import * as assert from 'assert';
|
2017-02-11 10:03:57 -06:00
|
|
|
|
|
2018-06-20 11:21:57 -05:00
|
|
|
|
import analyze from '../src/mfm/parse';
|
2018-09-16 12:45:30 -05:00
|
|
|
|
import toHtml from '../src/mfm/html';
|
2018-12-21 09:41:54 -06:00
|
|
|
|
import { createTree as tree, createLeaf as leaf, MfmTree, removeOrphanedBrackets } from '../src/mfm/parser';
|
2018-11-20 14:11:00 -06:00
|
|
|
|
|
2018-12-20 04:41:04 -06:00
|
|
|
|
function text(text: string): MfmTree {
|
|
|
|
|
return leaf('text', { text });
|
2018-11-20 14:11:00 -06:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-20 04:41:04 -06:00
|
|
|
|
describe('createLeaf', () => {
|
|
|
|
|
it('creates leaf', () => {
|
|
|
|
|
assert.deepStrictEqual(leaf('text', { text: 'abc' }), {
|
|
|
|
|
node: {
|
|
|
|
|
type: 'text',
|
|
|
|
|
props: {
|
|
|
|
|
text: 'abc'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
children: [],
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-11-20 14:11:00 -06:00
|
|
|
|
|
2018-12-20 04:41:04 -06:00
|
|
|
|
describe('createTree', () => {
|
|
|
|
|
it('creates tree', () => {
|
|
|
|
|
const t = tree('tree', [
|
|
|
|
|
leaf('left', { a: 2 }),
|
|
|
|
|
leaf('right', { b: 'hi' })
|
|
|
|
|
], {
|
2019-01-20 02:44:52 -06:00
|
|
|
|
c: 4
|
|
|
|
|
});
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(t, {
|
|
|
|
|
node: {
|
|
|
|
|
type: 'tree',
|
|
|
|
|
props: {
|
|
|
|
|
c: 4
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
children: [
|
|
|
|
|
leaf('left', { a: 2 }),
|
|
|
|
|
leaf('right', { b: 'hi' })
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-12-29 22:28:56 -06:00
|
|
|
|
|
2018-12-21 09:41:54 -06:00
|
|
|
|
describe('removeOrphanedBrackets', () => {
|
|
|
|
|
it('single (contained)', () => {
|
|
|
|
|
const input = '(foo)';
|
|
|
|
|
const expected = '(foo)';
|
|
|
|
|
const actual = removeOrphanedBrackets(input);
|
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('single (head)', () => {
|
|
|
|
|
const input = '(foo)bar';
|
|
|
|
|
const expected = '(foo)bar';
|
|
|
|
|
const actual = removeOrphanedBrackets(input);
|
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('single (tail)', () => {
|
|
|
|
|
const input = 'foo(bar)';
|
|
|
|
|
const expected = 'foo(bar)';
|
|
|
|
|
const actual = removeOrphanedBrackets(input);
|
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('a', () => {
|
|
|
|
|
const input = '(foo';
|
|
|
|
|
const expected = '';
|
|
|
|
|
const actual = removeOrphanedBrackets(input);
|
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('b', () => {
|
|
|
|
|
const input = ')foo';
|
|
|
|
|
const expected = '';
|
|
|
|
|
const actual = removeOrphanedBrackets(input);
|
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('nested', () => {
|
|
|
|
|
const input = 'foo(「(bar)」)';
|
|
|
|
|
const expected = 'foo(「(bar)」)';
|
|
|
|
|
const actual = removeOrphanedBrackets(input);
|
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('no brackets', () => {
|
|
|
|
|
const input = 'foo';
|
|
|
|
|
const expected = 'foo';
|
|
|
|
|
const actual = removeOrphanedBrackets(input);
|
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with foreign bracket (single)', () => {
|
|
|
|
|
const input = 'foo(bar))';
|
|
|
|
|
const expected = 'foo(bar)';
|
|
|
|
|
const actual = removeOrphanedBrackets(input);
|
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with foreign bracket (open)', () => {
|
|
|
|
|
const input = 'foo(bar';
|
|
|
|
|
const expected = 'foo';
|
|
|
|
|
const actual = removeOrphanedBrackets(input);
|
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with foreign bracket (close)', () => {
|
|
|
|
|
const input = 'foo)bar';
|
|
|
|
|
const expected = 'foo';
|
|
|
|
|
const actual = removeOrphanedBrackets(input);
|
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with foreign bracket (close and open)', () => {
|
|
|
|
|
const input = 'foo)(bar';
|
|
|
|
|
const expected = 'foo';
|
|
|
|
|
const actual = removeOrphanedBrackets(input);
|
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('various bracket type', () => {
|
|
|
|
|
const input = 'foo「(bar)」(';
|
|
|
|
|
const expected = 'foo「(bar)」';
|
|
|
|
|
const actual = removeOrphanedBrackets(input);
|
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('intersected', () => {
|
|
|
|
|
const input = 'foo(「)」';
|
|
|
|
|
const expected = 'foo(「)」';
|
|
|
|
|
const actual = removeOrphanedBrackets(input);
|
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2018-12-20 04:41:04 -06:00
|
|
|
|
describe('MFM', () => {
|
2018-01-21 00:49:31 -06:00
|
|
|
|
it('can be analyzed', () => {
|
2018-04-08 11:10:04 -05:00
|
|
|
|
const tokens = analyze('@himawari @hima_sub@namori.net お腹ペコい :cat: #yryr');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('mention', { acct: '@himawari', canonical: '@himawari', username: 'himawari', host: null }),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text(' '),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('mention', { acct: '@hima_sub@namori.net', canonical: '@hima_sub@namori.net', username: 'hima_sub', host: 'namori.net' }),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text(' お腹ペコい '),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('emoji', { name: 'cat' }),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text(' '),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('hashtag', { hashtag: 'yryr' }),
|
|
|
|
|
]);
|
2016-12-29 22:28:56 -06:00
|
|
|
|
});
|
|
|
|
|
|
2017-02-28 23:29:02 -06:00
|
|
|
|
describe('elements', () => {
|
2018-11-20 14:11:00 -06:00
|
|
|
|
describe('bold', () => {
|
|
|
|
|
it('simple', () => {
|
|
|
|
|
const tokens = analyze('**foo**');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('bold', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with other texts', () => {
|
|
|
|
|
const tokens = analyze('bar**foo**bar');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('bar'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
tree('bold', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('bar'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
2017-02-28 23:29:02 -06:00
|
|
|
|
});
|
2017-02-11 10:01:35 -06:00
|
|
|
|
|
2018-08-03 09:27:37 -05:00
|
|
|
|
it('big', () => {
|
|
|
|
|
const tokens = analyze('***Strawberry*** Pasta');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('big', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('Strawberry')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text(' Pasta'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-08-03 09:27:37 -05:00
|
|
|
|
});
|
|
|
|
|
|
2018-12-05 05:11:54 -06:00
|
|
|
|
it('small', () => {
|
|
|
|
|
const tokens = analyze('<small>smaller</small>');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('small', [
|
2018-12-05 05:11:54 -06:00
|
|
|
|
text('smaller')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-12-05 05:11:54 -06:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-20 14:11:00 -06:00
|
|
|
|
describe('motion', () => {
|
|
|
|
|
it('by triple brackets', () => {
|
|
|
|
|
const tokens = analyze('(((foo)))');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('motion', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
2018-08-05 09:56:08 -05:00
|
|
|
|
|
2018-11-20 14:11:00 -06:00
|
|
|
|
it('by triple brackets (with other texts)', () => {
|
|
|
|
|
const tokens = analyze('bar(((foo)))bar');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('bar'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
tree('motion', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('bar'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('by <motion> tag', () => {
|
|
|
|
|
const tokens = analyze('<motion>foo</motion>');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('motion', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('by <motion> tag (with other texts)', () => {
|
|
|
|
|
const tokens = analyze('bar<motion>foo</motion>bar');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('bar'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
tree('motion', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('bar'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
2018-08-04 22:33:51 -05:00
|
|
|
|
});
|
|
|
|
|
|
2018-09-30 00:46:18 -05:00
|
|
|
|
describe('mention', () => {
|
|
|
|
|
it('local', () => {
|
2018-11-20 14:11:00 -06:00
|
|
|
|
const tokens = analyze('@himawari foo');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('mention', { acct: '@himawari', canonical: '@himawari', username: 'himawari', host: null }),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text(' foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-09-30 00:46:18 -05:00
|
|
|
|
});
|
2017-02-11 10:01:35 -06:00
|
|
|
|
|
2018-09-30 00:46:18 -05:00
|
|
|
|
it('remote', () => {
|
2018-11-20 14:11:00 -06:00
|
|
|
|
const tokens = analyze('@hima_sub@namori.net foo');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('mention', { acct: '@hima_sub@namori.net', canonical: '@hima_sub@namori.net', username: 'hima_sub', host: 'namori.net' }),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text(' foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-10-14 02:56:19 -05:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('remote punycode', () => {
|
2018-11-20 14:11:00 -06:00
|
|
|
|
const tokens = analyze('@hima_sub@xn--q9j5bya.xn--zckzah foo');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('mention', { acct: '@hima_sub@xn--q9j5bya.xn--zckzah', canonical: '@hima_sub@なもり.テスト', username: 'hima_sub', host: 'xn--q9j5bya.xn--zckzah' }),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text(' foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-09-30 00:46:18 -05:00
|
|
|
|
});
|
2018-11-16 06:57:19 -06:00
|
|
|
|
|
2018-09-30 00:46:18 -05:00
|
|
|
|
it('ignore', () => {
|
|
|
|
|
const tokens = analyze('idolm@ster');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('idolm@ster')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-09-30 00:46:18 -05:00
|
|
|
|
|
|
|
|
|
const tokens2 = analyze('@a\n@b\n@c');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens2, [
|
|
|
|
|
leaf('mention', { acct: '@a', canonical: '@a', username: 'a', host: null }),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('\n'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('mention', { acct: '@b', canonical: '@b', username: 'b', host: null }),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('\n'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('mention', { acct: '@c', canonical: '@c', username: 'c', host: null })
|
|
|
|
|
]);
|
2018-09-30 00:46:18 -05:00
|
|
|
|
|
|
|
|
|
const tokens3 = analyze('**x**@a');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens3, [
|
|
|
|
|
tree('bold', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('x')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
|
|
|
|
leaf('mention', { acct: '@a', canonical: '@a', username: 'a', host: null })
|
|
|
|
|
]);
|
2018-12-17 04:11:38 -06:00
|
|
|
|
|
2019-01-20 02:44:52 -06:00
|
|
|
|
const tokens4 = analyze('@\n@v\n@veryverylongusername' /* \n@toolongtobeasamention */);
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens4, [
|
2018-12-17 04:11:38 -06:00
|
|
|
|
text('@\n'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('mention', { acct: '@v', canonical: '@v', username: 'v', host: null }),
|
2018-12-17 04:11:38 -06:00
|
|
|
|
text('\n'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('mention', { acct: '@veryverylongusername', canonical: '@veryverylongusername', username: 'veryverylongusername', host: null }),
|
2018-12-17 04:11:38 -06:00
|
|
|
|
// text('\n@toolongtobeasamention')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-12-17 04:11:38 -06:00
|
|
|
|
/*
|
|
|
|
|
const tokens5 = analyze('@domain_is@valid.example.com\n@domain_is@.invalid\n@domain_is@invali.d\n@domain_is@invali.d\n@domain_is@-invalid.com\n@domain_is@invalid-.com');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual([
|
|
|
|
|
leaf('mention', { acct: '@domain_is@valid.example.com', canonical: '@domain_is@valid.example.com', username: 'domain_is', host: 'valid.example.com' }),
|
2018-12-17 04:11:38 -06:00
|
|
|
|
text('\n@domain_is@.invalid\n@domain_is@invali.d\n@domain_is@invali.d\n@domain_is@-invalid.com\n@domain_is@invalid-.com')
|
|
|
|
|
], tokens5);
|
|
|
|
|
*/
|
2018-09-30 00:46:18 -05:00
|
|
|
|
});
|
2018-04-08 11:10:04 -05:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-20 17:30:29 -06:00
|
|
|
|
describe('hashtag', () => {
|
|
|
|
|
it('simple', () => {
|
|
|
|
|
const tokens = analyze('#alice');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('hashtag', { hashtag: 'alice' })
|
|
|
|
|
]);
|
2018-11-20 17:30:29 -06:00
|
|
|
|
});
|
2018-09-17 08:51:10 -05:00
|
|
|
|
|
2018-11-20 17:30:29 -06:00
|
|
|
|
it('after line break', () => {
|
|
|
|
|
const tokens = analyze('foo\n#alice');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 17:30:29 -06:00
|
|
|
|
text('foo\n'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('hashtag', { hashtag: 'alice' })
|
|
|
|
|
]);
|
2018-11-20 17:30:29 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with text', () => {
|
|
|
|
|
const tokens = analyze('Strawberry Pasta #alice');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 17:30:29 -06:00
|
|
|
|
text('Strawberry Pasta '),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('hashtag', { hashtag: 'alice' })
|
|
|
|
|
]);
|
2018-11-20 17:30:29 -06:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-29 05:12:37 -06:00
|
|
|
|
it('with text (zenkaku)', () => {
|
2018-12-01 15:53:57 -06:00
|
|
|
|
const tokens = analyze('こんにちは#世界');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-12-01 15:53:57 -06:00
|
|
|
|
text('こんにちは'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('hashtag', { hashtag: '世界' })
|
|
|
|
|
]);
|
2018-11-29 05:12:37 -06:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-20 17:30:29 -06:00
|
|
|
|
it('ignore comma and period', () => {
|
|
|
|
|
const tokens = analyze('Foo #bar, baz #piyo.');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 17:30:29 -06:00
|
|
|
|
text('Foo '),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('hashtag', { hashtag: 'bar' }),
|
2018-11-20 17:30:29 -06:00
|
|
|
|
text(', baz '),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('hashtag', { hashtag: 'piyo' }),
|
2018-11-20 17:30:29 -06:00
|
|
|
|
text('.'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-20 17:30:29 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('ignore exclamation mark', () => {
|
|
|
|
|
const tokens = analyze('#Foo!');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('hashtag', { hashtag: 'Foo' }),
|
2018-11-20 17:30:29 -06:00
|
|
|
|
text('!'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-20 17:30:29 -06:00
|
|
|
|
});
|
2018-11-23 01:02:17 -06:00
|
|
|
|
|
2019-01-11 23:10:16 -06:00
|
|
|
|
it('ignore colon', () => {
|
|
|
|
|
const tokens = analyze('#Foo:');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('hashtag', { hashtag: 'Foo' }),
|
|
|
|
|
text(':'),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2019-01-16 18:33:08 -06:00
|
|
|
|
it('ignore single quote', () => {
|
|
|
|
|
const tokens = analyze('#foo\'');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('hashtag', { hashtag: 'foo' }),
|
|
|
|
|
text('\''),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2019-01-16 18:24:20 -06:00
|
|
|
|
it('ignore double quote', () => {
|
|
|
|
|
const tokens = analyze('#foo"');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('hashtag', { hashtag: 'foo' }),
|
|
|
|
|
text('"'),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2018-11-24 02:18:11 -06:00
|
|
|
|
it('allow including number', () => {
|
|
|
|
|
const tokens = analyze('#foo123');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('hashtag', { hashtag: 'foo123' }),
|
|
|
|
|
]);
|
2018-11-24 02:18:11 -06:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-24 13:44:42 -06:00
|
|
|
|
it('with brackets', () => {
|
2018-11-26 11:08:51 -06:00
|
|
|
|
const tokens1 = analyze('(#foo)');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens1, [
|
2018-11-24 13:44:42 -06:00
|
|
|
|
text('('),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('hashtag', { hashtag: 'foo' }),
|
2018-11-24 13:44:42 -06:00
|
|
|
|
text(')'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-26 11:08:51 -06:00
|
|
|
|
|
|
|
|
|
const tokens2 = analyze('「#foo」');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens2, [
|
2018-11-26 11:08:51 -06:00
|
|
|
|
text('「'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('hashtag', { hashtag: 'foo' }),
|
2018-11-26 11:08:51 -06:00
|
|
|
|
text('」'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-26 11:08:51 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with mixed brackets', () => {
|
|
|
|
|
const tokens = analyze('「#foo(bar)」');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-26 11:08:51 -06:00
|
|
|
|
text('「'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('hashtag', { hashtag: 'foo(bar)' }),
|
2018-11-26 11:08:51 -06:00
|
|
|
|
text('」'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-24 13:44:42 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with brackets (space before)', () => {
|
2018-11-26 11:08:51 -06:00
|
|
|
|
const tokens1 = analyze('(bar #foo)');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens1, [
|
2018-11-24 13:44:42 -06:00
|
|
|
|
text('(bar '),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('hashtag', { hashtag: 'foo' }),
|
2018-11-24 13:44:42 -06:00
|
|
|
|
text(')'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-26 11:08:51 -06:00
|
|
|
|
|
|
|
|
|
const tokens2 = analyze('「bar #foo」');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens2, [
|
2018-11-26 11:08:51 -06:00
|
|
|
|
text('「bar '),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('hashtag', { hashtag: 'foo' }),
|
2018-11-26 11:08:51 -06:00
|
|
|
|
text('」'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-24 13:44:42 -06:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-23 01:02:17 -06:00
|
|
|
|
it('disallow number only', () => {
|
|
|
|
|
const tokens = analyze('#123');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-23 01:02:17 -06:00
|
|
|
|
text('#123'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-23 01:02:17 -06:00
|
|
|
|
});
|
2018-11-24 13:44:42 -06:00
|
|
|
|
|
|
|
|
|
it('disallow number only (with brackets)', () => {
|
|
|
|
|
const tokens = analyze('(#123)');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-24 13:44:42 -06:00
|
|
|
|
text('(#123)'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-24 13:44:42 -06:00
|
|
|
|
});
|
2017-02-28 23:29:02 -06:00
|
|
|
|
});
|
2017-02-11 10:01:35 -06:00
|
|
|
|
|
2018-11-20 14:11:00 -06:00
|
|
|
|
describe('quote', () => {
|
|
|
|
|
it('basic', () => {
|
|
|
|
|
const tokens1 = analyze('> foo');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens1, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {})
|
|
|
|
|
]);
|
2018-09-19 16:27:41 -05:00
|
|
|
|
|
2018-11-20 14:11:00 -06:00
|
|
|
|
const tokens2 = analyze('>foo');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens2, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {})
|
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
2018-09-20 18:33:24 -05:00
|
|
|
|
|
2018-11-20 14:11:00 -06:00
|
|
|
|
it('series', () => {
|
|
|
|
|
const tokens = analyze('> foo\n\n> bar');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
2018-11-30 19:40:09 -06:00
|
|
|
|
text('\n'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
tree('quote', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('bar')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
2018-09-20 18:33:24 -05:00
|
|
|
|
|
2018-11-20 14:11:00 -06:00
|
|
|
|
it('trailing line break', () => {
|
|
|
|
|
const tokens1 = analyze('> foo\n');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens1, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-10-29 05:09:24 -05:00
|
|
|
|
|
2018-11-20 14:11:00 -06:00
|
|
|
|
const tokens2 = analyze('> foo\n\n');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens2, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('\n')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('multiline', () => {
|
|
|
|
|
const tokens1 = analyze('>foo\n>bar');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens1, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo\nbar')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {})
|
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
|
|
|
|
|
const tokens2 = analyze('> foo\n> bar');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens2, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo\nbar')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {})
|
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('multiline with trailing line break', () => {
|
|
|
|
|
const tokens1 = analyze('> foo\n> bar\n');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens1, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo\nbar')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
|
|
|
|
|
const tokens2 = analyze('> foo\n> bar\n\n');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens2, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo\nbar')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('\n')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with before and after texts', () => {
|
|
|
|
|
const tokens = analyze('before\n> foo\nafter');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-30 19:40:09 -06:00
|
|
|
|
text('before\n'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
tree('quote', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('after'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-30 19:40:09 -06:00
|
|
|
|
it('multiple quotes', () => {
|
|
|
|
|
const tokens = analyze('> foo\nbar\n\n> foo\nbar\n\n> foo\nbar');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('quote', [
|
2018-11-30 19:40:09 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
2018-11-30 19:40:09 -06:00
|
|
|
|
text('bar\n\n'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
tree('quote', [
|
2018-11-30 19:40:09 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
2018-11-30 19:40:09 -06:00
|
|
|
|
text('bar\n\n'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
tree('quote', [
|
2018-11-30 19:40:09 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
2018-11-30 19:40:09 -06:00
|
|
|
|
text('bar'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-30 19:40:09 -06:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-20 14:11:00 -06:00
|
|
|
|
it('require line break before ">"', () => {
|
|
|
|
|
const tokens = analyze('foo>bar');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo>bar'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('nested', () => {
|
|
|
|
|
const tokens = analyze('>> foo\n> bar');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('quote', [
|
|
|
|
|
tree('quote', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('bar')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {})
|
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('trim line breaks', () => {
|
|
|
|
|
const tokens = analyze('foo\n\n>a\n>>b\n>>\n>>>\n>>>c\n>>>\n>d\n\n');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-30 19:40:09 -06:00
|
|
|
|
text('foo\n\n'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
tree('quote', [
|
2018-11-30 19:40:09 -06:00
|
|
|
|
text('a\n'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
tree('quote', [
|
2018-11-30 19:40:09 -06:00
|
|
|
|
text('b\n\n'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
tree('quote', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('\nc\n')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {})
|
|
|
|
|
], {}),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('d')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('\n'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
2018-09-19 16:27:41 -05:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-16 06:57:19 -06:00
|
|
|
|
describe('url', () => {
|
|
|
|
|
it('simple', () => {
|
|
|
|
|
const tokens = analyze('https://example.com');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('url', { url: 'https://example.com' })
|
|
|
|
|
]);
|
2018-11-16 06:57:19 -06:00
|
|
|
|
});
|
2018-11-16 06:30:01 -06:00
|
|
|
|
|
2018-11-16 21:52:20 -06:00
|
|
|
|
it('ignore trailing period', () => {
|
2018-11-16 06:57:19 -06:00
|
|
|
|
const tokens = analyze('https://example.com.');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('url', { url: 'https://example.com' }),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('.')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-16 06:57:19 -06:00
|
|
|
|
});
|
2018-11-16 06:30:01 -06:00
|
|
|
|
|
2018-11-16 06:57:19 -06:00
|
|
|
|
it('with comma', () => {
|
|
|
|
|
const tokens = analyze('https://example.com/foo?bar=a,b');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('url', { url: 'https://example.com/foo?bar=a,b' })
|
|
|
|
|
]);
|
2018-11-16 06:57:19 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('ignore trailing comma', () => {
|
|
|
|
|
const tokens = analyze('https://example.com/foo, bar');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('url', { url: 'https://example.com/foo' }),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text(', bar')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-16 06:57:19 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with brackets', () => {
|
|
|
|
|
const tokens = analyze('https://example.com/foo(bar)');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('url', { url: 'https://example.com/foo(bar)' })
|
|
|
|
|
]);
|
2018-11-16 06:57:19 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('ignore parent brackets', () => {
|
|
|
|
|
const tokens = analyze('(https://example.com/foo)');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('('),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('url', { url: 'https://example.com/foo' }),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text(')')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-16 06:57:19 -06:00
|
|
|
|
});
|
2018-11-16 21:52:20 -06:00
|
|
|
|
|
2018-11-21 14:02:38 -06:00
|
|
|
|
it('ignore parent brackets 2', () => {
|
|
|
|
|
const tokens = analyze('(foo https://example.com/foo)');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-21 14:02:38 -06:00
|
|
|
|
text('(foo '),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('url', { url: 'https://example.com/foo' }),
|
2018-11-21 14:02:38 -06:00
|
|
|
|
text(')')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-21 14:02:38 -06:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-16 21:52:20 -06:00
|
|
|
|
it('ignore parent brackets with internal brackets', () => {
|
|
|
|
|
const tokens = analyze('(https://example.com/foo(bar))');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('('),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('url', { url: 'https://example.com/foo(bar)' }),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text(')')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-16 21:52:20 -06:00
|
|
|
|
});
|
2017-03-17 11:16:32 -05:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-21 14:02:38 -06:00
|
|
|
|
describe('link', () => {
|
|
|
|
|
it('simple', () => {
|
|
|
|
|
const tokens = analyze('[foo](https://example.com)');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('link', [
|
2018-11-21 14:02:38 -06:00
|
|
|
|
text('foo')
|
|
|
|
|
], { url: 'https://example.com', silent: false })
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-21 14:02:38 -06:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-24 22:21:39 -06:00
|
|
|
|
it('simple (with silent flag)', () => {
|
|
|
|
|
const tokens = analyze('?[foo](https://example.com)');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('link', [
|
2018-11-24 22:21:39 -06:00
|
|
|
|
text('foo')
|
|
|
|
|
], { url: 'https://example.com', silent: true })
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-24 22:21:39 -06:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-21 14:02:38 -06:00
|
|
|
|
it('in text', () => {
|
|
|
|
|
const tokens = analyze('before[foo](https://example.com)after');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-21 14:02:38 -06:00
|
|
|
|
text('before'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
tree('link', [
|
2018-11-21 14:02:38 -06:00
|
|
|
|
text('foo')
|
|
|
|
|
], { url: 'https://example.com', silent: false }),
|
|
|
|
|
text('after'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-21 14:02:38 -06:00
|
|
|
|
});
|
2018-11-21 14:04:45 -06:00
|
|
|
|
|
|
|
|
|
it('with brackets', () => {
|
|
|
|
|
const tokens = analyze('[foo](https://example.com/foo(bar))');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('link', [
|
2018-11-21 14:04:45 -06:00
|
|
|
|
text('foo')
|
|
|
|
|
], { url: 'https://example.com/foo(bar)', silent: false })
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-21 14:04:45 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with parent brackets', () => {
|
|
|
|
|
const tokens = analyze('([foo](https://example.com/foo(bar)))');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-21 14:04:45 -06:00
|
|
|
|
text('('),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
tree('link', [
|
2018-11-21 14:04:45 -06:00
|
|
|
|
text('foo')
|
|
|
|
|
], { url: 'https://example.com/foo(bar)', silent: false }),
|
|
|
|
|
text(')')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-21 14:04:45 -06:00
|
|
|
|
});
|
2017-02-28 23:29:02 -06:00
|
|
|
|
});
|
2017-02-28 21:15:45 -06:00
|
|
|
|
|
2017-02-28 23:29:02 -06:00
|
|
|
|
it('emoji', () => {
|
2018-11-03 08:35:24 -05:00
|
|
|
|
const tokens1 = analyze(':cat:');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens1, [
|
|
|
|
|
leaf('emoji', { name: 'cat' })
|
|
|
|
|
]);
|
2018-11-03 08:35:24 -05:00
|
|
|
|
|
|
|
|
|
const tokens2 = analyze(':cat::cat::cat:');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens2, [
|
|
|
|
|
leaf('emoji', { name: 'cat' }),
|
|
|
|
|
leaf('emoji', { name: 'cat' }),
|
|
|
|
|
leaf('emoji', { name: 'cat' })
|
|
|
|
|
]);
|
2018-11-05 05:14:49 -06:00
|
|
|
|
|
|
|
|
|
const tokens3 = analyze('🍎');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens3, [
|
|
|
|
|
leaf('emoji', { emoji: '🍎' })
|
|
|
|
|
]);
|
2017-02-28 23:29:02 -06:00
|
|
|
|
});
|
2017-02-11 10:01:35 -06:00
|
|
|
|
|
2018-11-20 14:11:00 -06:00
|
|
|
|
describe('block code', () => {
|
|
|
|
|
it('simple', () => {
|
|
|
|
|
const tokens = analyze('```\nvar x = "Strawberry Pasta";\n```');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('blockCode', { code: 'var x = "Strawberry Pasta";', lang: null })
|
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can specify language', () => {
|
|
|
|
|
const tokens = analyze('``` json\n{ "x": 42 }\n```');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('blockCode', { code: '{ "x": 42 }', lang: 'json' })
|
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('require line break before "```"', () => {
|
|
|
|
|
const tokens = analyze('before```\nfoo\n```');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('before'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('inlineCode', { code: '`' }),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('\nfoo\n'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
leaf('inlineCode', { code: '`' })
|
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('series', () => {
|
|
|
|
|
const tokens = analyze('```\nfoo\n```\n```\nbar\n```\n```\nbaz\n```');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('blockCode', { code: 'foo', lang: null }),
|
|
|
|
|
leaf('blockCode', { code: 'bar', lang: null }),
|
|
|
|
|
leaf('blockCode', { code: 'baz', lang: null }),
|
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('ignore internal marker', () => {
|
|
|
|
|
const tokens = analyze('```\naaa```bbb\n```');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('blockCode', { code: 'aaa```bbb', lang: null })
|
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('trim after line break', () => {
|
|
|
|
|
const tokens = analyze('```\nfoo\n```\nbar');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('blockCode', { code: 'foo', lang: null }),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('bar')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
2017-02-28 23:29:02 -06:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-20 21:55:15 -06:00
|
|
|
|
describe('inline code', () => {
|
|
|
|
|
it('simple', () => {
|
|
|
|
|
const tokens = analyze('`var x = "Strawberry Pasta";`');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('inlineCode', { code: 'var x = "Strawberry Pasta";' })
|
|
|
|
|
]);
|
2018-11-20 21:55:15 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('disallow line break', () => {
|
|
|
|
|
const tokens = analyze('`foo\nbar`');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 21:55:15 -06:00
|
|
|
|
text('`foo\nbar`')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-20 21:55:15 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('disallow ´', () => {
|
|
|
|
|
const tokens = analyze('`foo´bar`');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 21:55:15 -06:00
|
|
|
|
text('`foo´bar`')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-20 21:55:15 -06:00
|
|
|
|
});
|
2017-02-28 23:29:02 -06:00
|
|
|
|
});
|
2018-06-23 05:31:28 -05:00
|
|
|
|
|
2018-11-16 02:03:52 -06:00
|
|
|
|
it('math', () => {
|
2018-11-16 21:52:20 -06:00
|
|
|
|
const fomula = 'x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}';
|
2018-11-16 09:31:49 -06:00
|
|
|
|
const text = `\\(${fomula}\\)`;
|
2018-11-16 02:03:52 -06:00
|
|
|
|
const tokens = analyze(text);
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('math', { formula: fomula })
|
|
|
|
|
]);
|
2018-11-16 02:03:52 -06:00
|
|
|
|
});
|
|
|
|
|
|
2018-06-23 05:31:28 -05:00
|
|
|
|
it('search', () => {
|
|
|
|
|
const tokens1 = analyze('a b c 検索');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens1, [
|
|
|
|
|
leaf('search', { content: 'a b c 検索', query: 'a b c' })
|
|
|
|
|
]);
|
2018-06-23 05:31:28 -05:00
|
|
|
|
|
|
|
|
|
const tokens2 = analyze('a b c Search');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens2, [
|
|
|
|
|
leaf('search', { content: 'a b c Search', query: 'a b c' })
|
|
|
|
|
]);
|
2018-06-23 05:31:28 -05:00
|
|
|
|
|
|
|
|
|
const tokens3 = analyze('a b c search');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens3, [
|
|
|
|
|
leaf('search', { content: 'a b c search', query: 'a b c' })
|
|
|
|
|
]);
|
2018-06-23 05:31:28 -05:00
|
|
|
|
|
|
|
|
|
const tokens4 = analyze('a b c SEARCH');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens4, [
|
|
|
|
|
leaf('search', { content: 'a b c SEARCH', query: 'a b c' })
|
|
|
|
|
]);
|
2018-06-23 05:31:28 -05:00
|
|
|
|
});
|
2018-06-26 04:42:00 -05:00
|
|
|
|
|
2018-11-20 14:11:00 -06:00
|
|
|
|
describe('title', () => {
|
|
|
|
|
it('simple', () => {
|
|
|
|
|
const tokens = analyze('【foo】');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('title', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {})
|
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
2017-03-18 06:05:11 -05:00
|
|
|
|
|
2018-11-20 14:11:00 -06:00
|
|
|
|
it('require line break', () => {
|
|
|
|
|
const tokens = analyze('a【foo】');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('a【foo】')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
2017-02-28 06:00:59 -06:00
|
|
|
|
|
2018-11-20 14:11:00 -06:00
|
|
|
|
it('with before and after texts', () => {
|
|
|
|
|
const tokens = analyze('before\n【foo】\nafter');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-30 19:40:09 -06:00
|
|
|
|
text('before\n'),
|
2018-12-20 04:41:04 -06:00
|
|
|
|
tree('title', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('after')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
2017-02-28 06:00:59 -06:00
|
|
|
|
});
|
2018-11-24 22:36:40 -06:00
|
|
|
|
|
|
|
|
|
describe('center', () => {
|
|
|
|
|
it('simple', () => {
|
|
|
|
|
const tokens = analyze('<center>foo</center>');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('center', [
|
2018-11-24 22:36:40 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-11-24 22:36:40 -06:00
|
|
|
|
});
|
|
|
|
|
});
|
2018-12-03 10:28:21 -06:00
|
|
|
|
|
|
|
|
|
describe('strike', () => {
|
|
|
|
|
it('simple', () => {
|
|
|
|
|
const tokens = analyze('~~foo~~');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('strike', [
|
2018-12-03 10:28:21 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-12-03 10:28:21 -06:00
|
|
|
|
});
|
|
|
|
|
});
|
2018-12-05 02:39:26 -06:00
|
|
|
|
|
|
|
|
|
describe('italic', () => {
|
2019-01-20 02:52:11 -06:00
|
|
|
|
it('<i>', () => {
|
|
|
|
|
const tokens = analyze('<i>foo</i>');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('italic', [
|
|
|
|
|
text('foo')
|
|
|
|
|
], {}),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2019-01-20 02:44:52 -06:00
|
|
|
|
it('underscore', () => {
|
|
|
|
|
const tokens = analyze('_foo_');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('italic', [
|
2018-12-05 02:39:26 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-12-05 02:39:26 -06:00
|
|
|
|
});
|
2019-01-20 02:44:52 -06:00
|
|
|
|
|
|
|
|
|
it('simple with asterix', () => {
|
|
|
|
|
const tokens = analyze('*foo*');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('italic', [
|
|
|
|
|
text('foo')
|
|
|
|
|
], {}),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('exlude emotes', () => {
|
|
|
|
|
const tokens = analyze('*.*');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
text("*.*"),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('mixed', () => {
|
|
|
|
|
const tokens = analyze('_foo*');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
text('_foo*'),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('mixed', () => {
|
|
|
|
|
const tokens = analyze('*foo_');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
text('*foo_'),
|
|
|
|
|
]);
|
|
|
|
|
});
|
2019-01-20 02:53:08 -06:00
|
|
|
|
});
|
2017-02-28 06:00:59 -06:00
|
|
|
|
});
|
2018-09-16 12:45:30 -05:00
|
|
|
|
|
|
|
|
|
describe('toHtml', () => {
|
|
|
|
|
it('br', () => {
|
|
|
|
|
const input = 'foo\nbar\nbaz';
|
2018-11-20 14:11:00 -06:00
|
|
|
|
const output = '<p><span>foo<br>bar<br>baz</span></p>';
|
2018-09-16 12:45:30 -05:00
|
|
|
|
assert.equal(toHtml(analyze(input)), output);
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-11-20 14:11:00 -06:00
|
|
|
|
|
|
|
|
|
it('code block with quote', () => {
|
|
|
|
|
const tokens = analyze('> foo\n```\nbar\n```');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
|
|
|
|
leaf('blockCode', { code: 'bar', lang: null })
|
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('quote between two code blocks', () => {
|
|
|
|
|
const tokens = analyze('```\nbefore\n```\n> foo\n```\nafter\n```');
|
2018-12-20 04:41:04 -06:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('blockCode', { code: 'before', lang: null }),
|
|
|
|
|
tree('quote', [
|
2018-11-20 14:11:00 -06:00
|
|
|
|
text('foo')
|
2018-12-20 04:41:04 -06:00
|
|
|
|
], {}),
|
|
|
|
|
leaf('blockCode', { code: 'after', lang: null })
|
|
|
|
|
]);
|
2018-11-20 14:11:00 -06:00
|
|
|
|
});
|
2016-12-29 22:28:56 -06:00
|
|
|
|
});
|