Reorganize tests

This commit is contained in:
Tangent Wantwight 2023-08-25 11:13:00 -04:00
parent ab4cd761b8
commit a4e65e567a
2 changed files with 16 additions and 20 deletions

View file

@ -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: "" }]]]));

View file

@ -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 {