-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
170 additions
and
126 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [] }; }; |