Merge pull request #2023 from xodio/fix-flatten-for-unbound-custom-type

Fix bug in flattening when uppermost custom type terminal has no input links
This commit is contained in:
Kirill Shumilov
2020-08-21 16:18:58 +03:00
committed by GitHub
3 changed files with 133 additions and 0 deletions

View File

@@ -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)),

View File

@@ -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"
}
}
}

View File

@@ -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(