diff options
Diffstat (limited to 'packages/backend/test/tests/extract-mentions.ts')
| -rw-r--r-- | packages/backend/test/tests/extract-mentions.ts | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/packages/backend/test/tests/extract-mentions.ts b/packages/backend/test/tests/extract-mentions.ts new file mode 100644 index 0000000000..4f9cb68763 --- /dev/null +++ b/packages/backend/test/tests/extract-mentions.ts @@ -0,0 +1,42 @@ +import * as assert from 'assert'; + +import { parse } from 'mfm-js'; +import { extractMentions } from '../../src/misc/extract-mentions.js'; + +describe('Extract mentions', () => { + it('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, + }]); + }); + + it('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, + }]); + }); +}); |