prototype-3x5/src/words.test.ts

57 lines
2.3 KiB
TypeScript
Raw Normal View History

2023-10-19 00:06:52 +00:00
import { AsHtml, AsText, Concat } from './words';
2023-08-26 05:16:22 +00:00
describe("Text Words", () => {
test.each([
2023-10-19 00:06:52 +00:00
[{ bare: "apple" }, "apple"],
[{ bare: "<pie>" }, "<pie>"],
2023-08-26 05:16:22 +00:00
[{ text: "banana" }, "banana"],
[{ text: "<b>kiwi" }, "<b>kiwi"],
[{ html: "<b>cherry</b>" }, "<b>cherry</b>"],
])("AsText(%s)", (word, expected) => expect(AsText(word)).toEqual(expected));
test.each([
2023-10-19 00:06:52 +00:00
[{ bare: "apple" }, "apple"],
[{ bare: "<pie>" }, "&lt;pie&gt;"],
2023-08-26 05:16:22 +00:00
[{ text: "banana" }, "banana"],
[{ text: "<b>kiwi" }, "&lt;b&gt;kiwi"],
[{ html: "<b>cherry</b>" }, "<b>cherry</b>"],
])("AsHtml(%s)", (word, expected) => expect(AsHtml(word)).toEqual(expected));
test.each([
2023-10-19 00:06:52 +00:00
[null, { bare: "1" }, { text: "1" }],
[null, { bare: ">1" }, { text: ">1" }],
2023-08-26 05:16:22 +00:00
[null, { text: "2" }, { text: "2" }],
[null, { text: "<b>3</b>" }, { text: "<b>3</b>" }],
[null, { html: "2" }, { html: "2" }],
[null, { html: "<b>3</b>" }, { html: "<b>3</b>" }],
2023-10-19 00:06:52 +00:00
[{ bare: "&pple" }, { bare: "1" }, { text: "&pple1" }],
[{ bare: "&pple" }, { bare: ">1" }, { text: "&pple>1" }],
[{ bare: "&pple" }, { text: "2" }, { text: "&pple2" }],
[{ bare: "&pple" }, { text: "<b>3</b>" }, { text: "&pple<b>3</b>" }],
[{ bare: "&pple" }, { html: "2" }, { html: "&amp;pple2" }],
[{ bare: "&pple" }, { html: "<b>3</b>" }, { html: "&amp;pple<b>3</b>" }],
[{ text: "<b>anana" }, { bare: "1" }, { text: "<b>anana1" }],
[{ text: "<b>anana" }, { bare: ">1" }, { text: "<b>anana>1" }],
2023-08-26 05:16:22 +00:00
[{ text: "<b>anana" }, { text: "2" }, { text: "<b>anana2" }],
[{ text: "<b>anana" }, { text: "<b>3</b>" }, { text: "<b>anana<b>3</b>" }],
[{ text: "<b>anana" }, { html: "2" }, { html: "&lt;b&gt;anana2" }],
[
{ text: "<b>anana" },
{ html: "<b>3</b>" },
{ html: "&lt;b&gt;anana<b>3</b>" },
],
2023-10-19 00:06:52 +00:00
[{ html: "<img />" }, { bare: "1" }, { html: "<img />1" }],
[{ html: "<img />" }, { bare: ">1" }, { html: "<img />&gt;1" }],
2023-08-26 05:16:22 +00:00
[{ html: "<img />" }, { text: "2" }, { html: "<img />2" }],
[
{ html: "<img />" },
{ text: "<b>3</b>" },
{ html: "<img />&lt;b&gt;3&lt;/b&gt;" },
],
[{ html: "<img />" }, { html: "2" }, { html: "<img />2" }],
[{ html: "<img />" }, { html: "<b>3</b>" }, { html: "<img /><b>3</b>" }],
])("Concat(%s, %s)", (left, right, expected) =>
expect(Concat(left, right)).toEqual(expected)
);
});