Add url tests

This commit is contained in:
syuilo 2021-06-05 15:56:23 +09:00
parent 229eb1e42a
commit 1ee9f95396

View file

@ -593,6 +593,14 @@ describe('FullParser', () => {
describe('url', () => { describe('url', () => {
it('basic', () => { it('basic', () => {
const input = 'https://misskey.io/@ai';
const output = [
N_URL('https://misskey.io/@ai'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
it('with other texts', () => {
const input = 'official instance: https://misskey.io/@ai.'; const input = 'official instance: https://misskey.io/@ai.';
const output = [ const output = [
TEXT('official instance: '), TEXT('official instance: '),
@ -601,6 +609,105 @@ describe('FullParser', () => {
]; ];
assert.deepStrictEqual(mfm.parse(input), output); assert.deepStrictEqual(mfm.parse(input), output);
}); });
it('ignore trailing period', () => {
const input = 'https://misskey.io/@ai.';
const output = [
N_URL('https://misskey.io/@ai'),
TEXT('.')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
it('ignore trailing periods', () => {
const input = 'https://misskey.io/@ai...';
const output = [
N_URL('https://misskey.io/@ai'),
TEXT('...')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
it('with comma', () => {
const input = 'https://example.com/foo?bar=a,b';
const output = [
N_URL('https://example.com/foo?bar=a,b'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
it('ignore trailing comma', () => {
const input = 'https://example.com/foo, bar';
const output = [
N_URL('https://example.com/foo'),
TEXT(', bar')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
it('with brackets', () => {
const input = 'https://example.com/foo(bar)';
const output = [
N_URL('https://example.com/foo(bar)'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
it('ignore parent brackets', () => {
const input = '(https://example.com/foo)';
const output = [
TEXT('('),
N_URL('https://example.com/foo'),
TEXT(')'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
it('ignore parent brackets (2)', () => {
const input = '(foo https://example.com/foo)';
const output = [
TEXT('(foo '),
N_URL('https://example.com/foo'),
TEXT(')'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
it('ignore parent brackets with internal brackets', () => {
const input = '(https://example.com/foo(bar))';
const output = [
TEXT('('),
N_URL('https://example.com/foo(bar)'),
TEXT(')'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
it('ignore parent []', () => {
const input = 'foo [https://example.com/foo] bar';
const output = [
TEXT('foo ['),
N_URL('https://example.com/foo'),
TEXT('] bar'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
it('ignore non-ascii characters contained url without angle brackets', () => {
const input = 'https://大石泉すき.example.com';
const output = [
TEXT('https://大石泉すき.example.com'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
it('match non-ascii characters contained url with angle brackets', () => {
const input = '<https://大石泉すき.example.com>';
const output = [
N_URL('https://大石泉すき.example.com'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
}); });
describe('link', () => { describe('link', () => {