import {ChunkType} from "../../chunks/types/ChunkType"; import {NodeImplChunk} from "../../chunks/types/NodeImplChunk"; import {isStructureNodeImplChunk} from "./isStructureNodeImplChunk"; describe("isStructureNodeImplChunk()", () => { const codeNodeImplChunk: NodeImplChunk = { "offset": { "line": 7, "column": 2 }, "type": ChunkType.NodeImpl, "children": [ { "offset": { "line": 8, "column": 4 }, "type": ChunkType.NodeCode, "children": [], "content": "console.log(value, tag);", "captures": [ "(value)", null, null, { "type": ChunkType.Identifier, "captures": [ "(value)" ], "offset": { "line": 8, "column": 4 } } ] } ], "content": "(value)\n console.log(value, tag);", "captures": [ "in node", null, { "type": ChunkType.Runtime, "captures": [ "node" ], "offset": { "line": 7, "column": 2 } } ] }; const structureNodeImplChunk: NodeImplChunk = { "offset": { "line": 10, "column": 2 }, "type": ChunkType.NodeImpl, "children": [ { "offset": { "line": 11, "column": 4 }, "type": ChunkType.ChildNodes, "children": [ { "offset": { "line": 12, "column": 6 }, "type": ChunkType.ChildNodesItem, "captures": [ "(start program):(core).(Start)", { "type": ChunkType.NodeDecl, "captures": [ "(start program):(core).(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 } } ] }, { "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!\"):(core).(Value)", { "type": ChunkType.NodeDecl, "captures": [ "(send \"Hello, World!\"):(core).(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 } } ] }, { "offset": { "line": 15, "column": 6 }, "type": ChunkType.ChildNodesItem, "captures": [ "(log to console):(console).(Console Log)", { "type": ChunkType.NodeDecl, "captures": [ "(log to console):(console).(Console Log)", { "type": ChunkType.Identifier, "captures": [ "(log to console)" ], "offset": { "line": 15, "column": 6 } }, { "type": ChunkType.Identifier, "captures": [ "(Console Log)" ], "offset": { "line": 15, "column": 6 } } ], "offset": { "line": 15, "column": 6 } } ] } ], "content": "(start program):(core).(Start)\n(send \"Hello, World!\"):(core).(Value)\n param (value) = \"Hello, World!\"\n(log to console):(console).(Console Log)", "captures": [ "children" ] }, { "offset": { "line": 16, "column": 4 }, "type": ChunkType.Connections, "children": [ { "offset": { "line": 17, "column": 6 }, "type": ChunkType.ConnectionsItem, "captures": [ "(start program).out.(start) and (send \"Hello, World!\").in.(start)", { "type": ChunkType.ConnectionBody, "captures": [ "(start program).out.(start) and (send \"Hello, World!\").in.(start)", { "type": ChunkType.ChildPort, "captures": [ "(start program).out.(start)", { "type": ChunkType.Identifier, "captures": [ "(start program)" ], "offset": { "line": 17, "column": 6 } }, { "type": ChunkType.ChildPortDirection, "captures": [ "out" ], "offset": { "line": 17, "column": 6 } }, { "type": ChunkType.Identifier, "captures": [ "(start)" ], "offset": { "line": 17, "column": 6 } } ], "offset": { "line": 17, "column": 6 } }, { "type": ChunkType.ChildPort, "captures": [ "(send \"Hello, World!\").in.(start)", { "type": ChunkType.Identifier, "captures": [ "(send \"Hello, World!\")" ], "offset": { "line": 17, "column": 6 } }, { "type": ChunkType.ChildPortDirection, "captures": [ "in" ], "offset": { "line": 17, "column": 6 } }, { "type": ChunkType.Identifier, "captures": [ "(start)" ], "offset": { "line": 17, "column": 6 } } ], "offset": { "line": 17, "column": 6 } } ], "offset": { "line": 17, "column": 6 } } ] }, { "offset": { "line": 18, "column": 6 }, "type": ChunkType.ConnectionsItem, "captures": [ "(send \"Hello, World!\").out.(value) and (log to console).in.(value)", { "type": ChunkType.ConnectionBody, "captures": [ "(send \"Hello, World!\").out.(value) and (log to console).in.(value)", { "type": ChunkType.ChildPort, "captures": [ "(send \"Hello, World!\").out.(value)", { "type": ChunkType.Identifier, "captures": [ "(send \"Hello, World!\")" ], "offset": { "line": 18, "column": 6 } }, { "type": ChunkType.ChildPortDirection, "captures": [ "out" ], "offset": { "line": 18, "column": 6 } }, { "type": ChunkType.Identifier, "captures": [ "(value)" ], "offset": { "line": 18, "column": 6 } } ], "offset": { "line": 18, "column": 6 } }, { "type": ChunkType.ChildPort, "captures": [ "(log to console).in.(value)", { "type": ChunkType.Identifier, "captures": [ "(log to console)" ], "offset": { "line": 18, "column": 6 } }, { "type": ChunkType.ChildPortDirection, "captures": [ "in" ], "offset": { "line": 18, "column": 6 } }, { "type": ChunkType.Identifier, "captures": [ "(value)" ], "offset": { "line": 18, "column": 6 } } ], "offset": { "line": 18, "column": 6 } } ], "offset": { "line": 18, "column": 6 } } ] } ], "content": "(start program).out.(start) and (send \"Hello, World!\").in.(start)\n(send \"Hello, World!\").out.(value) and (log to console).in.(value)", "captures": [ "connect" ] } ], "content": "children\n (start program):(core).(Start)\n (send \"Hello, World!\"):(core).(Value)\n param (value) = \"Hello, World!\"\n (log to console):(console).(Console Log)\nconnect\n (start program).out.(start) and (send \"Hello, World!\").in.(start)\n (send \"Hello, World!\").out.(value) and (log to console).in.(value)", "captures": [ "in all", { "type": ChunkType.BuiltinTarget, "captures": [ "all" ], "offset": { "line": 10, "column": 2 } }, null ] }; describe("for code nodes", () => { it("should return false", () => { const result = isStructureNodeImplChunk(codeNodeImplChunk); expect(result).toBe(false); }); }); describe("for structure nodes", () => { it("should return true", () => { const result = isStructureNodeImplChunk(structureNodeImplChunk); expect(result).toBe(true); }); }); });