@graffiticode/parser 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +3 -1
- package/package.json +1 -1
- package/src/index.js +1 -0
- package/src/parser.spec.js +31 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
package/src/parser.spec.js
CHANGED
|
@@ -2,6 +2,7 @@ import { jest } from "@jest/globals";
|
|
|
2
2
|
import { buildParser, parser } from "./parser.js";
|
|
3
3
|
import { mockPromiseValue, mockPromiseError } from "./testing/index.js";
|
|
4
4
|
import { lexicon as basisLexicon } from "@graffiticode/basis";
|
|
5
|
+
import { unparse } from "./unparse.js";
|
|
5
6
|
|
|
6
7
|
describe("lang/parser", () => {
|
|
7
8
|
const log = jest.fn();
|
|
@@ -547,6 +548,36 @@ describe("parser integration tests", () => {
|
|
|
547
548
|
expect(strNode.elts[0]).toBe("Price: ${amount}");
|
|
548
549
|
});
|
|
549
550
|
|
|
551
|
+
it("should parse and unparse a tag node", async () => {
|
|
552
|
+
// Arrange - use an empty lexicon so "foo" is not recognized as a function
|
|
553
|
+
const emptyLexicon = {};
|
|
554
|
+
|
|
555
|
+
// Act - parse "foo.." where "foo" is not in the lexicon, producing a TAG node
|
|
556
|
+
const result = await parser.parse(0, "foo..", emptyLexicon);
|
|
557
|
+
|
|
558
|
+
// Assert - find the TAG node
|
|
559
|
+
expect(result).toHaveProperty("root");
|
|
560
|
+
|
|
561
|
+
let tagNode = null;
|
|
562
|
+
for (const key in result) {
|
|
563
|
+
if (key !== "root") {
|
|
564
|
+
const node = result[key];
|
|
565
|
+
if (node.tag === "TAG" && node.elts[0] === "foo") {
|
|
566
|
+
tagNode = node;
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
expect(tagNode).not.toBeNull();
|
|
573
|
+
expect(tagNode.tag).toBe("TAG");
|
|
574
|
+
expect(tagNode.elts).toEqual(["foo"]);
|
|
575
|
+
|
|
576
|
+
// Unparse should reproduce the original source
|
|
577
|
+
const source = unparse(result, emptyLexicon);
|
|
578
|
+
expect(source).toBe("foo..");
|
|
579
|
+
});
|
|
580
|
+
|
|
550
581
|
it("should parse strings with mixed escape sequences", async () => {
|
|
551
582
|
// Arrange & Act
|
|
552
583
|
const result = await parser.parse(0, '"Line 1\\nTab\\t\\"Quote\\""..', basisLexicon);
|