Skip to content

Commit

Permalink
fix(xod-project): fix collecting terminal chain (for the further crea…
Browse files Browse the repository at this point in the history
…ting cast nodes for custom types) in case when the uppermost terminal has no input links
  • Loading branch information
brusherru committed Aug 19, 2020
1 parent 41d4cf1 commit 9d0c62c
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/xod-project/src/flatten.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,9 @@ const traverseUpAndCollectTerminalChain = R.curry(
R.compose(R.equals(nextNodeId), Link.getLinkInputNodeId),
links
);
// If the uppermost node has no input link — return collected data
if (!nextLink) return collected;

return R.compose(
traverseUpAndCollectTerminalChain(terminalNodeIds, links),
R.over(R.lensIndex(0), R.append(nextNodeId)),
Expand Down
111 changes: 111 additions & 0 deletions packages/xod-project/test/fixtures/cast-custom-types.xodball
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,117 @@
"type": "xod/patch-nodes/input-byte"
}
}
},
"@/test-wrapped-i2c": {
"nodes": {
"wrapped-i2c-node": {
"id": "wrapped-i2c-node",
"position": {
"x": -2,
"y": -1,
"units": "slots"
},
"type": "@/wrapped-i2c"
}
},
"path": "@/main"
},
"@/wrapped-i2c": {
"links": {
"terminal-to-node": {
"id": "terminal-to-node",
"input": {
"nodeId": "test-node",
"pinKey": "input-i2c"
},
"output": {
"nodeId": "input-i2c-terminal",
"pinKey": "__out__"
}
}
},
"nodes": {
"test-node": {
"id": "test-node",
"position": {
"x": 1,
"y": 1,
"units": "slots"
},
"type": "xod/i2c/test"
},
"input-i2c-terminal": {
"id": "input-i2c-terminal",
"label": "I2C",
"position": {
"x": 1,
"y": 0,
"units": "slots"
},
"type": "xod/i2c/input-i2c"
}
},
"path": "@/wrapped-i2c"
},
"xod/i2c/i2c": {
"attachments": [
{
"filename": "patch.cpp",
"encoding": "utf-8",
"content": "// implementation"
}
],
"nodes": {
"output-self": {
"id": "output-self",
"position": {
"units": "slots",
"x": 2,
"y": 2
},
"type": "xod/patch-nodes/output-self"
},
"niix": {
"id": "niix",
"position": {
"units": "slots",
"x": 2,
"y": 1
},
"type": "xod/patch-nodes/not-implemented-in-xod"
}
},
"path": "xod/i2c/i2c"
},
"xod/i2c/test": {
"attachments": [
{
"filename": "patch.cpp",
"encoding": "utf-8",
"content": "// implementation"
}
],
"nodes": {
"input-i2c": {
"id": "input-i2c",
"position": {
"units": "slots",
"x": 2,
"y": 2
},
"type": "xod/i2c/input-i2c"
},
"niix": {
"id": "niix",
"position": {
"units": "slots",
"x": 2,
"y": 1
},
"type": "xod/patch-nodes/not-implemented-in-xod"
}
},
"path": "xod/i2c/test"
}
}
}
19 changes: 19 additions & 0 deletions packages/xod-project/test/flatten.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,25 @@ describe('Flatten', () => {
'color-nested~nested-again~hsl-node-to-watch-node-pin-input-string'
));

it('should not create a cast node for a custom type if it not needed', () => {
const flatProject = flatten(project, '@/test-wrapped-i2c');
Helper.expectEitherRight(newProject => {
const nodeIds = R.compose(
R.map(Node.getNodeId),
Patch.listNodes,
Project.getPatchByPathUnsafe('@/test-wrapped-i2c')
)(newProject);

const links = R.compose(
Patch.listLinks,
Project.getPatchByPathUnsafe('@/test-wrapped-i2c')
)(newProject);

assert.sameMembers(['wrapped-i2c-node~test-node'], nodeIds);
assert.isEmpty(links);
}, flatProject);
});

it('should return Either.Left if custom type does not have a cast node', () => {
const flatProject = flatten(project, '@/test-no-cast-node');
Helper.expectEitherError(
Expand Down

0 comments on commit 9d0c62c

Please sign in to comment.