From 2261d18d56043aca9a3efcd3497d67d42d777dee Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Thu, 10 Aug 2023 21:51:23 -0400 Subject: [PATCH] Write brace tests --- src/notcl.test.ts | 55 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/notcl.test.ts b/src/notcl.test.ts index 4c63eca..eeee40b 100644 --- a/src/notcl.test.ts +++ b/src/notcl.test.ts @@ -88,7 +88,60 @@ b`) ).toEqual([true, []])); }); - // Enchanted Words + describe("enchanted words", () => { + // Enchanted Words + // simple words + // not braces + // not quotes + // not variables + // not commands + // not backslashes + // yes before folded newline + // no before folded newline that gives us backslashes + }); + + describe("interpolated words", () => {}); + + describe("brace words", () => { + it("can parse empty braces", () => + expect(parse("{}")).toEqual([true, [[{ text: "" }]]])); + it("can parse braces with text", () => + expect(parse("{a b c}")).toEqual([true, [[{ text: "a b c" }]]])); + it("can parse nested braces", () => + expect(parse("{{}}")).toEqual([true, [[{ text: "{}" }]]])); + it("can parse nested braces with text", () => + expect(parse("{a{b}c}")).toEqual([true, [[{ text: "a{b}c" }]]])); + + it.failing("doesn't count suppressed braces for nesting", () => + expect(parse(String.raw`{a\{b}`)).toEqual([true, [[{ text: "a\\{b" }]]]) + ); + it.failing("doesn't count suppressed braces for unnesting", () => + expect(parse(String.raw`{a\}b}`)).toEqual([true, [[{ text: "a\\}b" }]]]) + ); + it("nests braces after suppressed backslashes", () => + expect(parse(String.raw`{a\\{b}}`)).toEqual([ + true, + [[{ text: "a\\\\{b}" }]], + ])); + + it("permits newlines in braces", () => + expect(parse("{\n}")).toEqual([true, [[{ text: "\n" }]]])); + it("folds newlines in braces", () => + expect( + parse(String.raw`{\ +}`) + ).toEqual([true, [[{ text: " " }]]])); + it("doesn't fold newlines in braces with escaped backslashes", () => + expect( + parse(String.raw`{\\ +}`) + ).toEqual([true, [[{ text: "\\\\\n" }]]])); + it("folds newlines in braces with escaped backslashes", () => + expect( + parse(String.raw`{\\\ +}`) + ).toEqual([true, [[{ text: "\\\\ " }]]])); + }); // Braces // nesting