| 1 | import { test } from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | |
| 4 | import { mentionedHandles, mentions, mentionsColumn } from "./mentions.ts"; |
| 5 | |
| 6 | test("mentions are found once each, lowercased, in order", () => { |
| 7 | assert.deepEqual(mentionedHandles("@Ship can you cut it? cc @syntaqx and @ship"), ["ship", "syntaqx"]); |
| 8 | assert.deepEqual(mentionedHandles("(@review-bot) @a_b, @x."), ["review-bot", "a_b", "x"]); |
| 9 | assert.deepEqual(mentionedHandles("@ship\n@docs"), ["ship", "docs"]); |
| 10 | }); |
| 11 | |
| 12 | test("an email address or a stray @ is not a mention", () => { |
| 13 | assert.deepEqual(mentionedHandles("mail me@example.com"), []); |
| 14 | assert.deepEqual(mentionedHandles("@ alone, @@double, @-dash"), []); |
| 15 | assert.deepEqual(mentionedHandles(""), []); |
| 16 | }); |
| 17 | |
| 18 | test("a kept mention matches its whole handle only", () => { |
| 19 | const column = mentionsColumn(mentionedHandles("hey @bobby and @ship")); |
| 20 | assert.equal(column, " bobby ship "); |
| 21 | assert.equal(mentions(column, "bobby"), true); |
| 22 | assert.equal(mentions(column, "Ship"), true); |
| 23 | assert.equal(mentions(column, "bob"), false); |
| 24 | assert.equal(mentions(mentionsColumn([]), "bob"), false); |
| 25 | assert.equal(mentions(null, "bob"), false); |
| 26 | }); |