2023-04-06 19:56:46 -06:00
|
|
|
import * as assert from "assert";
|
2018-12-20 03:41:04 -07:00
|
|
|
|
2024-05-05 16:57:30 -06:00
|
|
|
import { parse } from "@transfem-org/sfm-js";
|
2023-04-06 19:56:46 -06:00
|
|
|
import { extractMentions } from "../src/misc/extract-mentions.js";
|
2018-12-20 03:41:04 -07:00
|
|
|
|
2023-04-06 19:56:46 -06:00
|
|
|
describe("Extract mentions", () => {
|
|
|
|
it("simple", () => {
|
|
|
|
const ast = parse("@foo @bar @baz")!;
|
2018-12-20 03:41:04 -07:00
|
|
|
const mentions = extractMentions(ast);
|
2023-04-06 19:56:46 -06:00
|
|
|
assert.deepStrictEqual(mentions, [
|
|
|
|
{
|
|
|
|
username: "foo",
|
|
|
|
acct: "@foo",
|
|
|
|
host: null,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
username: "bar",
|
|
|
|
acct: "@bar",
|
|
|
|
host: null,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
username: "baz",
|
|
|
|
acct: "@baz",
|
|
|
|
host: null,
|
|
|
|
},
|
|
|
|
]);
|
2018-12-20 03:41:04 -07:00
|
|
|
});
|
|
|
|
|
2023-04-06 19:56:46 -06:00
|
|
|
it("nested", () => {
|
|
|
|
const ast = parse("@foo **@bar** @baz")!;
|
2018-12-20 03:41:04 -07:00
|
|
|
const mentions = extractMentions(ast);
|
2023-04-06 19:56:46 -06:00
|
|
|
assert.deepStrictEqual(mentions, [
|
|
|
|
{
|
|
|
|
username: "foo",
|
|
|
|
acct: "@foo",
|
|
|
|
host: null,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
username: "bar",
|
|
|
|
acct: "@bar",
|
|
|
|
host: null,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
username: "baz",
|
|
|
|
acct: "@baz",
|
|
|
|
host: null,
|
|
|
|
},
|
|
|
|
]);
|
2018-12-20 03:41:04 -07:00
|
|
|
});
|
|
|
|
});
|