Skip to content

Commit 97a362c

Browse files
committed
update test
1 parent b15e4d3 commit 97a362c

File tree

4 files changed

+170
-126
lines changed

4 files changed

+170
-126
lines changed

Diff for: test/block.ts

-71
This file was deleted.

Diff for: test/inline.ts

-49
This file was deleted.

Diff for: test/main.ts

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
import assert from 'assert';
2+
import { parse, parsePlain } from '../built/index';
3+
import { createNode } from '../built/util';
4+
import {
5+
TEXT, CENTER, FN, UNI_EMOJI, MENTION, CUSTOM_EMOJI, HASHTAG, N_URL
6+
} from './node';
7+
8+
describe('text', () => {
9+
it('basic', () => {
10+
const input = 'abc';
11+
const output = [TEXT('abc')];
12+
assert.deepStrictEqual(parse(input), output);
13+
});
14+
});
15+
describe('custom emoji', () => {
16+
it('basic', () => {
17+
const input = ':abc:';
18+
const output = [CUSTOM_EMOJI('abc')];
19+
assert.deepStrictEqual(parse(input), output);
20+
});
21+
});
22+
23+
describe('unicode emoji', () => {
24+
it('basic', () => {
25+
const input = '今起きた😇';
26+
const output = [TEXT('今起きた'), UNI_EMOJI('😇')];
27+
assert.deepStrictEqual(parse(input), output);
28+
});
29+
});
30+
31+
describe('hashtag', () => {
32+
it('and unicode emoji', () => {
33+
const input = '#️⃣abc123#abc';
34+
const output = [UNI_EMOJI('#️⃣'), TEXT('abc123'), HASHTAG('abc')];
35+
assert.deepStrictEqual(parse(input), output);
36+
});
37+
});
38+
39+
describe('url', () => {
40+
it('basic', () => {
41+
const input = 'official instance: https://misskey.io/@ai.';
42+
const output = [
43+
TEXT('official instance: '),
44+
N_URL('https://misskey.io/@ai'),
45+
TEXT('.')
46+
];
47+
assert.deepStrictEqual(parse(input), output);
48+
});
49+
});
50+
51+
describe('search', () => {
52+
describe('basic', () => {
53+
it('Search', () => {
54+
const input = 'MFM 書き方 123 Search';
55+
const output = [
56+
createNode('search', {
57+
query: 'MFM 書き方 123',
58+
content: input
59+
})
60+
];
61+
assert.deepStrictEqual(parse(input), output);
62+
});
63+
it('[Search]', () => {
64+
const input = 'MFM 書き方 123 [Search]';
65+
const output = [
66+
createNode('search', {
67+
query: 'MFM 書き方 123',
68+
content: input
69+
})
70+
];
71+
assert.deepStrictEqual(parse(input), output);
72+
});
73+
it('search', () => {
74+
const input = 'MFM 書き方 123 search';
75+
const output = [
76+
createNode('search', {
77+
query: 'MFM 書き方 123',
78+
content: input
79+
})
80+
];
81+
assert.deepStrictEqual(parse(input), output);
82+
});
83+
it('[search]', () => {
84+
const input = 'MFM 書き方 123 [search]';
85+
const output = [
86+
createNode('search', {
87+
query: 'MFM 書き方 123',
88+
content: input
89+
})
90+
];
91+
assert.deepStrictEqual(parse(input), output);
92+
});
93+
it('検索', () => {
94+
const input = 'MFM 書き方 123 検索';
95+
const output = [
96+
createNode('search', {
97+
query: 'MFM 書き方 123',
98+
content: input
99+
})
100+
];
101+
assert.deepStrictEqual(parse(input), output);
102+
});
103+
it('[検索]', () => {
104+
const input = 'MFM 書き方 123 [検索]';
105+
const output = [
106+
createNode('search', {
107+
query: 'MFM 書き方 123',
108+
content: input
109+
})
110+
];
111+
assert.deepStrictEqual(parse(input), output);
112+
});
113+
});
114+
});
115+
116+
describe('center', () => {
117+
it('single text', () => {
118+
const input = '<center>abc</center>';
119+
const output = [
120+
CENTER([
121+
TEXT('abc')
122+
])
123+
];
124+
assert.deepStrictEqual(parse(input), output);
125+
});
126+
it('multiple text', () => {
127+
const input = '<center>\nabc\n123\n\npiyo\n</center>';
128+
const output = [
129+
CENTER([
130+
TEXT('\nabc\n123\n\npiyo\n')
131+
])
132+
];
133+
assert.deepStrictEqual(parse(input), output);
134+
});
135+
});
136+
137+
it('composite', () => {
138+
const input =
139+
`<center>
140+
Hello [tada everynyan! 🎉]
141+
142+
I'm @ai, A bot of misskey!
143+
144+
https://github.com/syuilo/ai
145+
</center>`;
146+
const output = [
147+
CENTER([
148+
TEXT('\nHello '),
149+
FN('tada', { }, [
150+
TEXT('everynyan! '),
151+
UNI_EMOJI('🎉')
152+
]),
153+
TEXT('\n\nI\'m '),
154+
MENTION('ai', null, '@ai'),
155+
TEXT(', A bot of misskey!\n\n'),
156+
N_URL('https://github.com/syuilo/ai'),
157+
TEXT('\n')
158+
])
159+
];
160+
assert.deepStrictEqual(parse(input), output);
161+
});

Diff for: test/node.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import { createNode } from '../built/mfm-node';
1+
import { MfmCenter, MfmEmoji, MfmFn, MfmHashtag, MfmInline, MfmMention, MfmText, MfmUrl } from '../built';
22

3-
export const TEXT = (value: string) => createNode('text', { text: value });
4-
export const EMOJI = (name: string) => createNode('emoji', { name: name });
5-
export const UNI_EMOJI = (value: string) => createNode('emoji', { emoji: value });
6-
export const HASHTAG = (value: string) => createNode('hashtag', { hashtag: value });
7-
export const N_URL = (value: string) => createNode('url', { url: value });
3+
export const TEXT = (value: string): MfmText => { return { type:'text', props: { text: value }, children: [] }; };
4+
export const CUSTOM_EMOJI = (name: string): MfmEmoji => { return { type:'emoji', props: { name: name }, children: [] }; };
5+
export const UNI_EMOJI = (value: string): MfmEmoji => { return { type:'emoji', props: { emoji: value }, children: [] }; };
6+
export const HASHTAG = (value: string): MfmHashtag => { return { type:'hashtag', props: { hashtag: value }, children: [] }; };
7+
export const N_URL = (value: string): MfmUrl => { return { type:'url', props: { url: value }, children: [] }; };
8+
export const CENTER = (children: MfmInline[]): MfmCenter => { return { type:'center', props: { }, children }; };
9+
export const FN = (name: string, args: MfmFn['props']['args'], children: MfmFn['children']): MfmFn => { return { type:'fn', props: { name, args }, children }; };
10+
export const MENTION = (username: string, host: string | null, acct: string): MfmMention => { return { type:'mention', props: { username, host, acct }, children: [] }; };

0 commit comments

Comments
 (0)