From 453a412efe5132e882462a3b1f0bab6793abba78 Mon Sep 17 00:00:00 2001 From: marihachi Date: Mon, 22 Mar 2021 01:43:52 +0900 Subject: [PATCH] update test --- test/main.ts | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++- test/node.ts | 28 ++++++-- 2 files changed, 201 insertions(+), 7 deletions(-) diff --git a/test/main.ts b/test/main.ts index c67822c..d89a55f 100644 --- a/test/main.ts +++ b/test/main.ts @@ -2,7 +2,7 @@ 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 + TEXT, CENTER, FN, UNI_EMOJI, MENTION, CUSTOM_EMOJI, HASHTAG, N_URL, BOLD, SMALL, ITALIC, STRIKE } from './node'; describe('text', () => { @@ -12,6 +12,184 @@ describe('text', () => { assert.deepStrictEqual(parse(input), output); }); }); + +describe('fn', () => { + it('basic', () => { + const input = '[tada abc]'; + const output = [ + FN('tada', { }, [ + TEXT('abc') + ]) + ]; + assert.deepStrictEqual(parse(input), output); + }); +}); + +describe('big', () => { + it('basic', () => { + const input = '***abc***'; + const output = [ + FN('tada', { }, [ + TEXT('abc') + ]) + ]; + assert.deepStrictEqual(parse(input), output); + }); + it('内容にはインライン構文を利用できる', () => { + const input = '***123**abc**123***'; + const output = [ + FN('tada', { }, [ + TEXT('123'), + BOLD([ + TEXT('abc') + ]), + TEXT('123') + ]) + ]; + assert.deepStrictEqual(parse(input), output); + }); + it('内容は改行できる', () => { + const input = '***123\n**abc**\n123***'; + const output = [ + FN('tada', { }, [ + TEXT('123\n'), + BOLD([ + TEXT('abc') + ]), + TEXT('\n123') + ]) + ]; + assert.deepStrictEqual(parse(input), output); + }); +}); + +describe('bold', () => { + it('basic', () => { + const input = '**abc**'; + const output = [ + BOLD([ + TEXT('abc') + ]) + ]; + assert.deepStrictEqual(parse(input), output); + }); + it('内容にはインライン構文を利用できる', () => { + const input = '**123~~abc~~123**'; + const output = [ + BOLD([ + TEXT('123'), + STRIKE([ + TEXT('abc') + ]), + TEXT('123') + ]) + ]; + assert.deepStrictEqual(parse(input), output); + }); + it('内容は改行できる', () => { + const input = '**123\n~~abc~~\n123**'; + const output = [ + BOLD([ + TEXT('123\n'), + STRIKE([ + TEXT('abc') + ]), + TEXT('\n123') + ]) + ]; + assert.deepStrictEqual(parse(input), output); + }); +}); + +describe('small', () => { + it('basic', () => { + const input = 'abc'; + const output = [ + SMALL([ + TEXT('abc') + ]) + ]; + assert.deepStrictEqual(parse(input), output); + }); + it('内容にはインライン構文を利用できる', () => { + const input = 'abc**123**abc'; + const output = [ + SMALL([ + TEXT('abc'), + BOLD([ + TEXT('123') + ]), + TEXT('abc') + ]) + ]; + assert.deepStrictEqual(parse(input), output); + }); + it('内容は改行できる', () => { + const input = 'abc\n**123**\nabc'; + const output = [ + SMALL([ + TEXT('abc\n'), + BOLD([ + TEXT('123') + ]), + TEXT('\nabc') + ]) + ]; + assert.deepStrictEqual(parse(input), output); + }); +}); + +describe('italic 1', () => { + it('basic', () => { + const input = 'abc'; + const output = [ + ITALIC([ + TEXT('abc') + ]) + ]; + assert.deepStrictEqual(parse(input), output); + }); + it('内容にはインライン構文を利用できる', () => { + const input = 'abc**123**abc'; + const output = [ + ITALIC([ + TEXT('abc'), + BOLD([ + TEXT('123') + ]), + TEXT('abc') + ]) + ]; + assert.deepStrictEqual(parse(input), output); + }); + it('内容は改行できる', () => { + const input = 'abc\n**123**\nabc'; + const output = [ + ITALIC([ + TEXT('abc\n'), + BOLD([ + TEXT('123') + ]), + TEXT('\nabc') + ]) + ]; + assert.deepStrictEqual(parse(input), output); + }); +}); + +describe('italic 2', () => { + it('basic', () => { + const input = '*abc*'; + const output = [ + ITALIC([ + TEXT('abc') + ]) + ]; + assert.deepStrictEqual(parse(input), output); + }); +}); + + describe('custom emoji', () => { it('basic', () => { const input = ':abc:'; diff --git a/test/node.ts b/test/node.ts index f81ea91..de302ad 100644 --- a/test/node.ts +++ b/test/node.ts @@ -1,10 +1,26 @@ -import { MfmCenter, MfmEmoji, MfmFn, MfmHashtag, MfmInline, MfmMention, MfmText, MfmUrl } from '../built'; +import { + MfmBold, MfmCenter, MfmCodeBlock, MfmEmoji, MfmFn, MfmHashtag, MfmInline, + MfmInlineCode, MfmItalic, MfmLink, MfmMathBlock, MfmMathInline, MfmMention, + MfmNode, MfmQuote, MfmSearch, MfmSmall, MfmStrike, MfmText, MfmUrl +} from '../built'; -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 QUOTE = (children: MfmNode[]): MfmQuote => { return { type:'quote', props: { }, children }; }; +export const SEARCH = (q: string, content: string): MfmSearch => { return { type:'search', props: { q, content }, children: [] }; }; +export const CODE_BLOCK = (code: string, lang: string | null): MfmCodeBlock => { return { type:'blockCode', props: { code, lang }, children: [] }; }; +export const MATH_BLOCK = (formula: string): MfmMathBlock => { return { type:'mathBlock', props: { formula }, children: [] }; }; +export const CENTER = (children: MfmInline[]): MfmCenter => { return { type:'center', props: { }, children }; }; + +export const BOLD = (children: MfmInline[]): MfmBold => { return { type:'bold', props: { }, children }; }; +export const SMALL = (children: MfmInline[]): MfmSmall => { return { type:'small', props: { }, children }; }; +export const ITALIC = (children: MfmInline[]): MfmItalic => { return { type:'italic', props: { }, children }; }; +export const STRIKE = (children: MfmInline[]): MfmStrike => { return { type:'strike', props: { }, children }; }; +export const INLINE_CODE = (code: string): MfmInlineCode => { return { type:'inlineCode', props: { code }, children: [] }; }; +export const MATH_INLINE = (formula: string): MfmMathInline => { return { type:'mathInline', props: { formula }, children: [] }; }; +export const MENTION = (username: string, host: string | null, acct: string): MfmMention => { return { type:'mention', props: { username, host, acct }, 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 LINK = (silent: boolean, url: string, children: MfmInline[]): MfmLink => { return { type:'link', props: { silent, url }, children }; }; +export const CUSTOM_EMOJI = (name: string): MfmEmoji => { return { type:'emoji', props: { name: name }, 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: [] }; }; +export const UNI_EMOJI = (value: string): MfmEmoji => { return { type:'emoji', props: { emoji: value }, children: [] }; }; +export const TEXT = (value: string): MfmText => { return { type:'text', props: { text: value }, children: [] }; };