2018-12-20 04:41:04 -06:00
|
|
|
import * as assert from 'assert';
|
|
|
|
|
2021-04-01 20:36:11 -05:00
|
|
|
import { parse } from 'mfm-js';
|
2022-09-17 13:27:08 -05:00
|
|
|
import { extractMentions } from '../../src/misc/extract-mentions.js';
|
2018-12-20 04:41:04 -06:00
|
|
|
|
|
|
|
describe('Extract mentions', () => {
|
2023-02-02 03:18:25 -06:00
|
|
|
test('simple', () => {
|
2020-01-08 23:35:04 -06:00
|
|
|
const ast = parse('@foo @bar @baz')!;
|
2018-12-20 04:41:04 -06:00
|
|
|
const mentions = extractMentions(ast);
|
|
|
|
assert.deepStrictEqual(mentions, [{
|
|
|
|
username: 'foo',
|
|
|
|
acct: '@foo',
|
2022-05-21 08:21:41 -05:00
|
|
|
host: null,
|
2018-12-20 04:41:04 -06:00
|
|
|
}, {
|
|
|
|
username: 'bar',
|
|
|
|
acct: '@bar',
|
2022-05-21 08:21:41 -05:00
|
|
|
host: null,
|
2018-12-20 04:41:04 -06:00
|
|
|
}, {
|
|
|
|
username: 'baz',
|
|
|
|
acct: '@baz',
|
2022-05-21 08:21:41 -05:00
|
|
|
host: null,
|
2018-12-20 04:41:04 -06:00
|
|
|
}]);
|
|
|
|
});
|
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('nested', () => {
|
2020-01-08 23:35:04 -06:00
|
|
|
const ast = parse('@foo **@bar** @baz')!;
|
2018-12-20 04:41:04 -06:00
|
|
|
const mentions = extractMentions(ast);
|
|
|
|
assert.deepStrictEqual(mentions, [{
|
|
|
|
username: 'foo',
|
|
|
|
acct: '@foo',
|
2022-05-21 08:21:41 -05:00
|
|
|
host: null,
|
2018-12-20 04:41:04 -06:00
|
|
|
}, {
|
|
|
|
username: 'bar',
|
|
|
|
acct: '@bar',
|
2022-05-21 08:21:41 -05:00
|
|
|
host: null,
|
2018-12-20 04:41:04 -06:00
|
|
|
}, {
|
|
|
|
username: 'baz',
|
|
|
|
acct: '@baz',
|
2022-05-21 08:21:41 -05:00
|
|
|
host: null,
|
2018-12-20 04:41:04 -06:00
|
|
|
}]);
|
|
|
|
});
|
|
|
|
});
|