1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-12-24 11:38:20 +09:00
MisskeyIO/packages/backend/test/unit/extract-mentions.ts

43 lines
824 B
TypeScript
Raw Normal View History

import * as assert from 'assert';
import { parse } from 'mfm-js';
import { extractMentions } from '@/misc/extract-mentions.js';
describe('Extract mentions', () => {
2023-02-02 18:18:25 +09:00
test('simple', () => {
const ast = parse('@foo @bar @baz');
const mentions = extractMentions(ast);
assert.deepStrictEqual(mentions, [{
username: 'foo',
acct: '@foo',
2022-05-21 22:21:41 +09:00
host: null,
}, {
username: 'bar',
acct: '@bar',
2022-05-21 22:21:41 +09:00
host: null,
}, {
username: 'baz',
acct: '@baz',
2022-05-21 22:21:41 +09:00
host: null,
}]);
});
2023-02-02 18:18:25 +09:00
test('nested', () => {
const ast = parse('@foo **@bar** @baz');
const mentions = extractMentions(ast);
assert.deepStrictEqual(mentions, [{
username: 'foo',
acct: '@foo',
2022-05-21 22:21:41 +09:00
host: null,
}, {
username: 'bar',
acct: '@bar',
2022-05-21 22:21:41 +09:00
host: null,
}, {
username: 'baz',
acct: '@baz',
2022-05-21 22:21:41 +09:00
host: null,
}]);
});
});