2018-12-20 12:41:04 +02:00
|
|
|
import * as assert from 'assert';
|
|
|
|
|
|
|
|
import extractMentions from '../src/misc/extract-mentions';
|
2019-01-30 09:56:27 +02:00
|
|
|
import { parse } from '../src/mfm/parse';
|
2018-12-20 12:41:04 +02:00
|
|
|
|
|
|
|
describe('Extract mentions', () => {
|
|
|
|
it('simple', () => {
|
2020-01-09 07:35:04 +02:00
|
|
|
const ast = parse('@foo @bar @baz')!;
|
2018-12-20 12:41:04 +02:00
|
|
|
const mentions = extractMentions(ast);
|
|
|
|
assert.deepStrictEqual(mentions, [{
|
|
|
|
username: 'foo',
|
|
|
|
acct: '@foo',
|
|
|
|
canonical: '@foo',
|
|
|
|
host: null
|
|
|
|
}, {
|
|
|
|
username: 'bar',
|
|
|
|
acct: '@bar',
|
|
|
|
canonical: '@bar',
|
|
|
|
host: null
|
|
|
|
}, {
|
|
|
|
username: 'baz',
|
|
|
|
acct: '@baz',
|
|
|
|
canonical: '@baz',
|
|
|
|
host: null
|
|
|
|
}]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('nested', () => {
|
2020-01-09 07:35:04 +02:00
|
|
|
const ast = parse('@foo **@bar** @baz')!;
|
2018-12-20 12:41:04 +02:00
|
|
|
const mentions = extractMentions(ast);
|
|
|
|
assert.deepStrictEqual(mentions, [{
|
|
|
|
username: 'foo',
|
|
|
|
acct: '@foo',
|
|
|
|
canonical: '@foo',
|
|
|
|
host: null
|
|
|
|
}, {
|
|
|
|
username: 'bar',
|
|
|
|
acct: '@bar',
|
|
|
|
canonical: '@bar',
|
|
|
|
host: null
|
|
|
|
}, {
|
|
|
|
username: 'baz',
|
|
|
|
acct: '@baz',
|
|
|
|
canonical: '@baz',
|
|
|
|
host: null
|
|
|
|
}]);
|
|
|
|
});
|
|
|
|
});
|