From 97a362cf1ae404df40cd61231c98b9701304826e Mon Sep 17 00:00:00 2001 From: marihachi <marihachi0620@gmail.com> Date: Sun, 21 Mar 2021 00:37:59 +0900 Subject: [PATCH] update test --- test/block.ts | 71 ---------------------- test/inline.ts | 49 --------------- test/main.ts | 161 +++++++++++++++++++++++++++++++++++++++++++++++++ test/node.ts | 15 +++-- 4 files changed, 170 insertions(+), 126 deletions(-) delete mode 100644 test/block.ts delete mode 100644 test/inline.ts create mode 100644 test/main.ts diff --git a/test/block.ts b/test/block.ts deleted file mode 100644 index 72e8319..0000000 --- a/test/block.ts +++ /dev/null @@ -1,71 +0,0 @@ -import assert from 'assert'; -import { parse, parsePlain } from '../built/index'; -import { createNode } from '../built/mfm-node'; -import { - TEXT, EMOJI -} from './node'; - -describe('search', () => { - describe('basic', () => { - it('Search', () => { - const input = 'MFM 書ãæ–¹ 123 Search'; - const output = [ - createNode('search', { - query: 'MFM 書ãæ–¹ 123', - content: input - }) - ]; - assert.deepStrictEqual(parse(input), output); - }); - it('[Search]', () => { - const input = 'MFM 書ãæ–¹ 123 [Search]'; - const output = [ - createNode('search', { - query: 'MFM 書ãæ–¹ 123', - content: input - }) - ]; - assert.deepStrictEqual(parse(input), output); - }); - it('search', () => { - const input = 'MFM 書ãæ–¹ 123 search'; - const output = [ - createNode('search', { - query: 'MFM 書ãæ–¹ 123', - content: input - }) - ]; - assert.deepStrictEqual(parse(input), output); - }); - it('[search]', () => { - const input = 'MFM 書ãæ–¹ 123 [search]'; - const output = [ - createNode('search', { - query: 'MFM 書ãæ–¹ 123', - content: input - }) - ]; - assert.deepStrictEqual(parse(input), output); - }); - it('検索', () => { - const input = 'MFM 書ãæ–¹ 123 検索'; - const output = [ - createNode('search', { - query: 'MFM 書ãæ–¹ 123', - content: input - }) - ]; - assert.deepStrictEqual(parse(input), output); - }); - it('[検索]', () => { - const input = 'MFM 書ãæ–¹ 123 [検索]'; - const output = [ - createNode('search', { - query: 'MFM 書ãæ–¹ 123', - content: input - }) - ]; - assert.deepStrictEqual(parse(input), output); - }); - }); -}); diff --git a/test/inline.ts b/test/inline.ts deleted file mode 100644 index 06b9ace..0000000 --- a/test/inline.ts +++ /dev/null @@ -1,49 +0,0 @@ -import assert from 'assert'; -import { parse, parsePlain } from '../built/index'; -import { createNode } from '../built/mfm-node'; -import { - TEXT, EMOJI, UNI_EMOJI, HASHTAG, N_URL -} from './node'; - -describe('text', () => { - it('basic', () => { - const input = 'abc'; - const output = [TEXT('abc')]; - assert.deepStrictEqual(parse(input), output); - }); -}); -describe('custom emoji', () => { - it('basic', () => { - const input = ':abc:'; - const output = [EMOJI('abc')]; - assert.deepStrictEqual(parse(input), output); - }); -}); - -describe('unicode emoji', () => { - it('basic', () => { - const input = '今起ããŸðŸ˜‡'; - const output = [TEXT('今起ããŸ'), UNI_EMOJI('😇')]; - assert.deepStrictEqual(parse(input), output); - }); -}); - -describe('hashtag', () => { - it('and unicode emoji', () => { - const input = '#ï¸âƒ£abc123#abc'; - const output = [UNI_EMOJI('#ï¸âƒ£'), TEXT('abc123'), HASHTAG('abc')]; - assert.deepStrictEqual(parse(input), output); - }); -}); - -describe('url', () => { - it('basic', () => { - const input = 'official instance: https://misskey.io/@ai.'; - const output = [ - TEXT('official instance: '), - N_URL('https://misskey.io/@ai'), - TEXT('.') - ]; - assert.deepStrictEqual(parse(input), output); - }); -}); diff --git a/test/main.ts b/test/main.ts new file mode 100644 index 0000000..c67822c --- /dev/null +++ b/test/main.ts @@ -0,0 +1,161 @@ +import assert from 'assert'; +import { parse, parsePlain } from '../built/index'; +import { createNode } from '../built/util'; +import { + TEXT, CENTER, FN, UNI_EMOJI, MENTION, CUSTOM_EMOJI, HASHTAG, N_URL +} from './node'; + +describe('text', () => { + it('basic', () => { + const input = 'abc'; + const output = [TEXT('abc')]; + assert.deepStrictEqual(parse(input), output); + }); +}); +describe('custom emoji', () => { + it('basic', () => { + const input = ':abc:'; + const output = [CUSTOM_EMOJI('abc')]; + assert.deepStrictEqual(parse(input), output); + }); +}); + +describe('unicode emoji', () => { + it('basic', () => { + const input = '今起ããŸðŸ˜‡'; + const output = [TEXT('今起ããŸ'), UNI_EMOJI('😇')]; + assert.deepStrictEqual(parse(input), output); + }); +}); + +describe('hashtag', () => { + it('and unicode emoji', () => { + const input = '#ï¸âƒ£abc123#abc'; + const output = [UNI_EMOJI('#ï¸âƒ£'), TEXT('abc123'), HASHTAG('abc')]; + assert.deepStrictEqual(parse(input), output); + }); +}); + +describe('url', () => { + it('basic', () => { + const input = 'official instance: https://misskey.io/@ai.'; + const output = [ + TEXT('official instance: '), + N_URL('https://misskey.io/@ai'), + TEXT('.') + ]; + assert.deepStrictEqual(parse(input), output); + }); +}); + +describe('search', () => { + describe('basic', () => { + it('Search', () => { + const input = 'MFM 書ãæ–¹ 123 Search'; + const output = [ + createNode('search', { + query: 'MFM 書ãæ–¹ 123', + content: input + }) + ]; + assert.deepStrictEqual(parse(input), output); + }); + it('[Search]', () => { + const input = 'MFM 書ãæ–¹ 123 [Search]'; + const output = [ + createNode('search', { + query: 'MFM 書ãæ–¹ 123', + content: input + }) + ]; + assert.deepStrictEqual(parse(input), output); + }); + it('search', () => { + const input = 'MFM 書ãæ–¹ 123 search'; + const output = [ + createNode('search', { + query: 'MFM 書ãæ–¹ 123', + content: input + }) + ]; + assert.deepStrictEqual(parse(input), output); + }); + it('[search]', () => { + const input = 'MFM 書ãæ–¹ 123 [search]'; + const output = [ + createNode('search', { + query: 'MFM 書ãæ–¹ 123', + content: input + }) + ]; + assert.deepStrictEqual(parse(input), output); + }); + it('検索', () => { + const input = 'MFM 書ãæ–¹ 123 検索'; + const output = [ + createNode('search', { + query: 'MFM 書ãæ–¹ 123', + content: input + }) + ]; + assert.deepStrictEqual(parse(input), output); + }); + it('[検索]', () => { + const input = 'MFM 書ãæ–¹ 123 [検索]'; + const output = [ + createNode('search', { + query: 'MFM 書ãæ–¹ 123', + content: input + }) + ]; + assert.deepStrictEqual(parse(input), output); + }); + }); +}); + +describe('center', () => { + it('single text', () => { + const input = '<center>abc</center>'; + const output = [ + CENTER([ + TEXT('abc') + ]) + ]; + assert.deepStrictEqual(parse(input), output); + }); + it('multiple text', () => { + const input = '<center>\nabc\n123\n\npiyo\n</center>'; + const output = [ + CENTER([ + TEXT('\nabc\n123\n\npiyo\n') + ]) + ]; + assert.deepStrictEqual(parse(input), output); + }); +}); + +it('composite', () => { + const input = +`<center> +Hello [tada everynyan! 🎉] + +I'm @ai, A bot of misskey! + +https://github.com/syuilo/ai +</center>`; + const output = [ + CENTER([ + TEXT('\nHello '), + FN('tada', { }, [ + TEXT('everynyan! '), + UNI_EMOJI('🎉') + ]), + TEXT('\n\nI\'m '), + MENTION('ai', null, '@ai'), + TEXT(', A bot of misskey!\n\n'), + N_URL('https://github.com/syuilo/ai'), + TEXT('\n') + ]) + ]; + assert.deepStrictEqual(parse(input), output); +}); diff --git a/test/node.ts b/test/node.ts index 2e04d2a..f81ea91 100644 --- a/test/node.ts +++ b/test/node.ts @@ -1,7 +1,10 @@ -import { createNode } from '../built/mfm-node'; +import { MfmCenter, MfmEmoji, MfmFn, MfmHashtag, MfmInline, MfmMention, MfmText, MfmUrl } from '../built'; -export const TEXT = (value: string) => createNode('text', { text: value }); -export const EMOJI = (name: string) => createNode('emoji', { name: name }); -export const UNI_EMOJI = (value: string) => createNode('emoji', { emoji: value }); -export const HASHTAG = (value: string) => createNode('hashtag', { hashtag: value }); -export const N_URL = (value: string) => createNode('url', { url: value }); +export const TEXT = (value: string): MfmText => { return { type:'text', props: { text: value }, children: [] }; }; +export const CUSTOM_EMOJI = (name: string): MfmEmoji => { return { type:'emoji', props: { name: name }, children: [] }; }; +export const UNI_EMOJI = (value: string): MfmEmoji => { return { type:'emoji', props: { emoji: value }, children: [] }; }; +export const HASHTAG = (value: string): MfmHashtag => { return { type:'hashtag', props: { hashtag: value }, children: [] }; }; +export const N_URL = (value: string): MfmUrl => { return { type:'url', props: { url: value }, children: [] }; }; +export const CENTER = (children: MfmInline[]): MfmCenter => { return { type:'center', props: { }, children }; }; +export const FN = (name: string, args: MfmFn['props']['args'], children: MfmFn['children']): MfmFn => { return { type:'fn', props: { name, args }, children }; }; +export const MENTION = (username: string, host: string | null, acct: string): MfmMention => { return { type:'mention', props: { username, host, acct }, children: [] }; }; -- GitLab