import {ChildNodesItemChunk} from "../chunks/types/ChildNodesItemChunk"; import {ChunkType} from "../chunks/types/ChunkType"; import {childNodesItemChunkToChildNodeProps} from "./childNodesItemChunkToChildNodeProps"; describe("childNodesItemChunkToChildNodeProps()", () => { it("should extract reference", () => { const childNodesItemChunk: ChildNodesItemChunk = { "offset": { "line": 12, "column": 6 }, "type": ChunkType.ChildNodesItem, "captures": [ "(start program):(Start)", { "type": ChunkType.NodeDecl, "captures": [ "(start program):(Start)", { "type": ChunkType.Identifier, "captures": [ "(start program)" ], "offset": { "line": 12, "column": 6 } }, { "type": ChunkType.Identifier, "captures": [ "(Start)" ], "offset": { "line": 12, "column": 6 } } ], "offset": { "line": 12, "column": 6 } } ] }; const result = childNodesItemChunkToChildNodeProps(childNodesItemChunk); expect(result).toMatchSnapshot(); }); describe("when parameters are present", () => { it("should extract parameters", () => { const childNodesItemChunk: ChildNodesItemChunk = { "offset": { "line": 13, "column": 6 }, "type": ChunkType.ChildNodesItem, "children": [ { "offset": { "line": 14, "column": 8 }, "type": ChunkType.NodeParam, "captures": [ "param (value) = \"Hello, World!\"", { "type": ChunkType.VarAssignment, "captures": [ "(value) = \"Hello, World!\"", { "type": ChunkType.Identifier, "captures": [ "(value)" ], "offset": { "line": 14, "column": 8 } }, { "type": ChunkType.Any, "captures": [ "\"Hello, World!\"" ], "offset": { "line": 14, "column": 8 } } ], "offset": { "line": 14, "column": 8 } } ] } ], "content": "param (value) = \"Hello, World!\"", "captures": [ "(send \"Hello, World!\"):(Value)", { "type": ChunkType.NodeDecl, "captures": [ "(send \"Hello, World!\"):(Value)", { "type": ChunkType.Identifier, "captures": [ "(send \"Hello, World!\")" ], "offset": { "line": 13, "column": 6 } }, { "type": ChunkType.Identifier, "captures": [ "(Value)" ], "offset": { "line": 13, "column": 6 } } ], "offset": { "line": 13, "column": 6 } } ] }; const result = childNodesItemChunkToChildNodeProps(childNodesItemChunk); expect(result).toMatchSnapshot(); }); }); });