2018-10-15 14:37:21 -07:00
|
|
|
|
/*
|
|
|
|
|
* Tests of MFM
|
2019-01-22 01:30:58 -08:00
|
|
|
|
*
|
2019-01-20 20:30:30 -08:00
|
|
|
|
* How to run the tests:
|
2020-03-06 07:12:23 -08:00
|
|
|
|
* > npx cross-env TS_NODE_FILES=true TS_NODE_TRANSPILE_ONLY=true npx mocha test/mfm.ts --require ts-node/register
|
2019-01-22 01:30:58 -08:00
|
|
|
|
*
|
|
|
|
|
* To specify test:
|
2020-03-06 07:12:23 -08:00
|
|
|
|
* > npx cross-env TS_NODE_FILES=true TS_NODE_TRANSPILE_ONLY=true npx mocha test/mfm.ts --require ts-node/register -g 'test name'
|
2018-10-15 14:37:21 -07:00
|
|
|
|
*/
|
|
|
|
|
|
2018-05-17 17:21:19 -07:00
|
|
|
|
import * as assert from 'assert';
|
2017-02-11 08:03:57 -08:00
|
|
|
|
|
2019-01-29 23:56:27 -08:00
|
|
|
|
import { parse, parsePlain } from '../src/mfm/parse';
|
2020-04-25 22:55:04 -07:00
|
|
|
|
import { toHtml } from '../src/mfm/totml';
|
2019-03-14 05:23:15 -07:00
|
|
|
|
import { createTree as tree, createLeaf as leaf, MfmTree } from '../src/mfm/prelude';
|
2019-01-30 00:15:12 -08:00
|
|
|
|
import { removeOrphanedBrackets } from '../src/mfm/language';
|
2018-11-20 12:11:00 -08:00
|
|
|
|
|
2018-12-20 02:41:04 -08:00
|
|
|
|
function text(text: string): MfmTree {
|
|
|
|
|
return leaf('text', { text });
|
2018-11-20 12:11:00 -08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-20 02:41:04 -08:00
|
|
|
|
describe('createLeaf', () => {
|
|
|
|
|
it('creates leaf', () => {
|
|
|
|
|
assert.deepStrictEqual(leaf('text', { text: 'abc' }), {
|
|
|
|
|
node: {
|
|
|
|
|
type: 'text',
|
|
|
|
|
props: {
|
|
|
|
|
text: 'abc'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
children: [],
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-11-20 12:11:00 -08:00
|
|
|
|
|
2018-12-20 02:41:04 -08:00
|
|
|
|
describe('createTree', () => {
|
|
|
|
|
it('creates tree', () => {
|
|
|
|
|
const t = tree('tree', [
|
|
|
|
|
leaf('left', { a: 2 }),
|
|
|
|
|
leaf('right', { b: 'hi' })
|
|
|
|
|
], {
|
2019-01-20 00:44:52 -08:00
|
|
|
|
c: 4
|
|
|
|
|
});
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(t, {
|
|
|
|
|
node: {
|
|
|
|
|
type: 'tree',
|
|
|
|
|
props: {
|
|
|
|
|
c: 4
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
children: [
|
|
|
|
|
leaf('left', { a: 2 }),
|
|
|
|
|
leaf('right', { b: 'hi' })
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-12-29 20:28:56 -08:00
|
|
|
|
|
2018-12-21 07:41:54 -08: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 02:41:04 -08:00
|
|
|
|
describe('MFM', () => {
|
2018-01-20 22:49:31 -08:00
|
|
|
|
it('can be analyzed', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('@himawari @hima_sub@namori.net お腹ペコい :cat: #yryr');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2019-01-26 20:55:11 -08:00
|
|
|
|
leaf('mention', {
|
|
|
|
|
acct: '@himawari',
|
|
|
|
|
canonical: '@himawari',
|
|
|
|
|
username: 'himawari',
|
|
|
|
|
host: null
|
|
|
|
|
}),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text(' '),
|
2019-01-26 20:55:11 -08:00
|
|
|
|
leaf('mention', {
|
|
|
|
|
acct: '@hima_sub@namori.net',
|
|
|
|
|
canonical: '@hima_sub@namori.net',
|
|
|
|
|
username: 'hima_sub',
|
|
|
|
|
host: 'namori.net'
|
|
|
|
|
}),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text(' お腹ペコい '),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
leaf('emoji', { name: 'cat' }),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text(' '),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
leaf('hashtag', { hashtag: 'yryr' }),
|
|
|
|
|
]);
|
2016-12-29 20:28:56 -08:00
|
|
|
|
});
|
|
|
|
|
|
2017-02-28 21:29:02 -08:00
|
|
|
|
describe('elements', () => {
|
2018-11-20 12:11:00 -08:00
|
|
|
|
describe('bold', () => {
|
|
|
|
|
it('simple', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('**foo**');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('bold', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with other texts', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('bar**foo**bar');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('bar'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
tree('bold', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('bar'),
|
2019-01-20 01:00:55 -08:00
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with underscores', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('__foo__');
|
2019-01-20 01:00:55 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('bold', [
|
|
|
|
|
text('foo')
|
|
|
|
|
], {}),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2019-01-20 01:06:04 -08:00
|
|
|
|
it('with underscores (ensure it allows alphabet only)', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('(=^・__________・^=)');
|
2019-01-20 01:06:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
text('(=^・__________・^=)')
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2019-01-20 01:00:55 -08:00
|
|
|
|
it('mixed syntax', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('**foo__');
|
2019-01-20 01:00:55 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
text('**foo__'),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('mixed syntax', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('__foo**');
|
2019-01-20 01:00:55 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
text('__foo**'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
2017-02-28 21:29:02 -08:00
|
|
|
|
});
|
2017-02-11 08:01:35 -08:00
|
|
|
|
|
2018-08-03 07:27:37 -07:00
|
|
|
|
it('big', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('***Strawberry*** Pasta');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('big', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('Strawberry')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text(' Pasta'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-08-03 07:27:37 -07:00
|
|
|
|
});
|
|
|
|
|
|
2018-12-05 03:11:54 -08:00
|
|
|
|
it('small', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('<small>smaller</small>');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('small', [
|
2018-12-05 03:11:54 -08:00
|
|
|
|
text('smaller')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-12-05 03:11:54 -08:00
|
|
|
|
});
|
|
|
|
|
|
2019-01-26 23:31:00 -08:00
|
|
|
|
it('flip', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('<flip>foo</flip>');
|
2019-01-26 23:31:00 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('flip', [
|
2019-01-26 23:36:01 -08:00
|
|
|
|
text('foo')
|
2019-01-26 23:31:00 -08:00
|
|
|
|
], {}),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-12-05 03:11:54 -08:00
|
|
|
|
});
|
|
|
|
|
|
2019-01-27 02:32:35 -08:00
|
|
|
|
describe('spin', () => {
|
2019-01-30 22:19:59 -08:00
|
|
|
|
it('text', () => {
|
|
|
|
|
const tokens = parse('<spin>foo</spin>');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('spin', [
|
|
|
|
|
text('foo')
|
|
|
|
|
], {
|
|
|
|
|
attr: null
|
|
|
|
|
}),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('emoji', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('<spin>:foo:</spin>');
|
2019-01-27 02:32:35 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('spin', [
|
|
|
|
|
leaf('emoji', { name: 'foo' })
|
|
|
|
|
], {
|
|
|
|
|
attr: null
|
|
|
|
|
}),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with attr', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('<spin left>:foo:</spin>');
|
2019-01-27 02:32:35 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('spin', [
|
|
|
|
|
leaf('emoji', { name: 'foo' })
|
|
|
|
|
], {
|
|
|
|
|
attr: 'left'
|
|
|
|
|
}),
|
|
|
|
|
]);
|
|
|
|
|
});
|
2019-01-31 00:15:14 -08:00
|
|
|
|
/*
|
2019-01-30 21:31:25 -08:00
|
|
|
|
it('multi', () => {
|
|
|
|
|
const tokens = parse('<spin>:foo:</spin><spin>:foo:</spin>');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('spin', [
|
|
|
|
|
leaf('emoji', { name: 'foo' })
|
|
|
|
|
], {
|
2019-01-30 22:10:27 -08:00
|
|
|
|
attr: null
|
2019-01-30 21:31:25 -08:00
|
|
|
|
}),
|
|
|
|
|
tree('spin', [
|
|
|
|
|
leaf('emoji', { name: 'foo' })
|
|
|
|
|
], {
|
2019-01-30 22:10:27 -08:00
|
|
|
|
attr: null
|
2019-01-30 21:31:25 -08:00
|
|
|
|
}),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2019-01-30 19:23:45 -08:00
|
|
|
|
it('nested', () => {
|
|
|
|
|
const tokens = parse('<spin><spin>:foo:</spin></spin>');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('spin', [
|
|
|
|
|
tree('spin', [
|
|
|
|
|
leaf('emoji', { name: 'foo' })
|
|
|
|
|
], {
|
|
|
|
|
attr: null
|
|
|
|
|
}),
|
|
|
|
|
], {
|
|
|
|
|
attr: null
|
|
|
|
|
}),
|
|
|
|
|
]);
|
|
|
|
|
});
|
2019-01-31 00:15:14 -08:00
|
|
|
|
*/
|
2019-01-26 23:18:04 -08:00
|
|
|
|
});
|
|
|
|
|
|
2019-01-27 02:12:45 -08:00
|
|
|
|
it('jump', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('<jump>:foo:</jump>');
|
2019-01-27 02:12:45 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('jump', [
|
|
|
|
|
leaf('emoji', { name: 'foo' })
|
|
|
|
|
], {}),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2018-11-20 12:11:00 -08:00
|
|
|
|
describe('motion', () => {
|
|
|
|
|
it('by triple brackets', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('(((foo)))');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('motion', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
2018-08-05 07:56:08 -07:00
|
|
|
|
|
2018-11-20 12:11:00 -08:00
|
|
|
|
it('by triple brackets (with other texts)', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('bar(((foo)))bar');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('bar'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
tree('motion', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('bar'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('by <motion> tag', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('<motion>foo</motion>');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('motion', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('by <motion> tag (with other texts)', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('bar<motion>foo</motion>bar');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('bar'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
tree('motion', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('bar'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
2018-08-04 20:33:51 -07:00
|
|
|
|
});
|
|
|
|
|
|
2018-09-29 22:46:18 -07:00
|
|
|
|
describe('mention', () => {
|
|
|
|
|
it('local', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('@himawari foo');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2019-01-26 20:55:11 -08:00
|
|
|
|
leaf('mention', {
|
|
|
|
|
acct: '@himawari',
|
|
|
|
|
canonical: '@himawari',
|
|
|
|
|
username: 'himawari',
|
|
|
|
|
host: null
|
|
|
|
|
}),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text(' foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-09-29 22:46:18 -07:00
|
|
|
|
});
|
2017-02-11 08:01:35 -08:00
|
|
|
|
|
2018-09-29 22:46:18 -07:00
|
|
|
|
it('remote', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('@hima_sub@namori.net foo');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2019-01-26 20:55:11 -08:00
|
|
|
|
leaf('mention', {
|
|
|
|
|
acct: '@hima_sub@namori.net',
|
|
|
|
|
canonical: '@hima_sub@namori.net',
|
|
|
|
|
username: 'hima_sub',
|
|
|
|
|
host: 'namori.net'
|
|
|
|
|
}),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text(' foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-10-14 00:56:19 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('remote punycode', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('@hima_sub@xn--q9j5bya.xn--zckzah foo');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2019-01-26 20:55:11 -08:00
|
|
|
|
leaf('mention', {
|
|
|
|
|
acct: '@hima_sub@xn--q9j5bya.xn--zckzah',
|
|
|
|
|
canonical: '@hima_sub@なもり.テスト',
|
|
|
|
|
username: 'hima_sub',
|
|
|
|
|
host: 'xn--q9j5bya.xn--zckzah'
|
|
|
|
|
}),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text(' foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-09-29 22:46:18 -07:00
|
|
|
|
});
|
2018-11-16 04:57:19 -08:00
|
|
|
|
|
2018-09-29 22:46:18 -07:00
|
|
|
|
it('ignore', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('idolm@ster');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('idolm@ster')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-09-29 22:46:18 -07:00
|
|
|
|
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens2 = parse('@a\n@b\n@c');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens2, [
|
2019-01-26 20:55:11 -08:00
|
|
|
|
leaf('mention', {
|
|
|
|
|
acct: '@a',
|
|
|
|
|
canonical: '@a',
|
|
|
|
|
username: 'a',
|
|
|
|
|
host: null
|
|
|
|
|
}),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('\n'),
|
2019-01-26 20:55:11 -08:00
|
|
|
|
leaf('mention', {
|
|
|
|
|
acct: '@b',
|
|
|
|
|
canonical: '@b',
|
|
|
|
|
username: 'b',
|
|
|
|
|
host: null
|
|
|
|
|
}),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('\n'),
|
2019-01-26 20:55:11 -08:00
|
|
|
|
leaf('mention', {
|
|
|
|
|
acct: '@c',
|
|
|
|
|
canonical: '@c',
|
|
|
|
|
username: 'c',
|
|
|
|
|
host: null
|
|
|
|
|
})
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-09-29 22:46:18 -07:00
|
|
|
|
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens3 = parse('**x**@a');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens3, [
|
|
|
|
|
tree('bold', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('x')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
2019-01-26 20:55:11 -08:00
|
|
|
|
leaf('mention', {
|
|
|
|
|
acct: '@a',
|
|
|
|
|
canonical: '@a',
|
|
|
|
|
username: 'a',
|
|
|
|
|
host: null
|
|
|
|
|
})
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-12-17 02:11:38 -08:00
|
|
|
|
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens4 = parse('@\n@v\n@veryverylongusername');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens4, [
|
2018-12-17 02:11:38 -08:00
|
|
|
|
text('@\n'),
|
2019-01-26 20:55:11 -08:00
|
|
|
|
leaf('mention', {
|
|
|
|
|
acct: '@v',
|
|
|
|
|
canonical: '@v',
|
|
|
|
|
username: 'v',
|
|
|
|
|
host: null
|
|
|
|
|
}),
|
2018-12-17 02:11:38 -08:00
|
|
|
|
text('\n'),
|
2019-01-26 20:55:11 -08:00
|
|
|
|
leaf('mention', {
|
|
|
|
|
acct: '@veryverylongusername',
|
|
|
|
|
canonical: '@veryverylongusername',
|
|
|
|
|
username: 'veryverylongusername',
|
|
|
|
|
host: null
|
|
|
|
|
}),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-09-29 22:46:18 -07:00
|
|
|
|
});
|
2018-04-08 09:10:04 -07:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-20 15:30:29 -08:00
|
|
|
|
describe('hashtag', () => {
|
|
|
|
|
it('simple', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('#alice');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('hashtag', { hashtag: 'alice' })
|
|
|
|
|
]);
|
2018-11-20 15:30:29 -08:00
|
|
|
|
});
|
2018-09-17 06:51:10 -07:00
|
|
|
|
|
2018-11-20 15:30:29 -08:00
|
|
|
|
it('after line break', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('foo\n#alice');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 15:30:29 -08:00
|
|
|
|
text('foo\n'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
leaf('hashtag', { hashtag: 'alice' })
|
|
|
|
|
]);
|
2018-11-20 15:30:29 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with text', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('Strawberry Pasta #alice');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 15:30:29 -08:00
|
|
|
|
text('Strawberry Pasta '),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
leaf('hashtag', { hashtag: 'alice' })
|
|
|
|
|
]);
|
2018-11-20 15:30:29 -08:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-29 03:12:37 -08:00
|
|
|
|
it('with text (zenkaku)', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('こんにちは#世界');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-12-01 13:53:57 -08:00
|
|
|
|
text('こんにちは'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
leaf('hashtag', { hashtag: '世界' })
|
|
|
|
|
]);
|
2018-11-29 03:12:37 -08:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-20 15:30:29 -08:00
|
|
|
|
it('ignore comma and period', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('Foo #bar, baz #piyo.');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 15:30:29 -08:00
|
|
|
|
text('Foo '),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
leaf('hashtag', { hashtag: 'bar' }),
|
2018-11-20 15:30:29 -08:00
|
|
|
|
text(', baz '),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
leaf('hashtag', { hashtag: 'piyo' }),
|
2018-11-20 15:30:29 -08:00
|
|
|
|
text('.'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-20 15:30:29 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('ignore exclamation mark', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('#Foo!');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('hashtag', { hashtag: 'Foo' }),
|
2018-11-20 15:30:29 -08:00
|
|
|
|
text('!'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-20 15:30:29 -08:00
|
|
|
|
});
|
2018-11-22 23:02:17 -08:00
|
|
|
|
|
2019-01-11 21:10:16 -08:00
|
|
|
|
it('ignore colon', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('#Foo:');
|
2019-01-11 21:10:16 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('hashtag', { hashtag: 'Foo' }),
|
|
|
|
|
text(':'),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2019-01-16 16:33:08 -08:00
|
|
|
|
it('ignore single quote', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('#foo\'');
|
2019-01-16 16:33:08 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('hashtag', { hashtag: 'foo' }),
|
|
|
|
|
text('\''),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2019-01-16 16:24:20 -08:00
|
|
|
|
it('ignore double quote', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('#foo"');
|
2019-01-16 16:24:20 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('hashtag', { hashtag: 'foo' }),
|
|
|
|
|
text('"'),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2019-03-05 05:18:29 -08:00
|
|
|
|
it('ignore square brackets', () => {
|
|
|
|
|
const tokens = parse('#foo]');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('hashtag', { hashtag: 'foo' }),
|
|
|
|
|
text(']'),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2019-04-17 08:40:56 -07:00
|
|
|
|
it('ignore 】', () => {
|
|
|
|
|
const tokens = parse('#foo】');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('hashtag', { hashtag: 'foo' }),
|
|
|
|
|
text('】'),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2018-11-24 00:18:11 -08:00
|
|
|
|
it('allow including number', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('#foo123');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('hashtag', { hashtag: 'foo123' }),
|
|
|
|
|
]);
|
2018-11-24 00:18:11 -08:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-24 11:44:42 -08:00
|
|
|
|
it('with brackets', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens1 = parse('(#foo)');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens1, [
|
2018-11-24 11:44:42 -08:00
|
|
|
|
text('('),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
leaf('hashtag', { hashtag: 'foo' }),
|
2018-11-24 11:44:42 -08:00
|
|
|
|
text(')'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-26 09:08:51 -08:00
|
|
|
|
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens2 = parse('「#foo」');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens2, [
|
2018-11-26 09:08:51 -08:00
|
|
|
|
text('「'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
leaf('hashtag', { hashtag: 'foo' }),
|
2018-11-26 09:08:51 -08:00
|
|
|
|
text('」'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-26 09:08:51 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with mixed brackets', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('「#foo(bar)」');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-26 09:08:51 -08:00
|
|
|
|
text('「'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
leaf('hashtag', { hashtag: 'foo(bar)' }),
|
2018-11-26 09:08:51 -08:00
|
|
|
|
text('」'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-24 11:44:42 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with brackets (space before)', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens1 = parse('(bar #foo)');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens1, [
|
2018-11-24 11:44:42 -08:00
|
|
|
|
text('(bar '),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
leaf('hashtag', { hashtag: 'foo' }),
|
2018-11-24 11:44:42 -08:00
|
|
|
|
text(')'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-26 09:08:51 -08:00
|
|
|
|
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens2 = parse('「bar #foo」');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens2, [
|
2018-11-26 09:08:51 -08:00
|
|
|
|
text('「bar '),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
leaf('hashtag', { hashtag: 'foo' }),
|
2018-11-26 09:08:51 -08:00
|
|
|
|
text('」'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-24 11:44:42 -08:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-22 23:02:17 -08:00
|
|
|
|
it('disallow number only', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('#123');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-22 23:02:17 -08:00
|
|
|
|
text('#123'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-22 23:02:17 -08:00
|
|
|
|
});
|
2018-11-24 11:44:42 -08:00
|
|
|
|
|
|
|
|
|
it('disallow number only (with brackets)', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('(#123)');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-24 11:44:42 -08:00
|
|
|
|
text('(#123)'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-24 11:44:42 -08:00
|
|
|
|
});
|
2019-02-05 07:05:26 -08:00
|
|
|
|
|
|
|
|
|
it('ignore slash', () => {
|
|
|
|
|
const tokens = parse('#foo/bar');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('hashtag', { hashtag: 'foo' }),
|
|
|
|
|
text('/bar'),
|
|
|
|
|
]);
|
|
|
|
|
});
|
2019-09-15 07:33:58 -07:00
|
|
|
|
|
|
|
|
|
it('ignore Keycap Number Sign (U+0023 + U+20E3)', () => {
|
|
|
|
|
const tokens = parse('#⃣');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('emoji', { emoji: '#⃣' })
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('ignore Keycap Number Sign (U+0023 + U+FE0F + U+20E3)', () => {
|
|
|
|
|
const tokens = parse('#️⃣');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('emoji', { emoji: '#️⃣' })
|
|
|
|
|
]);
|
|
|
|
|
});
|
2017-02-28 21:29:02 -08:00
|
|
|
|
});
|
2017-02-11 08:01:35 -08:00
|
|
|
|
|
2018-11-20 12:11:00 -08:00
|
|
|
|
describe('quote', () => {
|
|
|
|
|
it('basic', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens1 = parse('> foo');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens1, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {})
|
|
|
|
|
]);
|
2018-09-19 14:27:41 -07:00
|
|
|
|
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens2 = parse('>foo');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens2, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {})
|
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
2018-09-20 16:33:24 -07:00
|
|
|
|
|
2018-11-20 12:11:00 -08:00
|
|
|
|
it('series', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('> foo\n\n> bar');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
2018-11-30 17:40:09 -08:00
|
|
|
|
text('\n'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
tree('quote', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('bar')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
2018-09-20 16:33:24 -07:00
|
|
|
|
|
2018-11-20 12:11:00 -08:00
|
|
|
|
it('trailing line break', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens1 = parse('> foo\n');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens1, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-10-29 03:09:24 -07:00
|
|
|
|
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens2 = parse('> foo\n\n');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens2, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('\n')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('multiline', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens1 = parse('>foo\n>bar');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens1, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo\nbar')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {})
|
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens2 = parse('> foo\n> bar');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens2, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo\nbar')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {})
|
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('multiline with trailing line break', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens1 = parse('> foo\n> bar\n');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens1, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo\nbar')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens2 = parse('> foo\n> bar\n\n');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens2, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo\nbar')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('\n')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with before and after texts', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('before\n> foo\nafter');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-30 17:40:09 -08:00
|
|
|
|
text('before\n'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
tree('quote', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('after'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-30 17:40:09 -08:00
|
|
|
|
it('multiple quotes', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('> foo\nbar\n\n> foo\nbar\n\n> foo\nbar');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('quote', [
|
2018-11-30 17:40:09 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
2018-11-30 17:40:09 -08:00
|
|
|
|
text('bar\n\n'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
tree('quote', [
|
2018-11-30 17:40:09 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
2018-11-30 17:40:09 -08:00
|
|
|
|
text('bar\n\n'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
tree('quote', [
|
2018-11-30 17:40:09 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
2018-11-30 17:40:09 -08:00
|
|
|
|
text('bar'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-30 17:40:09 -08:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-20 12:11:00 -08:00
|
|
|
|
it('require line break before ">"', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('foo>bar');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo>bar'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('nested', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('>> foo\n> bar');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('quote', [
|
|
|
|
|
tree('quote', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('bar')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {})
|
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('trim line breaks', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('foo\n\n>a\n>>b\n>>\n>>>\n>>>c\n>>>\n>d\n\n');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-30 17:40:09 -08:00
|
|
|
|
text('foo\n\n'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
tree('quote', [
|
2018-11-30 17:40:09 -08:00
|
|
|
|
text('a\n'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
tree('quote', [
|
2018-11-30 17:40:09 -08:00
|
|
|
|
text('b\n\n'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
tree('quote', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('\nc\n')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {})
|
|
|
|
|
], {}),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('d')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('\n'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
2018-09-19 14:27:41 -07:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-16 04:57:19 -08:00
|
|
|
|
describe('url', () => {
|
|
|
|
|
it('simple', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('https://example.com');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('url', { url: 'https://example.com' })
|
|
|
|
|
]);
|
2018-11-16 04:57:19 -08:00
|
|
|
|
});
|
2018-11-16 04:30:01 -08:00
|
|
|
|
|
2018-11-16 19:52:20 -08:00
|
|
|
|
it('ignore trailing period', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('https://example.com.');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('url', { url: 'https://example.com' }),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('.')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-16 04:57:19 -08:00
|
|
|
|
});
|
2018-11-16 04:30:01 -08:00
|
|
|
|
|
2019-06-17 04:15:19 -07:00
|
|
|
|
it('ignore trailing periods', () => {
|
|
|
|
|
const tokens = parse('https://example.com...');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('url', { url: 'https://example.com' }),
|
|
|
|
|
text('...')
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2018-11-16 04:57:19 -08:00
|
|
|
|
it('with comma', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('https://example.com/foo?bar=a,b');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('url', { url: 'https://example.com/foo?bar=a,b' })
|
|
|
|
|
]);
|
2018-11-16 04:57:19 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('ignore trailing comma', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('https://example.com/foo, bar');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('url', { url: 'https://example.com/foo' }),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text(', bar')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-16 04:57:19 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with brackets', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('https://example.com/foo(bar)');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('url', { url: 'https://example.com/foo(bar)' })
|
|
|
|
|
]);
|
2018-11-16 04:57:19 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('ignore parent brackets', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('(https://example.com/foo)');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('('),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
leaf('url', { url: 'https://example.com/foo' }),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text(')')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-16 04:57:19 -08:00
|
|
|
|
});
|
2018-11-16 19:52:20 -08:00
|
|
|
|
|
2019-07-02 04:05:52 -07:00
|
|
|
|
it('ignore parent []', () => {
|
2019-07-02 04:08:30 -07:00
|
|
|
|
const tokens = parse('foo [https://example.com/foo] bar');
|
2019-07-02 04:05:52 -07:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2019-07-02 04:08:30 -07:00
|
|
|
|
text('foo ['),
|
2019-07-02 04:05:52 -07:00
|
|
|
|
leaf('url', { url: 'https://example.com/foo' }),
|
2019-07-02 04:08:30 -07:00
|
|
|
|
text('] bar')
|
2019-07-02 04:05:52 -07:00
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2018-11-21 12:02:38 -08:00
|
|
|
|
it('ignore parent brackets 2', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('(foo https://example.com/foo)');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-21 12:02:38 -08:00
|
|
|
|
text('(foo '),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
leaf('url', { url: 'https://example.com/foo' }),
|
2018-11-21 12:02:38 -08:00
|
|
|
|
text(')')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-21 12:02:38 -08:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-16 19:52:20 -08:00
|
|
|
|
it('ignore parent brackets with internal brackets', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('(https://example.com/foo(bar))');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('('),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
leaf('url', { url: 'https://example.com/foo(bar)' }),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text(')')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-16 19:52:20 -08:00
|
|
|
|
});
|
2019-03-14 05:23:15 -07:00
|
|
|
|
|
|
|
|
|
it('ignore non-ascii characters contained url without angle brackets', () => {
|
|
|
|
|
const tokens = parse('https://大石泉すき.example.com');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
text('https://大石泉すき.example.com')
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('match non-ascii characters contained url with angle brackets', () => {
|
|
|
|
|
const tokens = parse('<https://大石泉すき.example.com>');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('url', { url: 'https://大石泉すき.example.com' })
|
|
|
|
|
]);
|
|
|
|
|
});
|
2017-03-17 09:16:32 -07:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-21 12:02:38 -08:00
|
|
|
|
describe('link', () => {
|
|
|
|
|
it('simple', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('[foo](https://example.com)');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('link', [
|
2018-11-21 12:02:38 -08:00
|
|
|
|
text('foo')
|
|
|
|
|
], { url: 'https://example.com', silent: false })
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-21 12:02:38 -08:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-24 20:21:39 -08:00
|
|
|
|
it('simple (with silent flag)', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('?[foo](https://example.com)');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('link', [
|
2018-11-24 20:21:39 -08:00
|
|
|
|
text('foo')
|
|
|
|
|
], { url: 'https://example.com', silent: true })
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-24 20:21:39 -08:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-21 12:02:38 -08:00
|
|
|
|
it('in text', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('before[foo](https://example.com)after');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-21 12:02:38 -08:00
|
|
|
|
text('before'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
tree('link', [
|
2018-11-21 12:02:38 -08:00
|
|
|
|
text('foo')
|
|
|
|
|
], { url: 'https://example.com', silent: false }),
|
|
|
|
|
text('after'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-21 12:02:38 -08:00
|
|
|
|
});
|
2018-11-21 12:04:45 -08:00
|
|
|
|
|
|
|
|
|
it('with brackets', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('[foo](https://example.com/foo(bar))');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('link', [
|
2018-11-21 12:04:45 -08:00
|
|
|
|
text('foo')
|
|
|
|
|
], { url: 'https://example.com/foo(bar)', silent: false })
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-21 12:04:45 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with parent brackets', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('([foo](https://example.com/foo(bar)))');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-21 12:04:45 -08:00
|
|
|
|
text('('),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
tree('link', [
|
2018-11-21 12:04:45 -08:00
|
|
|
|
text('foo')
|
|
|
|
|
], { url: 'https://example.com/foo(bar)', silent: false }),
|
|
|
|
|
text(')')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-21 12:04:45 -08:00
|
|
|
|
});
|
2017-02-28 21:29:02 -08:00
|
|
|
|
});
|
2017-02-28 19:15:45 -08:00
|
|
|
|
|
2017-02-28 21:29:02 -08:00
|
|
|
|
it('emoji', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens1 = parse(':cat:');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens1, [
|
|
|
|
|
leaf('emoji', { name: 'cat' })
|
|
|
|
|
]);
|
2018-11-03 06:35:24 -07:00
|
|
|
|
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens2 = parse(':cat::cat::cat:');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens2, [
|
|
|
|
|
leaf('emoji', { name: 'cat' }),
|
|
|
|
|
leaf('emoji', { name: 'cat' }),
|
|
|
|
|
leaf('emoji', { name: 'cat' })
|
|
|
|
|
]);
|
2018-11-05 03:14:49 -08:00
|
|
|
|
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens3 = parse('🍎');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens3, [
|
|
|
|
|
leaf('emoji', { emoji: '🍎' })
|
|
|
|
|
]);
|
2017-02-28 21:29:02 -08:00
|
|
|
|
});
|
2017-02-11 08:01:35 -08:00
|
|
|
|
|
2018-11-20 12:11:00 -08:00
|
|
|
|
describe('block code', () => {
|
|
|
|
|
it('simple', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('```\nvar x = "Strawberry Pasta";\n```');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('blockCode', { code: 'var x = "Strawberry Pasta";', lang: null })
|
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can specify language', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('``` json\n{ "x": 42 }\n```');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('blockCode', { code: '{ "x": 42 }', lang: 'json' })
|
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('require line break before "```"', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('before```\nfoo\n```');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('before'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
leaf('inlineCode', { code: '`' }),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('\nfoo\n'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
leaf('inlineCode', { code: '`' })
|
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('series', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('```\nfoo\n```\n```\nbar\n```\n```\nbaz\n```');
|
2018-12-20 02:41:04 -08: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 12:11:00 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('ignore internal marker', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('```\naaa```bbb\n```');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('blockCode', { code: 'aaa```bbb', lang: null })
|
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('trim after line break', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('```\nfoo\n```\nbar');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('blockCode', { code: 'foo', lang: null }),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('bar')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
2017-02-28 21:29:02 -08:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-20 19:55:15 -08:00
|
|
|
|
describe('inline code', () => {
|
|
|
|
|
it('simple', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('`var x = "Strawberry Pasta";`');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('inlineCode', { code: 'var x = "Strawberry Pasta";' })
|
|
|
|
|
]);
|
2018-11-20 19:55:15 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('disallow line break', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('`foo\nbar`');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 19:55:15 -08:00
|
|
|
|
text('`foo\nbar`')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-20 19:55:15 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('disallow ´', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('`foo´bar`');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 19:55:15 -08:00
|
|
|
|
text('`foo´bar`')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-20 19:55:15 -08:00
|
|
|
|
});
|
2017-02-28 21:29:02 -08:00
|
|
|
|
});
|
2018-06-23 03:31:28 -07:00
|
|
|
|
|
2019-01-25 06:08:06 -08:00
|
|
|
|
it('mathInline', () => {
|
2018-11-16 19:52:20 -08:00
|
|
|
|
const fomula = 'x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}';
|
2019-01-25 06:08:06 -08:00
|
|
|
|
const content = `\\(${fomula}\\)`;
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse(content);
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2019-01-25 06:08:06 -08:00
|
|
|
|
leaf('mathInline', { formula: fomula })
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-16 00:03:52 -08:00
|
|
|
|
});
|
|
|
|
|
|
2019-01-25 06:08:06 -08:00
|
|
|
|
describe('mathBlock', () => {
|
|
|
|
|
it('simple', () => {
|
|
|
|
|
const fomula = 'x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}';
|
|
|
|
|
const content = `\\[\n${fomula}\n\\]`;
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse(content);
|
2019-01-25 06:08:06 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('mathBlock', { formula: fomula })
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2018-06-23 03:31:28 -07:00
|
|
|
|
it('search', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens1 = parse('a b c 検索');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens1, [
|
|
|
|
|
leaf('search', { content: 'a b c 検索', query: 'a b c' })
|
|
|
|
|
]);
|
2018-06-23 03:31:28 -07:00
|
|
|
|
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens2 = parse('a b c Search');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens2, [
|
|
|
|
|
leaf('search', { content: 'a b c Search', query: 'a b c' })
|
|
|
|
|
]);
|
2018-06-23 03:31:28 -07:00
|
|
|
|
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens3 = parse('a b c search');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens3, [
|
|
|
|
|
leaf('search', { content: 'a b c search', query: 'a b c' })
|
|
|
|
|
]);
|
2018-06-23 03:31:28 -07:00
|
|
|
|
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens4 = parse('a b c SEARCH');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens4, [
|
|
|
|
|
leaf('search', { content: 'a b c SEARCH', query: 'a b c' })
|
|
|
|
|
]);
|
2018-06-23 03:31:28 -07:00
|
|
|
|
});
|
2018-06-26 02:42:00 -07:00
|
|
|
|
|
2018-11-20 12:11:00 -08:00
|
|
|
|
describe('title', () => {
|
|
|
|
|
it('simple', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('【foo】');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('title', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {})
|
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
2017-03-18 04:05:11 -07:00
|
|
|
|
|
2018-11-20 12:11:00 -08:00
|
|
|
|
it('require line break', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('a【foo】');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('a【foo】')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
2017-02-28 04:00:59 -08:00
|
|
|
|
|
2018-11-20 12:11:00 -08:00
|
|
|
|
it('with before and after texts', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('before\n【foo】\nafter');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2018-11-30 17:40:09 -08:00
|
|
|
|
text('before\n'),
|
2018-12-20 02:41:04 -08:00
|
|
|
|
tree('title', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('after')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
2019-01-26 20:40:38 -08:00
|
|
|
|
|
|
|
|
|
it('ignore multiple title blocks', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('【foo】bar【baz】');
|
2019-01-26 20:40:38 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
text('【foo】bar【baz】')
|
|
|
|
|
]);
|
|
|
|
|
});
|
2019-01-26 20:48:56 -08:00
|
|
|
|
|
|
|
|
|
it('disallow linebreak in title', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('【foo\nbar】');
|
2019-01-26 20:48:56 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
text('【foo\nbar】')
|
|
|
|
|
]);
|
|
|
|
|
});
|
2017-02-28 04:00:59 -08:00
|
|
|
|
});
|
2018-11-24 20:36:40 -08:00
|
|
|
|
|
|
|
|
|
describe('center', () => {
|
|
|
|
|
it('simple', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('<center>foo</center>');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('center', [
|
2018-11-24 20:36:40 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-11-24 20:36:40 -08:00
|
|
|
|
});
|
|
|
|
|
});
|
2018-12-03 08:28:21 -08:00
|
|
|
|
|
|
|
|
|
describe('strike', () => {
|
|
|
|
|
it('simple', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('~~foo~~');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('strike', [
|
2018-12-03 08:28:21 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-12-03 08:28:21 -08:00
|
|
|
|
});
|
2019-06-16 05:42:57 -07:00
|
|
|
|
|
|
|
|
|
// https://misskey.io/notes/7u1kv5dmia
|
|
|
|
|
it('ignore internal tilde', () => {
|
|
|
|
|
const tokens = parse('~~~~~');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
text('~~~~~')
|
|
|
|
|
]);
|
|
|
|
|
});
|
2018-12-03 08:28:21 -08:00
|
|
|
|
});
|
2018-12-05 00:39:26 -08:00
|
|
|
|
|
|
|
|
|
describe('italic', () => {
|
2019-01-20 00:52:11 -08:00
|
|
|
|
it('<i>', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('<i>foo</i>');
|
2019-01-20 00:52:11 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('italic', [
|
|
|
|
|
text('foo')
|
|
|
|
|
], {}),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2019-01-20 00:44:52 -08:00
|
|
|
|
it('underscore', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('_foo_');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('italic', [
|
2018-12-05 00:39:26 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
|
|
|
|
]);
|
2018-12-05 00:39:26 -08:00
|
|
|
|
});
|
2019-01-20 00:44:52 -08:00
|
|
|
|
|
|
|
|
|
it('simple with asterix', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('*foo*');
|
2019-01-20 00:44:52 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('italic', [
|
|
|
|
|
text('foo')
|
|
|
|
|
], {}),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('exlude emotes', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('*.*');
|
2019-01-20 00:44:52 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2019-04-14 20:10:40 -07:00
|
|
|
|
text('*.*'),
|
2019-01-20 00:44:52 -08:00
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('mixed', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('_foo*');
|
2019-01-20 00:44:52 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
text('_foo*'),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('mixed', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('*foo_');
|
2019-01-20 00:44:52 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
text('*foo_'),
|
|
|
|
|
]);
|
|
|
|
|
});
|
2019-01-24 23:41:51 -08:00
|
|
|
|
|
|
|
|
|
it('ignore snake_case string', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('foo_bar_baz');
|
2019-01-24 23:41:51 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
text('foo_bar_baz'),
|
|
|
|
|
]);
|
|
|
|
|
});
|
2019-06-16 05:26:43 -07:00
|
|
|
|
|
|
|
|
|
it('require spaces', () => {
|
2019-06-16 05:29:31 -07:00
|
|
|
|
const tokens = parse('4日目_L38b a_b');
|
2019-06-16 05:26:43 -07:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
2019-06-16 05:29:31 -07:00
|
|
|
|
text('4日目_L38b a_b'),
|
2019-06-16 05:26:43 -07:00
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('newline sandwich', () => {
|
|
|
|
|
const tokens = parse('foo\n_bar_\nbaz');
|
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
text('foo\n'),
|
|
|
|
|
tree('italic', [
|
|
|
|
|
text('bar')
|
|
|
|
|
], {}),
|
2019-06-16 05:30:26 -07:00
|
|
|
|
text('\nbaz'),
|
2019-06-16 05:26:43 -07:00
|
|
|
|
]);
|
|
|
|
|
});
|
2019-01-20 00:53:08 -08:00
|
|
|
|
});
|
2017-02-28 04:00:59 -08:00
|
|
|
|
});
|
2018-09-16 10:45:30 -07:00
|
|
|
|
|
2019-01-29 22:12:48 -08:00
|
|
|
|
describe('plainText', () => {
|
|
|
|
|
it('text', () => {
|
2019-01-29 22:27:54 -08:00
|
|
|
|
const tokens = parsePlain('foo');
|
2019-01-29 22:12:48 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
text('foo'),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('emoji', () => {
|
2019-01-29 22:27:54 -08:00
|
|
|
|
const tokens = parsePlain(':foo:');
|
2019-01-29 22:12:48 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('emoji', { name: 'foo' })
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('emoji in text', () => {
|
2019-01-29 22:27:54 -08:00
|
|
|
|
const tokens = parsePlain('foo:bar:baz');
|
2019-01-29 22:12:48 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
text('foo'),
|
|
|
|
|
leaf('emoji', { name: 'bar' }),
|
|
|
|
|
text('baz'),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('disallow other syntax', () => {
|
2019-01-29 22:27:54 -08:00
|
|
|
|
const tokens = parsePlain('foo **bar** baz');
|
2019-01-29 22:12:48 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
text('foo **bar** baz'),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2018-09-16 10:45:30 -07:00
|
|
|
|
describe('toHtml', () => {
|
|
|
|
|
it('br', () => {
|
|
|
|
|
const input = 'foo\nbar\nbaz';
|
2018-11-20 12:11:00 -08:00
|
|
|
|
const output = '<p><span>foo<br>bar<br>baz</span></p>';
|
2019-01-29 22:30:05 -08:00
|
|
|
|
assert.equal(toHtml(parse(input)), output);
|
2018-09-16 10:45:30 -07:00
|
|
|
|
});
|
2019-01-29 03:33:28 -08:00
|
|
|
|
|
|
|
|
|
it('br alt', () => {
|
|
|
|
|
const input = 'foo\r\nbar\rbaz';
|
|
|
|
|
const output = '<p><span>foo<br>bar<br>baz</span></p>';
|
2019-01-29 22:30:05 -08:00
|
|
|
|
assert.equal(toHtml(parse(input)), output);
|
2019-01-29 03:33:28 -08:00
|
|
|
|
});
|
2018-09-16 10:45:30 -07:00
|
|
|
|
});
|
2018-11-20 12:11:00 -08:00
|
|
|
|
|
|
|
|
|
it('code block with quote', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('> foo\n```\nbar\n```');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
tree('quote', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
|
|
|
|
leaf('blockCode', { code: 'bar', lang: null })
|
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('quote between two code blocks', () => {
|
2019-01-29 22:30:05 -08:00
|
|
|
|
const tokens = parse('```\nbefore\n```\n> foo\n```\nafter\n```');
|
2018-12-20 02:41:04 -08:00
|
|
|
|
assert.deepStrictEqual(tokens, [
|
|
|
|
|
leaf('blockCode', { code: 'before', lang: null }),
|
|
|
|
|
tree('quote', [
|
2018-11-20 12:11:00 -08:00
|
|
|
|
text('foo')
|
2018-12-20 02:41:04 -08:00
|
|
|
|
], {}),
|
|
|
|
|
leaf('blockCode', { code: 'after', lang: null })
|
|
|
|
|
]);
|
2018-11-20 12:11:00 -08:00
|
|
|
|
});
|
2016-12-29 20:28:56 -08:00
|
|
|
|
});
|