this repo has no description
1import { describe, expect, test } from "bun:test";
2import { parseIRCFormatting, parseSlackMarkdown } from "./parser";
3
4describe("parseSlackMarkdown", () => {
5 test("converts channel mentions with name", () => {
6 const result = parseSlackMarkdown("Check out <#C123ABC|general>");
7 expect(result).toBe("Check out #general");
8 });
9
10 test("converts channel mentions without name", () => {
11 const result = parseSlackMarkdown("Check out <#C123ABC>");
12 expect(result).toBe("Check out #channel");
13 });
14
15 test("converts links with text", () => {
16 const result = parseSlackMarkdown(
17 "Visit <https://example.com|Example Site>",
18 );
19 expect(result).toBe("Visit Example Site (https://example.com)");
20 });
21
22 test("converts links without text", () => {
23 const result = parseSlackMarkdown("Visit <https://example.com>");
24 expect(result).toBe("Visit https://example.com");
25 });
26
27 test("converts mailto links", () => {
28 const result = parseSlackMarkdown(
29 "Email <mailto:test@example.com|Support>",
30 );
31 expect(result).toBe("Email Support <test@example.com>");
32 });
33
34 test("converts special mentions", () => {
35 expect(parseSlackMarkdown("<!here> everyone")).toBe("@here everyone");
36 expect(parseSlackMarkdown("<!channel> announcement")).toBe(
37 "@channel announcement",
38 );
39 expect(parseSlackMarkdown("<!everyone> alert")).toBe("@everyone alert");
40 });
41
42 test("converts user group mentions", () => {
43 const result = parseSlackMarkdown("Hey <!subteam^GROUP123|developers>");
44 expect(result).toBe("Hey @developers");
45 });
46
47 test("converts bold formatting", () => {
48 const result = parseSlackMarkdown("This is *bold* text");
49 expect(result).toBe("This is \x02bold\x02 text");
50 });
51
52 test("converts italic formatting", () => {
53 const result = parseSlackMarkdown("This is _italic_ text");
54 expect(result).toBe("This is \x1Ditalic\x1D text");
55 });
56
57 test("strips strikethrough formatting", () => {
58 const result = parseSlackMarkdown("This is ~strikethrough~ text");
59 expect(result).toBe("This is strikethrough text");
60 });
61
62 test("strips code blocks", () => {
63 const result = parseSlackMarkdown("Code: ```const x = 1;```");
64 expect(result).toBe("Code: const x = 1;");
65 });
66
67 test("strips inline code", () => {
68 const result = parseSlackMarkdown("Run `npm install` to start");
69 expect(result).toBe("Run npm install to start");
70 });
71
72 test("unescapes HTML entities", () => {
73 const result = parseSlackMarkdown("a < b && c > d");
74 expect(result).toBe("a < b && c > d");
75 });
76
77 test("handles mixed formatting", () => {
78 const result = parseSlackMarkdown(
79 "*Bold* and _italic_ with <https://example.com|link>",
80 );
81 expect(result).toBe(
82 "\x02Bold\x02 and \x1Ditalic\x1D with link (https://example.com)",
83 );
84 });
85});
86
87describe("parseIRCFormatting", () => {
88 test("strips IRC color codes", () => {
89 const result = parseIRCFormatting("\x0304red text\x03 normal");
90 expect(result).toBe("red text normal");
91 });
92
93 test("converts bold formatting", () => {
94 const result = parseIRCFormatting("This is \x02bold\x02 text");
95 expect(result).toBe("This is *bold* text");
96 });
97
98 test("converts italic formatting", () => {
99 const result = parseIRCFormatting("This is \x1Ditalic\x1D text");
100 expect(result).toBe("This is _italic_ text");
101 });
102
103 test("converts underline to italic", () => {
104 const result = parseIRCFormatting("This is \x1Funderline\x1F text");
105 expect(result).toBe("This is _underline_ text");
106 });
107
108 test("strips reverse/inverse formatting", () => {
109 const result = parseIRCFormatting("Normal \x16reversed\x16 normal");
110 expect(result).toBe("Normal reversed normal");
111 });
112
113 test("strips reset formatting", () => {
114 const result = parseIRCFormatting("Text\x0F reset");
115 expect(result).toBe("Text reset");
116 });
117
118 test("escapes special Slack characters", () => {
119 const result = parseIRCFormatting("a < b & c > d");
120 expect(result).toBe("a < b & c > d");
121 });
122
123 test("handles mixed formatting", () => {
124 const result = parseIRCFormatting("\x02Bold\x02 and \x1Ditalic\x1D");
125 expect(result).toBe("*Bold* and _italic_");
126 });
127
128 test("handles nested formatting codes", () => {
129 const result = parseIRCFormatting("\x02\x1Dbold italic\x1D\x02");
130 expect(result).toBe("*_bold italic_*");
131 });
132
133 test("handles color codes with background", () => {
134 const result = parseIRCFormatting("\x0304,08red on yellow\x03");
135 expect(result).toBe("red on yellow");
136 });
137});