Sharkey/packages/backend/test/unit/extract-mentions.ts

48 lines
948 B
TypeScript
Raw Permalink Normal View History

/*
* SPDX-FileCopyrightText: syuilo and other misskey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
import * as assert from 'assert';
2023-12-18 04:03:05 +02:00
import { parse } from '@sharkey/sfm-js';
import { extractMentions } from '@/misc/extract-mentions.js';
describe('Extract mentions', () => {
2023-02-02 11:18:25 +02:00
test('simple', () => {
const ast = parse('@foo @bar @baz');
const mentions = extractMentions(ast);
assert.deepStrictEqual(mentions, [{
username: 'foo',
acct: '@foo',
2022-05-21 16:21:41 +03:00
host: null,
}, {
username: 'bar',
acct: '@bar',
2022-05-21 16:21:41 +03:00
host: null,
}, {
username: 'baz',
acct: '@baz',
2022-05-21 16:21:41 +03:00
host: null,
}]);
});
2023-02-02 11:18:25 +02:00
test('nested', () => {
const ast = parse('@foo **@bar** @baz');
const mentions = extractMentions(ast);
assert.deepStrictEqual(mentions, [{
username: 'foo',
acct: '@foo',
2022-05-21 16:21:41 +03:00
host: null,
}, {
username: 'bar',
acct: '@bar',
2022-05-21 16:21:41 +03:00
host: null,
}, {
username: 'baz',
acct: '@baz',
2022-05-21 16:21:41 +03:00
host: null,
}]);
});
});