[wip] update test

This commit is contained in:
marihachi 2021-03-27 19:51:39 +09:00
parent 372cd47035
commit 3c5cd201a6

View file

@ -2,7 +2,7 @@ import assert from 'assert';
import { inspect, parse, parsePlain, toString } from '../built/index'; import { inspect, parse, parsePlain, toString } from '../built/index';
import { createNode } from '../built/util'; import { createNode } from '../built/util';
import { import {
TEXT, CENTER, FN, UNI_EMOJI, MENTION, CUSTOM_EMOJI, HASHTAG, N_URL, BOLD, SMALL, ITALIC, STRIKE, QUOTE TEXT, CENTER, FN, UNI_EMOJI, MENTION, CUSTOM_EMOJI, HASHTAG, N_URL, BOLD, SMALL, ITALIC, STRIKE, QUOTE, MATH_BLOCK, SEARCH, CODE_BLOCK
} from './node'; } from './node';
describe('text', () => { describe('text', () => {
@ -29,11 +29,9 @@ describe('quote', () => {
> 123 > 123
`; `;
const output = [ const output = [
TEXT('\n'),
QUOTE([ QUOTE([
TEXT('abc\n123') TEXT('abc\n123')
]), ])
TEXT('\n')
]; ];
assert.deepStrictEqual(parse(input), output); assert.deepStrictEqual(parse(input), output);
}); });
@ -45,13 +43,11 @@ describe('quote', () => {
> </center> > </center>
`; `;
const output = [ const output = [
TEXT('\n'),
QUOTE([ QUOTE([
CENTER([ CENTER([
TEXT('\na\n') TEXT('a')
]) ])
]), ])
TEXT('\n')
]; ];
assert.deepStrictEqual(parse(input), output); assert.deepStrictEqual(parse(input), output);
}); });
@ -63,30 +59,164 @@ describe('quote', () => {
> </center> > </center>
`; `;
const output = [ const output = [
TEXT('\n'),
QUOTE([ QUOTE([
CENTER([ CENTER([
TEXT('\nI\'m '), TEXT('I\'m '),
MENTION('ai', null, '@ai'), MENTION('ai', null, '@ai'),
TEXT(', An bot of misskey!\n'), TEXT(', An bot of misskey!'),
]) ])
]), ])
TEXT('\n')
]; ];
assert.deepStrictEqual(parse(input), output); assert.deepStrictEqual(parse(input), output);
}); });
}); });
describe('fn', () => { describe('search', () => {
it('basic', () => { describe('basic', () => {
const input = '[tada abc]'; 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);
});
});
it('with text', () => {
const input = 'abc\nhoge piyo bebeyo 検索\n123';
const output = [ const output = [
FN('tada', { }, [ TEXT('abc'),
SEARCH('hoge piyo bebeyo', 'hoge piyo bebeyo 検索'),
TEXT('123')
];
assert.deepStrictEqual(parse(input), output);
});
});
describe('code block', () => {
it('basic', () => {
const input = '```\nabc\n```';
const output = [CODE_BLOCK('abc', null)];
assert.deepStrictEqual(parse(input), output);
});
it('with text', () => {
const input = 'abc\n```\nconst abc = 1;\n```\n123';
const output = [
TEXT('abc'),
CODE_BLOCK('const abc = 1;', null),
TEXT('123')
];
assert.deepStrictEqual(parse(input), output);
});
});
describe('mathBlock', () => {
it('basic', () => {
const input = '123\n\\[math1\\]\nabc\n\\[math2\\]';
const output = [
TEXT('123'),
MATH_BLOCK('math1'),
TEXT('abc'),
MATH_BLOCK('math2')
];
assert.deepStrictEqual(parse(input), output);
});
it('case of no matched', () => {
const input = '\\[aaa\\]\\[bbb\\]';
const output = [
TEXT('\\[aaa\\]\\[bbb\\]')
];
assert.deepStrictEqual(parse(input), output);
});
});
describe('center', () => {
it('single text', () => {
const input = '<center>abc</center>';
const output = [
CENTER([
TEXT('abc') TEXT('abc')
]) ])
]; ];
assert.deepStrictEqual(parse(input), output); 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);
});
});
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('big', () => { describe('big', () => {
@ -253,22 +383,13 @@ describe('italic 2', () => {
}); });
}); });
// strike
describe('custom emoji', () => { // inlineCode
it('basic', () => {
const input = ':abc:';
const output = [CUSTOM_EMOJI('abc')];
assert.deepStrictEqual(parse(input), output);
});
});
describe('unicode emoji', () => { // mathInline
it('basic', () => {
const input = '今起きた😇'; // mention
const output = [TEXT('今起きた'), UNI_EMOJI('😇')];
assert.deepStrictEqual(parse(input), output);
});
});
describe('hashtag', () => { describe('hashtag', () => {
it('and unicode emoji', () => { it('and unicode emoji', () => {
@ -290,90 +411,18 @@ describe('url', () => {
}); });
}); });
describe('search', () => { // link
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', () => { describe('fn', () => {
it('single text', () => { it('basic', () => {
const input = '<center>abc</center>'; const input = '[tada abc]';
const output = [ const output = [
CENTER([ FN('tada', { }, [
TEXT('abc') TEXT('abc')
]) ])
]; ];
assert.deepStrictEqual(parse(input), output); 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', () => { it('composite', () => {