feat(xod-arduino): do not allow native nodes with more than 7 outputs

This commit is contained in:
Evgeny Kochetkov
2017-08-02 20:56:30 +03:00
parent 267af7c719
commit ddd67034da
8 changed files with 127 additions and 8 deletions

View File

@@ -46,6 +46,7 @@ const kebabToSnake = R.replace(/-/g, '_');
const createPatchNames = def(
'createPatchNames :: PatchPath -> { owner :: String, libName :: String, patchName :: String }',
(path) => {
// TODO: this handles @/local-patches incorrectly
const [owner, libName, ...patchNameParts] = R.split('/', path);
const patchName = patchNameParts.join('/');
@@ -194,7 +195,7 @@ const getPinLabelsMap = def(
);
const getNodePinsUnsafe = def(
'getNodePinLabels :: Node -> Project -> [Pin]',
'getNodePinsUnsafe :: Node -> Project -> [Pin]',
(node, project) => R.compose(
explodeMaybe(`Cant get node pins of node ${node}. Referred type missing?`),
Project.getNodePins
@@ -349,6 +350,19 @@ const createTNodes = def(
export const transformProject = def(
'transformProject :: [Source] -> Project -> PatchPath -> Either Error TProject',
(impls, project, path) => R.compose(
R.chain((tProject) => {
const nodeWithTooManyOutputs = R.find(
R.pipe(R.prop('outputs'), R.length, R.lte(7)),
tProject.patches
);
if (nodeWithTooManyOutputs) {
const { owner, libName, patchName } = nodeWithTooManyOutputs;
return Either.Left(new Error(`Native node ${owner}/${libName}/${patchName} has more than 7 outputs`));
}
return Either.of(tProject);
}),
R.map(([proj, topology]) => {
const patches = createTPatches(path, proj);

View File

@@ -1,4 +1,4 @@
--require babel-register
--colors
--timeout 120000
--timeout 240000
--plugins babel-plugin-inline-import

View File

@@ -3,7 +3,7 @@ import path from 'path';
import R from 'ramda';
import { assert } from 'chai';
import { explode } from 'xod-func-tools';
import { explode, foldEither } from 'xod-func-tools';
import { loadProject } from 'xod-fs';
import { PIN_TYPE } from 'xod-project';
import { defaultizePin } from 'xod-project/test/helpers';
@@ -35,6 +35,19 @@ describe('xod-arduino transpiler', () => {
.then(transpile(R.__, '@/non-existing-patch'))
.then(result => assert.ok(result.isLeft))
);
it('returns error if some native node has more than 7 outputs',
() =>
loadProject(wsPath('faulty'))
.then(transpile(R.__, '@/too-many-outputs-main'))
.then(foldEither(
(err) => {
assert.include(err.message, '@/too_many_outputs');
assert.include(err.message, 'has more than 7 outputs');
},
() => assert.fail('expecting Either.Left')
))
);
});
describe('getInitialDirtyFlags', () => {

View File

@@ -1136,11 +1136,11 @@ namespace xod {
};
DirtyFlags dirtyFlags[NODE_COUNT] = {
DirtyFlags(-1),
DirtyFlags(-1),
DirtyFlags(-1),
DirtyFlags(-1),
DirtyFlags(-1)
DirtyFlags(253),
DirtyFlags(255),
DirtyFlags(255),
DirtyFlags(255),
DirtyFlags(255)
};
NodeId topology[NODE_COUNT] = {

View File

@@ -0,0 +1,3 @@
{
"name": "faulty"
}

View File

@@ -0,0 +1,12 @@
{
"nodes": [
{
"id": "Bk-49Oyw-",
"position": {
"x": 138,
"y": 120
},
"type": "@/too-many-outputs"
}
]
}

View File

@@ -0,0 +1 @@
// it shoud not transpile anyway

View File

@@ -0,0 +1,76 @@
{
"nodes": [
{
"id": "Bkby9_1vb",
"position": {
"x": 138,
"y": 224
},
"type": "xod/patch-nodes/output-number"
},
{
"id": "H14e5uyDZ",
"position": {
"x": 778,
"y": 224
},
"type": "xod/patch-nodes/output-pulse"
},
{
"id": "Hy0CF_kDW",
"position": {
"x": 10,
"y": 224
},
"type": "xod/patch-nodes/output-boolean"
},
{
"id": "S1N1cdJDW",
"position": {
"x": 266,
"y": 224
},
"type": "xod/patch-nodes/output-pulse"
},
{
"id": "SJ_e9uJvZ",
"position": {
"x": 906,
"y": 224
},
"type": "xod/patch-nodes/output-string"
},
{
"id": "SkhkcdyDb",
"position": {
"x": 522,
"y": 224
},
"type": "xod/patch-nodes/output-boolean"
},
{
"id": "rJ4ZcukDb",
"position": {
"x": 10,
"y": 16
},
"type": "xod/patch-nodes/not-implemented-in-xod"
},
{
"id": "rkO1quyPW",
"position": {
"x": 394,
"y": 224
},
"type": "xod/patch-nodes/output-string"
},
{
"id": "rkbl5dyPb",
"position": {
"x": 650,
"y": 224
},
"type": "xod/patch-nodes/output-number"
}
]
}