From f7e4eb83694aa007a492ef66c28ffbe6a2dae791 Mon Sep 17 00:00:00 2001 From: Ashcon Partovi Date: Tue, 7 Mar 2023 12:22:34 -0800 Subject: Reorganize tests (#2332) --- test/bun.js/escapeHTML.test.js | 92 ------------------------------------------ 1 file changed, 92 deletions(-) delete mode 100644 test/bun.js/escapeHTML.test.js (limited to 'test/bun.js/escapeHTML.test.js') diff --git a/test/bun.js/escapeHTML.test.js b/test/bun.js/escapeHTML.test.js deleted file mode 100644 index f96849a84..000000000 --- a/test/bun.js/escapeHTML.test.js +++ /dev/null @@ -1,92 +0,0 @@ -import { describe, it, expect } from "bun:test"; -import { gcTick } from "./gc"; -import { escapeHTML } from "bun"; - -describe("escapeHTML", () => { - // The matrix of cases we need to test for: - // 1. Works with short strings - // 2. Works with long strings - // 3. Works with latin1 strings - // 4. Works with utf16 strings - // 5. Works when the text to escape is somewhere in the middle - // 6. Works when the text to escape is in the beginning - // 7. Works when the text to escape is in the end - // 8. Returns the same string when there's no need to escape - it("works", () => { - expect(escapeHTML("absolutely nothing to do here")).toBe("absolutely nothing to do here"); - expect(escapeHTML("")).toBe("<script>alert(1)</script>"); - expect(escapeHTML("<")).toBe("<"); - expect(escapeHTML(">")).toBe(">"); - expect(escapeHTML("&")).toBe("&"); - expect(escapeHTML("'")).toBe("'"); - expect(escapeHTML('"')).toBe("""); - expect(escapeHTML("\n")).toBe("\n"); - expect(escapeHTML("\r")).toBe("\r"); - expect(escapeHTML("\t")).toBe("\t"); - expect(escapeHTML("\f")).toBe("\f"); - expect(escapeHTML("\v")).toBe("\v"); - expect(escapeHTML("\b")).toBe("\b"); - expect(escapeHTML("\u00A0")).toBe("\u00A0"); - expect(escapeHTML("" + "lalala")).toBe( - "lalala<script>alert(1)</script>lalala", - ); - - expect(escapeHTML("" + "lalala")).toBe("<script>alert(1)</script>lalala"); - expect(escapeHTML("lalala" + "")).toBe("lalala" + "<script>alert(1)</script>"); - - expect(escapeHTML("What does 😊 mean?")).toBe("What does 😊 mean?"); - const output = escapeHTML("What does 😊 mean in text?")).toBe("<div>What does 😊 mean in text?"); - - expect(escapeHTML(("lalala" + "" + "lalala").repeat(900))).toBe( - "lalala<script>alert(1)</script>lalala".repeat(900), - ); - expect(escapeHTML(("" + "lalala").repeat(900))).toBe( - "<script>alert(1)</script>lalala".repeat(900), - ); - expect(escapeHTML(("lalala" + "").repeat(900))).toBe( - ("lalala" + "<script>alert(1)</script>").repeat(900), - ); - - // the positions of the unicode codepoint are important - // our simd code for U16 is at 8 bytes, so we need to especially check the boundaries - expect(escapeHTML("😊lalala" + "" + "lalala")).toBe( - "😊lalala<script>alert(1)</script>lalala", - ); - expect(escapeHTML("" + "lalala")).toBe("<script>😊alert(1)</script>lalala"); - expect(escapeHTML("" + "lalala")).toBe("<script>alert(1)😊</script>lalala"); - expect(escapeHTML("" + "😊lalala")).toBe("<script>alert(1)</script>😊lalala"); - expect(escapeHTML("" + "lal😊ala")).toBe("<script>alert(1)</script>lal😊ala"); - expect(escapeHTML("" + "lal😊ala".repeat(10))).toBe( - "<script>alert(1)</script>" + "lal😊ala".repeat(10), - ); - - for (let i = 1; i < 10; i++) - expect(escapeHTML("" + "la😊".repeat(i))).toBe( - "<script>alert(1)</script>" + "la😊".repeat(i), - ); - - expect(escapeHTML("la😊" + "")).toBe("la😊" + "<script>alert(1)</script>"); - expect(escapeHTML(("lalala" + "😊").repeat(1))).toBe( - ("lalala" + "<script>alert(1)</script>😊").repeat(1), - ); - - expect(escapeHTML("😊".repeat(100))).toBe("😊".repeat(100)); - expect(escapeHTML("😊<".repeat(100))).toBe("😊<".repeat(100)); - expect(escapeHTML("<😊>".repeat(100))).toBe("<😊>".repeat(100)); - expect(escapeHTML("😊")).toBe("😊"); - expect(escapeHTML("😊😊")).toBe("😊😊"); - expect(escapeHTML("😊lo")).toBe("😊lo"); - expect(escapeHTML("lo😊")).toBe("lo😊"); - - expect(escapeHTML(" ".repeat(32) + "😊")).toBe(" ".repeat(32) + "😊"); - expect(escapeHTML(" ".repeat(32) + "😊😊")).toBe(" ".repeat(32) + "😊😊"); - expect(escapeHTML(" ".repeat(32) + "😊lo")).toBe(" ".repeat(32) + "😊lo"); - expect(escapeHTML(" ".repeat(32) + "lo😊")).toBe(" ".repeat(32) + "lo😊"); - }); -}); -- cgit v1.2.3