1
0
Fork 1
mirror of https://example.com synced 2024-11-27 12:26:38 +09:00
firefish/packages/backend/test/extract-mentions.ts

51 lines
879 B
TypeScript
Raw Normal View History

2023-04-07 10:56:46 +09:00
import * as assert from "assert";
2023-04-07 10:56:46 +09:00
import { parse } from "mfm-js";
import { extractMentions } from "../src/misc/extract-mentions.js";
2023-04-07 10:56:46 +09:00
describe("Extract mentions", () => {
it("simple", () => {
const ast = parse("@foo @bar @baz")!;
const mentions = extractMentions(ast);
2023-04-07 10:56:46 +09:00
assert.deepStrictEqual(mentions, [
{
username: "foo",
acct: "@foo",
host: null,
},
{
username: "bar",
acct: "@bar",
host: null,
},
{
username: "baz",
acct: "@baz",
host: null,
},
]);
});
2023-04-07 10:56:46 +09:00
it("nested", () => {
const ast = parse("@foo **@bar** @baz")!;
const mentions = extractMentions(ast);
2023-04-07 10:56:46 +09:00
assert.deepStrictEqual(mentions, [
{
username: "foo",
acct: "@foo",
host: null,
},
{
username: "bar",
acct: "@bar",
host: null,
},
{
username: "baz",
acct: "@baz",
host: null,
},
]);
});
});