|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import { isValidAttrValue, isValidStatement } from ".."; |
| 3 | + |
| 4 | +describe("validation helpers", () => { |
| 5 | + describe("isValidStatement", () => { |
| 6 | + it("accepts single-line expressions", () => { |
| 7 | + assert.equal(isValidStatement("foo + bar"), true); |
| 8 | + }); |
| 9 | + |
| 10 | + it("accepts indented continuation lines", () => { |
| 11 | + assert.equal(isValidStatement("foo\n + bar"), true); |
| 12 | + }); |
| 13 | + |
| 14 | + it("rejects unindented continuation lines", () => { |
| 15 | + assert.equal(isValidStatement("foo\nbar"), false); |
| 16 | + }); |
| 17 | + |
| 18 | + it("accepts indented ternary continuation", () => { |
| 19 | + assert.equal(isValidStatement("foo ?\n bar : baz"), true); |
| 20 | + }); |
| 21 | + |
| 22 | + it("rejects unterminated groups", () => { |
| 23 | + assert.equal(isValidStatement("(foo"), false); |
| 24 | + }); |
| 25 | + |
| 26 | + it("rejects mismatched closing groups", () => { |
| 27 | + assert.equal(isValidStatement(")"), false); |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + describe("isValidAttrValue", () => { |
| 32 | + it("accepts html attr values with operators", () => { |
| 33 | + assert.equal(isValidAttrValue("foo + bar", false), true); |
| 34 | + }); |
| 35 | + |
| 36 | + it("accepts html attr values containing =>", () => { |
| 37 | + assert.equal(isValidAttrValue("foo=>bar", false), true); |
| 38 | + }); |
| 39 | + |
| 40 | + it("rejects html attr values terminated by >", () => { |
| 41 | + assert.equal(isValidAttrValue("foo >", false), false); |
| 42 | + }); |
| 43 | + |
| 44 | + it("accepts concise attr values with >", () => { |
| 45 | + assert.equal(isValidAttrValue("foo > bar", true), true); |
| 46 | + }); |
| 47 | + |
| 48 | + it("rejects html attr values terminated by commas", () => { |
| 49 | + assert.equal(isValidAttrValue("foo, bar", false), false); |
| 50 | + }); |
| 51 | + |
| 52 | + it("accepts html attr values containing semicolons", () => { |
| 53 | + assert.equal(isValidAttrValue("foo;", false), true); |
| 54 | + }); |
| 55 | + |
| 56 | + it("rejects concise attr values terminated by semicolons", () => { |
| 57 | + assert.equal(isValidAttrValue("foo;", true), false); |
| 58 | + }); |
| 59 | + |
| 60 | + it("accepts html attr values with decrement operator", () => { |
| 61 | + assert.equal(isValidAttrValue("foo --", false), true); |
| 62 | + }); |
| 63 | + |
| 64 | + it("rejects concise attr values with decrement operator", () => { |
| 65 | + assert.equal(isValidAttrValue("foo --", true), false); |
| 66 | + }); |
| 67 | + |
| 68 | + it("rejects attr values separated only by whitespace", () => { |
| 69 | + assert.equal(isValidAttrValue("foo bar", false), false); |
| 70 | + }); |
| 71 | + }); |
| 72 | +}); |
0 commit comments