|
| 1 | +import * as assert from "node:assert"; |
| 2 | +import * as hole from "../hole.js"; |
| 3 | + |
| 4 | +describe("hole.markup()", () => { |
| 5 | + it("it wraps the key in curly braces", () => { |
| 6 | + const markup = hole.markup("key"); |
| 7 | + assert.strictEqual(markup, "{{key}}"); |
| 8 | + }); |
| 9 | + |
| 10 | + it("throws if key is not alphanumeric", () => { |
| 11 | + assert.throws(() => hole.markup("bad key with spaces")); |
| 12 | + }); |
| 13 | +}); |
| 14 | + |
| 15 | +describe("hole.create()", () => { |
| 16 | + it("it creates a hole", () => { |
| 17 | + const keyHole = hole.create("key"); |
| 18 | + assert.deepStrictEqual(keyHole, { |
| 19 | + type: "hole", |
| 20 | + name: "key", |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + it("throws if key is not alphanumeric", () => { |
| 25 | + assert.throws(() => hole.create("bad key with spaces")); |
| 26 | + }); |
| 27 | +}); |
| 28 | + |
| 29 | +describe("hole.parse()", () => { |
| 30 | + it("parses", () => { |
| 31 | + const xml = `Hello {{world}}!`; |
| 32 | + const result = hole.parse(xml); |
| 33 | + assert.deepStrictEqual(result, ["Hello ", hole.create("world"), "!"]); |
| 34 | + }); |
| 35 | + |
| 36 | + it("does not parse staches with non-word characters in them", () => { |
| 37 | + const xml = `Hello {{ world }}!`; |
| 38 | + const result = hole.parse(xml); |
| 39 | + assert.deepStrictEqual(result, ["Hello {{ world }}!"]); |
| 40 | + }); |
| 41 | + |
| 42 | + it("handles broken staches", () => { |
| 43 | + const xml = `Hello {{world}!`; |
| 44 | + const result = hole.parse(xml); |
| 45 | + assert.deepStrictEqual(result, ["Hello {{world}!"]); |
| 46 | + }); |
| 47 | + |
| 48 | + it("handles broken staches 2", () => { |
| 49 | + const xml = `Hello {world}}!`; |
| 50 | + const result = hole.parse(xml); |
| 51 | + assert.deepStrictEqual(result, ["Hello {world}}!"]); |
| 52 | + }); |
| 53 | + |
| 54 | + it("handles broken staches 3", () => { |
| 55 | + const xml = `Hello {{wor}ld}}!`; |
| 56 | + const result = hole.parse(xml); |
| 57 | + assert.deepStrictEqual(result, ["Hello {{wor}ld}}!"]); |
| 58 | + }); |
| 59 | + |
| 60 | + it("handles broken staches 4", () => { |
| 61 | + const xml = `Hello {{wor}}ld}}!`; |
| 62 | + const result = hole.parse(xml); |
| 63 | + assert.deepStrictEqual(result, ["Hello ", hole.create("wor"), "ld}}!"]); |
| 64 | + }); |
| 65 | +}); |
0 commit comments