Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
marihachi committed Mar 20, 2021
1 parent b15e4d3 commit 97a362c
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 126 deletions.
71 changes: 0 additions & 71 deletions test/block.ts

This file was deleted.

49 changes: 0 additions & 49 deletions test/inline.ts

This file was deleted.

161 changes: 161 additions & 0 deletions test/main.ts
Original file line number Diff line number Diff line change
@@ -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);
});
15 changes: 9 additions & 6 deletions test/node.ts
Original file line number Diff line number Diff line change
@@ -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: [] }; };

0 comments on commit 97a362c

Please sign in to comment.