| 1 | import { isIdentifierName } from "../lib/index.js"; |
| 2 | |
| 3 | describe("isIdentifierName", function () { |
| 4 | it("returns false if provided string is empty", function () { |
| 5 | expect(isIdentifierName("")).toBe(false); |
| 6 | }); |
| 7 | it.each([ |
| 8 | "hello", |
| 9 | "$", |
| 10 | "ゆゆ式", |
| 11 | "$20", |
| 12 | "hello20", |
| 13 | "_", |
| 14 | "if", |
| 15 | "_\u200c", |
| 16 | "_\u200d", |
| 17 | ])( |
| 18 | "returns true if provided string %p is an IdentifierName", |
| 19 | function (word) { |
| 20 | expect(isIdentifierName(word)).toBe(true); |
| 21 | }, |
| 22 | ); |
| 23 | it.each(["+hello", "0$", "-ゆゆ式", "#_", "_#", "\ud800\ud800"])( |
| 24 | "returns false if provided string %p is not an IdentifierName", |
| 25 | function (word) { |
| 26 | expect(isIdentifierName(word)).toBe(false); |
| 27 | }, |
| 28 | ); |
| 29 | it("supports astral symbols", function () { |
| 30 | expect(isIdentifierName("x\uDB40\uDDD5")).toBe(true); |
| 31 | }); |
| 32 | it("supports Unicode 15", () => { |
| 33 | expect(isIdentifierName("\u{1e030}")).toBe(true); |
| 34 | }); |
| 35 | it("supports Unicode 14", () => { |
| 36 | expect(isIdentifierName("\u{10f70}")).toBe(true); |
| 37 | }); |
| 38 | it("supports Unicode 13", () => { |
| 39 | expect(isIdentifierName("\u{30000}")).toBe(true); |
| 40 | }); |
| 41 | it("supports Unicode 12", () => { |
| 42 | expect(isIdentifierName("\u{10fe0}")).toBe(true); |
| 43 | }); |
| 44 | it("supports Unicode 11", () => { |
| 45 | expect(isIdentifierName("\u{10f00}")).toBe(true); |
| 46 | }); |
| 47 | }); |