Skip to content

Commit b7a62ec

Browse files
committed
posix-ify tests in an attempt to normalize across platforms
1 parent 433d893 commit b7a62ec

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

test/pattern_graph_tests.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var VERSION = require('../core/lib/pattern_graph').PATTERN_GRAPH_VERSION;
66
var Pattern = require('../core/lib/object_factory').Pattern;
77
var CompileState = require('../core/lib/object_factory').CompileState;
88
var tap = require('tap');
9+
const posixPath = require('./util/test_utils.js').posixPath;
910

1011
var patternlab = {
1112
config: {
@@ -150,7 +151,7 @@ tap.test("Adding two nodes with only different subpattern types", (test) => {
150151
g.add(atomFoo);
151152
g.add(moleculeFoo);
152153
var actual = g.nodes();
153-
test.same(actual, ["00-atoms/00-foo/baz.html", "00-atoms/00-bar/baz.html"]);
154+
test.same(posixPath(actual), ["00-atoms/00-foo/baz.html", "00-atoms/00-bar/baz.html"]);
154155
test.end();
155156
});
156157

@@ -224,10 +225,10 @@ tap.test("filter() - Removing nodes via filter", (test) => {
224225
g.link(moleculeBar, atomFoo);
225226

226227
tap.test("lineage() - Calculate the lineage of a node", (test) => {
227-
test.same(g.lineage(organismFoo).map(p => p.relPath), ["01-molecule/xy/foo"]);
228-
test.same(g.lineage(organismBar).map(p => p.relPath), ["01-molecule/xy/foo","01-molecule/xy/bar"]);
229-
test.same(g.lineage(moleculeFoo).map(p => p.relPath), ["00-atom/xy/foo"]);
230-
test.same(g.lineage(moleculeBar).map(p => p.relPath), ["00-atom/xy/foo"]);
228+
test.same(posixPath(g.lineage(organismFoo).map(p => p.relPath)), ["01-molecule/xy/foo"]);
229+
test.same(posixPath(g.lineage(organismBar).map(p => p.relPath)), ["01-molecule/xy/foo","01-molecule/xy/bar"]);
230+
test.same(posixPath(g.lineage(moleculeFoo).map(p => p.relPath)), ["00-atom/xy/foo"]);
231+
test.same(posixPath(g.lineage(moleculeBar).map(p => p.relPath)), ["00-atom/xy/foo"]);
231232
test.same(g.lineage(atomFoo).map(p => p.relPath), []);
232233
test.same(g.lineage(atomIsolated).map(p => p.relPath), []);
233234
test.end();
@@ -246,9 +247,9 @@ tap.test("filter() - Removing nodes via filter", (test) => {
246247
tap.test("lineageR() - Calculate the reverse lineage of a node", (test) => {
247248
test.same(g.lineageR(organismFoo).map(p => p.relPath), []);
248249
test.same(g.lineageR(organismBar).map(p => p.relPath), []);
249-
test.same(g.lineageR(moleculeFoo).map(p => p.relPath), ["02-organism/xy/foo", "02-organism/xy/bar"]);
250-
test.same(g.lineageR(moleculeBar).map(p => p.relPath), ["02-organism/xy/bar"]);
251-
test.same(g.lineageR(atomFoo).map(p => p.relPath), ["01-molecule/xy/foo", "01-molecule/xy/bar"]);
250+
test.same(posixPath(g.lineageR(moleculeFoo).map(p => p.relPath)), ["02-organism/xy/foo", "02-organism/xy/bar"]);
251+
test.same(posixPath(g.lineageR(moleculeBar).map(p => p.relPath)), ["02-organism/xy/bar"]);
252+
test.same(posixPath(g.lineageR(atomFoo).map(p => p.relPath)), ["01-molecule/xy/foo", "01-molecule/xy/bar"]);
252253
test.same(g.lineageR(atomIsolated).map(p => p.relPath), []);
253254
test.end();
254255
});

test/util/test_utils.js

+18
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,23 @@ module.exports = {
3636
*/
3737
sanitized: (outputTemplate) => {
3838
return outputTemplate.replace(/\n/g, ' ').replace(/\r/g, ' ').replace(/\s\s+/g, ' ').trim();
39+
},
40+
41+
/**
42+
* normalize a string (probably a path) to posix - style
43+
* @param s - the string or array of strings to normalize path separators to posix - style
44+
*/
45+
posixPath: (s) => {
46+
if (Array.isArray(s)) {
47+
var paths = [];
48+
for (let i = 0; i < s.length; i++) {
49+
paths.push(s[i].replace(/\\/g,"/"));
50+
}
51+
return paths;
52+
} else {
53+
return s.replace(/\\/g,"/");
54+
}
3955
}
56+
57+
4058
};

0 commit comments

Comments
 (0)