mirror of
https://github.com/xodio/xod.git
synced 2026-03-13 04:06:53 +01:00
feat(xod-arduino): do not allow native nodes with more than 7 outputs
This commit is contained in:
@@ -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(`Can’t 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);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
--require babel-register
|
||||
--colors
|
||||
--timeout 120000
|
||||
--timeout 240000
|
||||
--plugins babel-plugin-inline-import
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -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] = {
|
||||
|
||||
3
workspace/faulty/project.xod
Normal file
3
workspace/faulty/project.xod
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "faulty"
|
||||
}
|
||||
12
workspace/faulty/too-many-outputs-main/patch.xodp
Normal file
12
workspace/faulty/too-many-outputs-main/patch.xodp
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"nodes": [
|
||||
{
|
||||
"id": "Bk-49Oyw-",
|
||||
"position": {
|
||||
"x": 138,
|
||||
"y": 120
|
||||
},
|
||||
"type": "@/too-many-outputs"
|
||||
}
|
||||
]
|
||||
}
|
||||
1
workspace/faulty/too-many-outputs/any.cpp
Normal file
1
workspace/faulty/too-many-outputs/any.cpp
Normal file
@@ -0,0 +1 @@
|
||||
// it shoud not transpile anyway
|
||||
76
workspace/faulty/too-many-outputs/patch.xodp
Normal file
76
workspace/faulty/too-many-outputs/patch.xodp
Normal 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"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user