2023-07-27 08:31:52 +03:00
|
|
|
/*
|
2024-02-13 17:59:27 +02:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 08:31:52 +03:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2018-12-20 12:41:04 +02:00
|
|
|
import * as assert from 'assert';
|
|
|
|
|
2024-02-03 16:01:09 +02:00
|
|
|
import { parse } from '@transfem-org/sfm-js';
|
2023-02-20 10:24:09 +02:00
|
|
|
import { extractMentions } from '@/misc/extract-mentions.js';
|
2018-12-20 12:41:04 +02:00
|
|
|
|
|
|
|
describe('Extract mentions', () => {
|
2023-02-02 11:18:25 +02:00
|
|
|
test('simple', () => {
|
2023-02-20 10:24:09 +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',
|
2022-05-21 16:21:41 +03:00
|
|
|
host: null,
|
2018-12-20 12:41:04 +02:00
|
|
|
}, {
|
|
|
|
username: 'bar',
|
|
|
|
acct: '@bar',
|
2022-05-21 16:21:41 +03:00
|
|
|
host: null,
|
2018-12-20 12:41:04 +02:00
|
|
|
}, {
|
|
|
|
username: 'baz',
|
|
|
|
acct: '@baz',
|
2022-05-21 16:21:41 +03:00
|
|
|
host: null,
|
2018-12-20 12:41:04 +02:00
|
|
|
}]);
|
|
|
|
});
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
test('nested', () => {
|
2023-02-20 10:24:09 +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',
|
2022-05-21 16:21:41 +03:00
|
|
|
host: null,
|
2018-12-20 12:41:04 +02:00
|
|
|
}, {
|
|
|
|
username: 'bar',
|
|
|
|
acct: '@bar',
|
2022-05-21 16:21:41 +03:00
|
|
|
host: null,
|
2018-12-20 12:41:04 +02:00
|
|
|
}, {
|
|
|
|
username: 'baz',
|
|
|
|
acct: '@baz',
|
2022-05-21 16:21:41 +03:00
|
|
|
host: null,
|
2018-12-20 12:41:04 +02:00
|
|
|
}]);
|
|
|
|
});
|
|
|
|
});
|