diff --git a/src/notcl.test.ts b/src/notcl.test.ts index 7912a0f..0856244 100644 --- a/src/notcl.test.ts +++ b/src/notcl.test.ts @@ -5,9 +5,6 @@ describe("Parsing Notcl", () => { it("can parse an empty script", () => expect(parse("")).toEqual([true, []])); - it("can parse a one-word command", () => - expect(parse("a")).toEqual([true, [[{ enchanted: "a" }]]])); - it("can parse a multi-word command", () => expect(parse("a b c")).toEqual([ true, @@ -89,15 +86,10 @@ b`) }); 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 + it("can parse a simple word", () => + expect(parse("a")).toEqual([true, [[{ enchanted: "a" }]]])); + it("can parse a word with non-special punctuation", () => + expect(parse("-switch")).toEqual([true, [[{ enchanted: "-switch" }]]])); }); describe("interpolated words", () => { @@ -126,12 +118,16 @@ b`) expect(parse("\\{")).toEqual([true, [[{ text: "{" }]]])); it("treats a quoted brace as a plain character", () => expect(parse('"{"')).toEqual([true, [[{ text: "{" }]]])); - - // Interpolated words - // variables- bare, brace - // command subst }); + describe("backslash interpolation", () => {}); + + describe("variable interpolation", () => { + // variables- bare, brace + }); + + describe("command interpolation", () => {}); + describe("brace words", () => { it("can parse empty braces", () => expect(parse("{}")).toEqual([true, [[{ text: "" }]]])); diff --git a/src/words.ts b/src/words.ts index 894a826..00f5e93 100644 --- a/src/words.ts +++ b/src/words.ts @@ -42,15 +42,15 @@ export type InterpolatedWord = { pieces: InterpolatedPiece[]; }; -function IsTextPiece(piece: InterpolatedPiece | undefined): piece is TextPiece { - return piece ? "text" in piece : false; -} - // safely concatenate text pieces, converting as needed export function Concat(left: TextPiece, right: TextPiece) { return { text: left.text + right.text }; } +function IsTextPiece(piece: InterpolatedPiece | undefined): piece is TextPiece { + return piece ? "text" in piece : false; +} + export function SimplifyWord( pieces: InterpolatedPiece[] ): InterpolatedWord | TextWord {