update test

This commit is contained in:
marihachi 2021-03-22 01:43:52 +09:00
parent 97a362cf1a
commit 453a412efe
2 changed files with 201 additions and 7 deletions

View file

@ -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 = '<small>abc</small>';
const output = [
SMALL([
TEXT('abc')
])
];
assert.deepStrictEqual(parse(input), output);
});
it('内容にはインライン構文を利用できる', () => {
const input = '<small>abc**123**abc</small>';
const output = [
SMALL([
TEXT('abc'),
BOLD([
TEXT('123')
]),
TEXT('abc')
])
];
assert.deepStrictEqual(parse(input), output);
});
it('内容は改行できる', () => {
const input = '<small>abc\n**123**\nabc</small>';
const output = [
SMALL([
TEXT('abc\n'),
BOLD([
TEXT('123')
]),
TEXT('\nabc')
])
];
assert.deepStrictEqual(parse(input), output);
});
});
describe('italic 1', () => {
it('basic', () => {
const input = '<i>abc</i>';
const output = [
ITALIC([
TEXT('abc')
])
];
assert.deepStrictEqual(parse(input), output);
});
it('内容にはインライン構文を利用できる', () => {
const input = '<i>abc**123**abc</i>';
const output = [
ITALIC([
TEXT('abc'),
BOLD([
TEXT('123')
]),
TEXT('abc')
])
];
assert.deepStrictEqual(parse(input), output);
});
it('内容は改行できる', () => {
const input = '<i>abc\n**123**\nabc</i>';
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:';

View file

@ -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: [] }; };