mirror of
https://github.com/xodio/xod.git
synced 2026-03-24 01:26:53 +01:00
fix(xod-tabtest, xod-arduino): escape pin labels for C++
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
foldEither,
|
||||
isAmong,
|
||||
fail,
|
||||
cppEscape,
|
||||
} from 'xod-func-tools';
|
||||
import * as XP from 'xod-project';
|
||||
import { def } from './types';
|
||||
@@ -77,6 +78,8 @@ const toposortProject = def(
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const pinLabelLens = R.lens(XP.getPinLabel, XP.setPinLabel);
|
||||
|
||||
const arrangeTPatchesInTopologicalOrder = def(
|
||||
'arrangeTPatchesInTopologicalOrder :: PatchPath -> Project -> Map PatchPath TPatch -> [TPatch]',
|
||||
(entryPath, project, tpatchesMap) =>
|
||||
@@ -128,6 +131,7 @@ const convertPatchToTPatch = def(
|
||||
),
|
||||
})
|
||||
),
|
||||
R.map(R.over(pinLabelLens, cppEscape)),
|
||||
XP.normalizeEmptyPinLabels,
|
||||
XP.listOutputPins
|
||||
)(patch);
|
||||
@@ -140,6 +144,7 @@ const convertPatchToTPatch = def(
|
||||
isDirtyable,
|
||||
})
|
||||
),
|
||||
R.map(R.over(pinLabelLens, cppEscape)),
|
||||
XP.normalizeEmptyPinLabels,
|
||||
XP.listInputPins
|
||||
)(patch);
|
||||
@@ -274,7 +279,12 @@ const getNodePinsUnsafe = def(
|
||||
|
||||
const getNodePinLabels = def(
|
||||
'getNodePinLabels :: Node -> Project -> Map PinKey PinLabel',
|
||||
R.compose(getPinLabelsMap, XP.normalizeEmptyPinLabels, getNodePinsUnsafe)
|
||||
R.compose(
|
||||
getPinLabelsMap,
|
||||
R.map(R.over(pinLabelLens, cppEscape)),
|
||||
XP.normalizeEmptyPinLabels,
|
||||
getNodePinsUnsafe
|
||||
)
|
||||
);
|
||||
|
||||
// TODO: Remove it when `Project.getBoundValue` will return default values
|
||||
|
||||
@@ -68,6 +68,8 @@ module Record = {
|
||||
type t = Map.String.t(Value.t);
|
||||
let fromPairs = (pairs: list((string, Value.t))) : t =>
|
||||
pairs |. List.toArray |. Map.String.fromArray;
|
||||
let toPairs = (record: t) : list((string, Value.t)) =>
|
||||
record |. Map.String.toList;
|
||||
let get = (t, column) =>
|
||||
Map.String.get(t, column)
|
||||
|. Option.flatMap(value =>
|
||||
|
||||
@@ -201,11 +201,12 @@ module TestCase = {
|
||||
|. Probes.keepInjecting
|
||||
|. Probes.map(probe => {
|
||||
let name = probe |. Probe.getTargetPin |. Pin.getLabel;
|
||||
let probeName = Strings.cppEscape(name);
|
||||
switch (record |. TabData.Record.get(name)) {
|
||||
| Some(Pulse(false)) => {j|// No pulse for $name|j}
|
||||
| Some(value) =>
|
||||
let literal = valueToLiteral(value);
|
||||
{j|INJECT(probe_$name, $literal);|j};
|
||||
{j|INJECT(probe_$probeName, $literal);|j};
|
||||
| None => {j|// No changes for $name|j}
|
||||
};
|
||||
});
|
||||
@@ -260,11 +261,17 @@ module TestCase = {
|
||||
let nodeAliases =
|
||||
idMap
|
||||
|. Map.String.toList
|
||||
|. List.map(((name, id)) => {j|auto& probe_$name = xod::node_$id;|j});
|
||||
|. List.map(
|
||||
((name, id)) => {
|
||||
let probeName = Strings.cppEscape(name);
|
||||
{j|auto& probe_$probeName = xod::node_$id;|j}
|
||||
}
|
||||
);
|
||||
let sections =
|
||||
tabData
|
||||
|. TabData.mapWithIndex((idx, record) =>
|
||||
generateSection(record, probes, idx)
|
||||
record
|
||||
|. generateSection(probes, idx)
|
||||
);
|
||||
Cpp.(
|
||||
source([
|
||||
@@ -315,7 +322,10 @@ let generatePatchSuite = (project, patchPathToTest) : XResult.t(t) => {
|
||||
let realPinLabels =
|
||||
bench.probeMap |> Map.String.keysToArray |> List.fromArray;
|
||||
let testingPinLabels =
|
||||
tsv |. TabData.listDataLines |. List.getExn(0) |. TabData.tabSplit;
|
||||
tsv
|
||||
|. TabData.listDataLines
|
||||
|. List.getExn(0)
|
||||
|. TabData.tabSplit;
|
||||
let result =
|
||||
switch (Validator.validatePinLabels(realPinLabels, testingPinLabels)) {
|
||||
| Some(e) => Result.Error(e)
|
||||
|
||||
Reference in New Issue
Block a user