diff --git a/test/api.ts b/test/api.ts index 910cd3cd843b4487145ff26e944444119a1cbd65..5e5343d1a641c867a16a7b11fa4a5688f492b560 100644 --- a/test/api.ts +++ b/test/api.ts @@ -1,5 +1,5 @@ import assert from 'assert'; -import { extract, inspect, parse, toString } from '../built/index'; +import * as mfm from '../built/index'; import { TEXT, CENTER, FN, UNI_EMOJI, MENTION, EMOJI_CODE, HASHTAG, N_URL, BOLD, SMALL, ITALIC, STRIKE, QUOTE, MATH_BLOCK, SEARCH, CODE_BLOCK, LINK } from './node'; @@ -17,42 +17,42 @@ I'm @ai, A bot of misskey! https://github.com/syuilo/ai </center> after`; - assert.strictEqual(toString(parse(input)), input); + assert.strictEqual(mfm.toString(mfm.parse(input)), input); }); }); describe('inspect', () => { it('replace text', () => { const input = 'good morning [tada everynyan!]'; - const result = parse(input); - inspect(result, node => { + const result = mfm.parse(input); + mfm.inspect(result, node => { if (node.type == 'text') { node.props.text = node.props.text.replace(/good morning/g, 'hello'); } }); - assert.strictEqual(toString(result), 'hello [tada everynyan!]'); + assert.strictEqual(mfm.toString(result), 'hello [tada everynyan!]'); }); }); describe('extract', () => { it('basic', () => { - const nodes = parse('@hoge @piyo @bebeyo'); + const nodes = mfm.parse('@hoge @piyo @bebeyo'); const expect = [ MENTION('hoge', null, '@hoge'), MENTION('piyo', null, '@piyo'), MENTION('bebeyo', null, '@bebeyo') ]; - assert.deepStrictEqual(extract(nodes, 'mention'), expect); + assert.deepStrictEqual(mfm.extract(nodes, 'mention'), expect); }); it('nested', () => { - const nodes = parse('abc:hoge:[tada 123 @hoge :foo:]:piyo:'); + const nodes = mfm.parse('abc:hoge:[tada 123 @hoge :foo:]:piyo:'); const expect = [ EMOJI_CODE('hoge'), EMOJI_CODE('foo'), EMOJI_CODE('piyo') ]; - assert.deepStrictEqual(extract(nodes, 'emojiCode'), expect); + assert.deepStrictEqual(mfm.extract(nodes, 'emojiCode'), expect); }); }); }); diff --git a/test/node.ts b/test/node.ts index 8f9918d5a2ef6187e02dc64c8cf603e02e980775..b3e4a07ed64d629172b0711245c68d39bcbda9ce 100644 --- a/test/node.ts +++ b/test/node.ts @@ -1,7 +1,7 @@ import { MfmFn, MfmInline, MfmNode, NodeType } from '../built'; - + export const QUOTE = (children: MfmNode[]): NodeType<'quote'> => { return { type:'quote', children }; }; export const SEARCH = (query: string, content: string): NodeType<'search'> => { return { type:'search', props: { query, content } }; }; export const CODE_BLOCK = (code: string, lang: string | null): NodeType<'blockCode'> => { return { type:'blockCode', props: { code, lang } }; }; diff --git a/test/parser.ts b/test/parser.ts index 45cf536c382ab51f21fec53e5640dc66765e00d4..9bfc6846017acbe7f143cd93fd7fd2c8ed13b1c8 100644 --- a/test/parser.ts +++ b/test/parser.ts @@ -1,5 +1,5 @@ import assert from 'assert'; -import { parse } from '../built/index'; +import * as mfm from '../built/index'; import { createNode } from '../built/util'; import { TEXT, CENTER, FN, UNI_EMOJI, MENTION, EMOJI_CODE, HASHTAG, N_URL, BOLD, SMALL, ITALIC, STRIKE, QUOTE, MATH_BLOCK, SEARCH, CODE_BLOCK, LINK @@ -10,7 +10,7 @@ describe('parser', () => { it('普通ã®ãƒ†ã‚ストを入力ã™ã‚‹ã¨1ã¤ã®ãƒ†ã‚ストノードãŒè¿”ã•ã‚Œã‚‹', () => { const input = 'abc'; const output = [TEXT('abc')]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); }); @@ -22,7 +22,7 @@ describe('parser', () => { TEXT('abc') ]) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('複数行ã®å¼•ç”¨ãƒ–ãƒãƒƒã‚¯ã‚’使用ã§ãã‚‹', () => { const input = ` @@ -34,7 +34,7 @@ describe('parser', () => { TEXT('abc\n123') ]) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('引用ブãƒãƒƒã‚¯ã¯ãƒ–ãƒãƒƒã‚¯ã‚’ãƒã‚¹ãƒˆã§ãã‚‹', () => { const input = ` @@ -49,7 +49,7 @@ describe('parser', () => { ]) ]) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('引用ブãƒãƒƒã‚¯ã¯ã‚¤ãƒ³ãƒ©ã‚¤ãƒ³æ§‹æ–‡ã‚’å«ã‚“ã ブãƒãƒƒã‚¯ã‚’ãƒã‚¹ãƒˆã§ãã‚‹', () => { const input = ` @@ -66,7 +66,7 @@ describe('parser', () => { ]) ]) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); }); @@ -80,7 +80,7 @@ describe('parser', () => { content: input }) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('[Search]', () => { const input = 'MFM 書ãæ–¹ 123 [Search]'; @@ -90,7 +90,7 @@ describe('parser', () => { content: input }) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('search', () => { const input = 'MFM 書ãæ–¹ 123 search'; @@ -100,7 +100,7 @@ describe('parser', () => { content: input }) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('[search]', () => { const input = 'MFM 書ãæ–¹ 123 [search]'; @@ -110,7 +110,7 @@ describe('parser', () => { content: input }) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('検索', () => { const input = 'MFM 書ãæ–¹ 123 検索'; @@ -120,7 +120,7 @@ describe('parser', () => { content: input }) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('[検索]', () => { const input = 'MFM 書ãæ–¹ 123 [検索]'; @@ -130,7 +130,7 @@ describe('parser', () => { content: input }) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); }); it('ブãƒãƒƒã‚¯ã®å‰å¾Œã«ã‚るテã‚ストãŒæ£ã—ã解釈ã•ã‚Œã‚‹', () => { @@ -140,7 +140,7 @@ describe('parser', () => { SEARCH('hoge piyo bebeyo', 'hoge piyo bebeyo 検索'), TEXT('123') ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); }); @@ -148,17 +148,17 @@ describe('parser', () => { it('コードブãƒãƒƒã‚¯ã‚’使用ã§ãã‚‹', () => { const input = '```\nabc\n```'; const output = [CODE_BLOCK('abc', null)]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('コードブãƒãƒƒã‚¯ã«ã¯è¤‡æ•°è¡Œã®ã‚³ãƒ¼ãƒ‰ã‚’入力ã§ãã‚‹', () => { const input = '```\na\nb\nc\n```'; const output = [CODE_BLOCK('a\nb\nc', null)]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('コードブãƒãƒƒã‚¯ã¯è¨€èªžã‚’指定ã§ãã‚‹', () => { const input = '```js\nconst a = 1;\n```'; const output = [CODE_BLOCK('const a = 1;', 'js')]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('ブãƒãƒƒã‚¯ã®å‰å¾Œã«ã‚るテã‚ストãŒæ£ã—ã解釈ã•ã‚Œã‚‹', () => { const input = 'abc\n```\nconst abc = 1;\n```\n123'; @@ -167,7 +167,7 @@ describe('parser', () => { CODE_BLOCK('const abc = 1;', null), TEXT('123') ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); }); @@ -177,7 +177,7 @@ describe('parser', () => { const output = [ MATH_BLOCK('math1') ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('ブãƒãƒƒã‚¯ã®å‰å¾Œã«ã‚るテã‚ストãŒæ£ã—ã解釈ã•ã‚Œã‚‹', () => { const input = 'abc\n\\[math1\\]\n123'; @@ -186,21 +186,21 @@ describe('parser', () => { MATH_BLOCK('math1'), TEXT('123') ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('行末以外ã«é–‰ã˜ã‚¿ã‚°ãŒã‚ã‚‹å ´åˆã¯ãƒžãƒƒãƒã—ãªã„', () => { const input = '\\[aaa\\]after'; const output = [ TEXT('\\[aaa\\]after') ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('è¡Œé 以外ã«é–‹å§‹ã‚¿ã‚°ãŒã‚ã‚‹å ´åˆã¯ãƒžãƒƒãƒã—ãªã„', () => { const input = 'before\\[aaa\\]'; const output = [ TEXT('before\\[aaa\\]') ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); }); @@ -212,7 +212,7 @@ describe('parser', () => { TEXT('abc') ]) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('multiple text', () => { const input = 'before\n<center>\nabc\n123\n\npiyo\n</center>\nafter'; @@ -223,7 +223,7 @@ describe('parser', () => { ]), TEXT('after') ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); }); @@ -231,7 +231,7 @@ describe('parser', () => { it('basic', () => { const input = ':abc:'; const output = [EMOJI_CODE('abc')]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); }); @@ -239,7 +239,7 @@ describe('parser', () => { it('basic', () => { const input = '今起ããŸðŸ˜‡'; const output = [TEXT('今起ããŸ'), UNI_EMOJI('😇')]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); }); @@ -251,7 +251,7 @@ describe('parser', () => { TEXT('abc') ]) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('内容ã«ã¯ã‚¤ãƒ³ãƒ©ã‚¤ãƒ³æ§‹æ–‡ã‚’利用ã§ãã‚‹', () => { const input = '***123**abc**123***'; @@ -264,7 +264,7 @@ describe('parser', () => { TEXT('123') ]) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('内容ã¯æ”¹è¡Œã§ãã‚‹', () => { const input = '***123\n**abc**\n123***'; @@ -277,7 +277,7 @@ describe('parser', () => { TEXT('\n123') ]) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); }); @@ -289,7 +289,7 @@ describe('parser', () => { TEXT('abc') ]) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('内容ã«ã¯ã‚¤ãƒ³ãƒ©ã‚¤ãƒ³æ§‹æ–‡ã‚’利用ã§ãã‚‹', () => { const input = '**123~~abc~~123**'; @@ -302,7 +302,7 @@ describe('parser', () => { TEXT('123') ]) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('内容ã¯æ”¹è¡Œã§ãã‚‹', () => { const input = '**123\n~~abc~~\n123**'; @@ -315,7 +315,7 @@ describe('parser', () => { TEXT('\n123') ]) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); }); @@ -327,7 +327,7 @@ describe('parser', () => { TEXT('abc') ]) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('内容ã«ã¯ã‚¤ãƒ³ãƒ©ã‚¤ãƒ³æ§‹æ–‡ã‚’利用ã§ãã‚‹', () => { const input = '<small>abc**123**abc</small>'; @@ -340,7 +340,7 @@ describe('parser', () => { TEXT('abc') ]) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('内容ã¯æ”¹è¡Œã§ãã‚‹', () => { const input = '<small>abc\n**123**\nabc</small>'; @@ -353,7 +353,7 @@ describe('parser', () => { TEXT('\nabc') ]) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); }); @@ -365,7 +365,7 @@ describe('parser', () => { TEXT('abc') ]) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('内容ã«ã¯ã‚¤ãƒ³ãƒ©ã‚¤ãƒ³æ§‹æ–‡ã‚’利用ã§ãã‚‹', () => { const input = '<i>abc**123**abc</i>'; @@ -378,7 +378,7 @@ describe('parser', () => { TEXT('abc') ]) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('内容ã¯æ”¹è¡Œã§ãã‚‹', () => { const input = '<i>abc\n**123**\nabc</i>'; @@ -391,7 +391,7 @@ describe('parser', () => { TEXT('\nabc') ]) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); }); @@ -403,7 +403,7 @@ describe('parser', () => { TEXT('abc') ]) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); }); @@ -419,7 +419,7 @@ describe('parser', () => { it('and unicode emoji', () => { const input = '#ï¸âƒ£abc123#abc'; const output = [UNI_EMOJI('#ï¸âƒ£'), TEXT('abc123'), HASHTAG('abc')]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); }); @@ -431,7 +431,7 @@ describe('parser', () => { N_URL('https://misskey.io/@ai'), TEXT('.') ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); }); @@ -444,7 +444,7 @@ describe('parser', () => { ]), TEXT('.') ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('silent flag', () => { @@ -455,7 +455,7 @@ describe('parser', () => { ]), TEXT('.') ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('do not yield url node even if label is recognisable as a url', () => { @@ -467,7 +467,7 @@ describe('parser', () => { ]), TEXT('.') ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); it('do not yield link node even if label is recognisable as a link', () => { @@ -479,7 +479,7 @@ describe('parser', () => { ]), TEXT('.') ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); }); @@ -491,7 +491,7 @@ describe('parser', () => { TEXT('abc') ]) ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); }); @@ -521,6 +521,6 @@ after`; ]), TEXT('after') ]; - assert.deepStrictEqual(parse(input), output); + assert.deepStrictEqual(mfm.parse(input), output); }); });