Improve readability and some cleanups
This commit is contained in:
parent
54ce19bd56
commit
50b809784f
1 changed files with 67 additions and 20 deletions
87
test/mfm.ts
87
test/mfm.ts
|
@ -152,9 +152,19 @@ describe('MFM', () => {
|
||||||
it('can be analyzed', () => {
|
it('can be analyzed', () => {
|
||||||
const tokens = analyze('@himawari @hima_sub@namori.net お腹ペコい :cat: #yryr');
|
const tokens = analyze('@himawari @hima_sub@namori.net お腹ペコい :cat: #yryr');
|
||||||
assert.deepStrictEqual(tokens, [
|
assert.deepStrictEqual(tokens, [
|
||||||
leaf('mention', { acct: '@himawari', canonical: '@himawari', username: 'himawari', host: null }),
|
leaf('mention', {
|
||||||
|
acct: '@himawari',
|
||||||
|
canonical: '@himawari',
|
||||||
|
username: 'himawari',
|
||||||
|
host: null
|
||||||
|
}),
|
||||||
text(' '),
|
text(' '),
|
||||||
leaf('mention', { acct: '@hima_sub@namori.net', canonical: '@hima_sub@namori.net', username: 'hima_sub', host: 'namori.net' }),
|
leaf('mention', {
|
||||||
|
acct: '@hima_sub@namori.net',
|
||||||
|
canonical: '@hima_sub@namori.net',
|
||||||
|
username: 'hima_sub',
|
||||||
|
host: 'namori.net'
|
||||||
|
}),
|
||||||
text(' お腹ペコい '),
|
text(' お腹ペコい '),
|
||||||
leaf('emoji', { name: 'cat' }),
|
leaf('emoji', { name: 'cat' }),
|
||||||
text(' '),
|
text(' '),
|
||||||
|
@ -280,7 +290,12 @@ describe('MFM', () => {
|
||||||
it('local', () => {
|
it('local', () => {
|
||||||
const tokens = analyze('@himawari foo');
|
const tokens = analyze('@himawari foo');
|
||||||
assert.deepStrictEqual(tokens, [
|
assert.deepStrictEqual(tokens, [
|
||||||
leaf('mention', { acct: '@himawari', canonical: '@himawari', username: 'himawari', host: null }),
|
leaf('mention', {
|
||||||
|
acct: '@himawari',
|
||||||
|
canonical: '@himawari',
|
||||||
|
username: 'himawari',
|
||||||
|
host: null
|
||||||
|
}),
|
||||||
text(' foo')
|
text(' foo')
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
@ -288,7 +303,12 @@ describe('MFM', () => {
|
||||||
it('remote', () => {
|
it('remote', () => {
|
||||||
const tokens = analyze('@hima_sub@namori.net foo');
|
const tokens = analyze('@hima_sub@namori.net foo');
|
||||||
assert.deepStrictEqual(tokens, [
|
assert.deepStrictEqual(tokens, [
|
||||||
leaf('mention', { acct: '@hima_sub@namori.net', canonical: '@hima_sub@namori.net', username: 'hima_sub', host: 'namori.net' }),
|
leaf('mention', {
|
||||||
|
acct: '@hima_sub@namori.net',
|
||||||
|
canonical: '@hima_sub@namori.net',
|
||||||
|
username: 'hima_sub',
|
||||||
|
host: 'namori.net'
|
||||||
|
}),
|
||||||
text(' foo')
|
text(' foo')
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
@ -296,7 +316,12 @@ describe('MFM', () => {
|
||||||
it('remote punycode', () => {
|
it('remote punycode', () => {
|
||||||
const tokens = analyze('@hima_sub@xn--q9j5bya.xn--zckzah foo');
|
const tokens = analyze('@hima_sub@xn--q9j5bya.xn--zckzah foo');
|
||||||
assert.deepStrictEqual(tokens, [
|
assert.deepStrictEqual(tokens, [
|
||||||
leaf('mention', { acct: '@hima_sub@xn--q9j5bya.xn--zckzah', canonical: '@hima_sub@なもり.テスト', username: 'hima_sub', host: 'xn--q9j5bya.xn--zckzah' }),
|
leaf('mention', {
|
||||||
|
acct: '@hima_sub@xn--q9j5bya.xn--zckzah',
|
||||||
|
canonical: '@hima_sub@なもり.テスト',
|
||||||
|
username: 'hima_sub',
|
||||||
|
host: 'xn--q9j5bya.xn--zckzah'
|
||||||
|
}),
|
||||||
text(' foo')
|
text(' foo')
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
@ -309,11 +334,26 @@ describe('MFM', () => {
|
||||||
|
|
||||||
const tokens2 = analyze('@a\n@b\n@c');
|
const tokens2 = analyze('@a\n@b\n@c');
|
||||||
assert.deepStrictEqual(tokens2, [
|
assert.deepStrictEqual(tokens2, [
|
||||||
leaf('mention', { acct: '@a', canonical: '@a', username: 'a', host: null }),
|
leaf('mention', {
|
||||||
|
acct: '@a',
|
||||||
|
canonical: '@a',
|
||||||
|
username: 'a',
|
||||||
|
host: null
|
||||||
|
}),
|
||||||
text('\n'),
|
text('\n'),
|
||||||
leaf('mention', { acct: '@b', canonical: '@b', username: 'b', host: null }),
|
leaf('mention', {
|
||||||
|
acct: '@b',
|
||||||
|
canonical: '@b',
|
||||||
|
username: 'b',
|
||||||
|
host: null
|
||||||
|
}),
|
||||||
text('\n'),
|
text('\n'),
|
||||||
leaf('mention', { acct: '@c', canonical: '@c', username: 'c', host: null })
|
leaf('mention', {
|
||||||
|
acct: '@c',
|
||||||
|
canonical: '@c',
|
||||||
|
username: 'c',
|
||||||
|
host: null
|
||||||
|
})
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const tokens3 = analyze('**x**@a');
|
const tokens3 = analyze('**x**@a');
|
||||||
|
@ -321,24 +361,31 @@ describe('MFM', () => {
|
||||||
tree('bold', [
|
tree('bold', [
|
||||||
text('x')
|
text('x')
|
||||||
], {}),
|
], {}),
|
||||||
leaf('mention', { acct: '@a', canonical: '@a', username: 'a', host: null })
|
leaf('mention', {
|
||||||
|
acct: '@a',
|
||||||
|
canonical: '@a',
|
||||||
|
username: 'a',
|
||||||
|
host: null
|
||||||
|
})
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const tokens4 = analyze('@\n@v\n@veryverylongusername' /* \n@toolongtobeasamention */);
|
const tokens4 = analyze('@\n@v\n@veryverylongusername');
|
||||||
assert.deepStrictEqual(tokens4, [
|
assert.deepStrictEqual(tokens4, [
|
||||||
text('@\n'),
|
text('@\n'),
|
||||||
leaf('mention', { acct: '@v', canonical: '@v', username: 'v', host: null }),
|
leaf('mention', {
|
||||||
|
acct: '@v',
|
||||||
|
canonical: '@v',
|
||||||
|
username: 'v',
|
||||||
|
host: null
|
||||||
|
}),
|
||||||
text('\n'),
|
text('\n'),
|
||||||
leaf('mention', { acct: '@veryverylongusername', canonical: '@veryverylongusername', username: 'veryverylongusername', host: null }),
|
leaf('mention', {
|
||||||
// text('\n@toolongtobeasamention')
|
acct: '@veryverylongusername',
|
||||||
|
canonical: '@veryverylongusername',
|
||||||
|
username: 'veryverylongusername',
|
||||||
|
host: null
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
/*
|
|
||||||
const tokens5 = analyze('@domain_is@valid.example.com\n@domain_is@.invalid\n@domain_is@invali.d\n@domain_is@invali.d\n@domain_is@-invalid.com\n@domain_is@invalid-.com');
|
|
||||||
assert.deepStrictEqual([
|
|
||||||
leaf('mention', { acct: '@domain_is@valid.example.com', canonical: '@domain_is@valid.example.com', username: 'domain_is', host: 'valid.example.com' }),
|
|
||||||
text('\n@domain_is@.invalid\n@domain_is@invali.d\n@domain_is@invali.d\n@domain_is@-invalid.com\n@domain_is@invalid-.com')
|
|
||||||
], tokens5);
|
|
||||||
*/
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue