summaryrefslogtreecommitdiff
path: root/packages/backend/test/unit/extract-mentions.ts
blob: 3403387e30e3794ae41d38cf125898c88f59e31b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * SPDX-FileCopyrightText: syuilo and misskey-project
 * SPDX-License-Identifier: AGPL-3.0-only
 */

import * as assert from 'assert';

import { parse } from 'mfm-js';
import { extractMentions } from '@/misc/extract-mentions.js';

describe('Extract mentions', () => {
	test('simple', () => {
		const ast = parse('@foo @bar @baz');
		const mentions = extractMentions(ast);
		assert.deepStrictEqual(mentions, [{
			username: 'foo',
			acct: '@foo',
			host: null,
		}, {
			username: 'bar',
			acct: '@bar',
			host: null,
		}, {
			username: 'baz',
			acct: '@baz',
			host: null,
		}]);
	});

	test('nested', () => {
		const ast = parse('@foo **@bar** @baz');
		const mentions = extractMentions(ast);
		assert.deepStrictEqual(mentions, [{
			username: 'foo',
			acct: '@foo',
			host: null,
		}, {
			username: 'bar',
			acct: '@bar',
			host: null,
		}, {
			username: 'baz',
			acct: '@baz',
			host: null,
		}]);
	});
});