import {ChildNodeChunk} from "../chunks/types/ChildNodeChunk"; import {ChunkType} from "../chunks/types/ChunkType"; import {childNodeChunkToChildNodeProps} from "./childNodeChunkToChildNodeProps"; describe("childNodeChunkToChildNodeProps()", () => { it("should extract reference", () => { const childNodeChunk: ChildNodeChunk = { "offset": { "line": 29, "column": 4 }, "type": ChunkType.ChildNode, "children": [ { "offset": { "line": 30, "column": 6 }, "type": ChunkType.NodeParam, "captures": [ "param (fields) = [\"a\", \"b\"]", { "type": ChunkType.VarAssignment, "captures": [ "(fields) = [\"a\", \"b\"]", { "type": ChunkType.Identifier, "captures": [ "(fields)" ], "offset": { "line": 30, "column": 6 } }, { "type": ChunkType.Any, "captures": [ "[\"a\", \"b\"]" ], "offset": { "line": 30, "column": 6 } } ], "offset": { "line": 30, "column": 6 } } ] } ], "content": "param (fields) = [\"a\", \"b\"]", "captures": [ "child (sync a & b):(Syncer)", { "type": ChunkType.NodeDecl, "captures": [ "(sync a & b):(Syncer)", { "type": ChunkType.Identifier, "captures": [ "(sync a & b)" ], "offset": { "line": 29, "column": 4 } }, { "type": ChunkType.Identifier, "captures": [ "(Syncer)" ], "offset": { "line": 29, "column": 4 } } ], "offset": { "line": 29, "column": 4 } } ] }; const result = childNodeChunkToChildNodeProps(childNodeChunk); expect(result).toMatchSnapshot(); }); describe("when parameters are present", () => { it("should extract parameters", () => { const childNodeChunk: ChildNodeChunk = { "offset": { "line": 29, "column": 4 }, "type": ChunkType.ChildNode, "children": [ { "offset": { "line": 30, "column": 6 }, "type": ChunkType.NodeParam, "captures": [ "param (fields) = [\"a\", \"b\"]", { "type": ChunkType.VarAssignment, "captures": [ "(fields) = [\"a\", \"b\"]", { "type": ChunkType.Identifier, "captures": [ "(fields)" ], "offset": { "line": 30, "column": 6 } }, { "type": ChunkType.Any, "captures": [ "[\"a\", \"b\"]" ], "offset": { "line": 30, "column": 6 } } ], "offset": { "line": 30, "column": 6 } } ] } ], "content": "param (fields) = [\"a\", \"b\"]", "captures": [ "child (sync a & b):(Syncer)", { "type": ChunkType.NodeDecl, "captures": [ "(sync a & b):(Syncer)", { "type": ChunkType.Identifier, "captures": [ "(sync a & b)" ], "offset": { "line": 29, "column": 4 } }, { "type": ChunkType.Identifier, "captures": [ "(Syncer)" ], "offset": { "line": 29, "column": 4 } } ], "offset": { "line": 29, "column": 4 } } ] }; const result = childNodeChunkToChildNodeProps(childNodeChunk); expect(result).toMatchSnapshot(); }); describe("when parameters are grouped", () => { it("should extract parameters", () => { const childNodeChunk: ChildNodeChunk = { "offset": { "line": 29, "column": 4 }, "type": ChunkType.ChildNode, "children": [ { "offset": { "line": 30, "column": 6 }, "type": ChunkType.NodeParams, "children": [ { "offset": { "line": 31, "column": 8 }, "type": ChunkType.NodeParamsItem, "captures": [ "(fields) = [\"a\", \"b\"]", { "type": ChunkType.VarAssignment, "captures": [ "(fields) = [\"a\", \"b\"]", { "type": ChunkType.Identifier, "captures": [ "(fields)" ], "offset": { "line": 31, "column": 8 } }, { "type": ChunkType.Any, "captures": [ "[\"a\", \"b\"]" ], "offset": { "line": 31, "column": 8 } } ], "offset": { "line": 31, "column": 8 } } ] } ], "content": "(fields) = [\"a\", \"b\"]", "captures": [ "params" ] } ], "content": "params\n (fields) = [\"a\", \"b\"]", "captures": [ "child (sync a & b):(Syncer)", { "type": ChunkType.NodeDecl, "captures": [ "(sync a & b):(Syncer)", { "type": ChunkType.Identifier, "captures": [ "(sync a & b)" ], "offset": { "line": 29, "column": 4 } }, { "type": ChunkType.Identifier, "captures": [ "(Syncer)" ], "offset": { "line": 29, "column": 4 } } ], "offset": { "line": 29, "column": 4 } } ] }; const result = childNodeChunkToChildNodeProps(childNodeChunk); expect(result).toMatchSnapshot(); }); }); }); });