Skip to content

Commit

Permalink
Upgrade unit testing libs to gain Set content testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Bishop committed Aug 19, 2017
1 parent e0e90d1 commit 0471cdd
Show file tree
Hide file tree
Showing 12 changed files with 319 additions and 198 deletions.
2 changes: 1 addition & 1 deletion dist/js.spec.bundle.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions lib/spec/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ export class Collection extends Spec {
}
}

const ret = [];
for (const [key, val] of value.entries()) {
const conformed = dt(this.options.spec, val);
if (conformed === invalid) {
return invalid;
}
ret[key] = conformed;
const spreadValue = p.array(value) ? value : [...value];
const ret = spreadValue
.map(val => dt(this.options.spec, val))
.filter(val => val !== invalid);

if (spreadValue.length > ret.length) {
return invalid;
}
return p.array(value) ? ret : new Set(ret);
}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-es2015": "^6.18.0",
"babel-register": "^6.18.0",
"chai": "^3.5.0",
"coveralls": "^2.11.14",
"chai": "^4.1.1",
"coveralls": "2.13.1",
"eslint": "^4.4.1",
"eslint-plugin-prettier": "^2.1.2",
"mocha": "^3.1.2",
"mocha": "^3.5.0",
"nodemon": "^1.11.0",
"prettier": "^1.5.3",
"pretty-format": "^18.0.0",
Expand Down
40 changes: 20 additions & 20 deletions test/regex/alt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,33 +131,33 @@ describe("alt", () => {
//
expect(problems).to.be.an("array").and.to.have.length(2);

expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].predicate")
.that.is.a("function");
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].path")
.that.is.an("array")
.and.deep.equals([0]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].via")
.that.is.an("array")
.and.deep.equals(["alt |", "regular", "cat ·"]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].value")
.that.deep.equals(["spoons"]);

expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[1].predicate")
.that.is.a("function");
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[1].path")
.that.is.an("array")
.and.deep.equals([1]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[1].via")
.that.is.an("array")
.and.deep.equals(["alt |", "reversed", "cat ·"]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[1].value")
.that.deep.equals(["spoons"]);
});
Expand All @@ -170,44 +170,44 @@ describe("alt", () => {

expect(problems).to.be.an("array").and.to.have.length(3);

expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].predicate")
.that.is.a("function");
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].path")
.that.is.an("array")
.and.deep.equals([0, 0]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].via")
.that.is.an("array")
.and.deep.equals(["alt |", "regular", "cat ·", "quantity", "isNumber"]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].value")
.that.deep.equals("spoons");

expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[1].predicate")
.that.is.a("function");
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[1].path")
.that.is.an("array")
.and.deep.equals([0, 1]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[1].via")
.that.is.an("array")
.and.deep.equals(["alt |", "regular", "cat ·", "unit", "isString"]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[1].value")
.that.deep.equals(false);

expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[2].predicate")
.that.is.a("function");
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[2].path")
.that.is.an("array")
.and.deep.equals([1, 1]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[2].via")
.that.is.an("array")
.and.deep.equals([
Expand All @@ -217,7 +217,7 @@ describe("alt", () => {
"quantity",
"isNumber"
]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[2].value")
.that.deep.equals(false);
});
Expand Down
16 changes: 8 additions & 8 deletions test/regex/cat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ describe("cat", () => {
const problems = explainData(weak_ingredient, ["spoons"]);

expect(problems).to.be.an("array").and.to.have.length(1);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].predicate")
.that.is.a("function");
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].path")
.that.is.an("array")
.and.deep.equals([]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].via")
.that.is.an("array")
.and.deep.equals(["cat ·"]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].value")
.that.deep.equals(["spoons"]);
});
Expand All @@ -140,18 +140,18 @@ describe("cat", () => {
const problems = explainData(weak_ingredient, ["spoons", false]);

expect(problems).to.be.an("array").and.to.have.length(1);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].predicate")
.that.is.a("function");
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].path")
.that.is.an("array")
.and.deep.equals([1]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].via")
.that.is.an("array")
.and.deep.equals(["cat ·", "unit"]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].value")
.that.deep.equals(false);
});
Expand Down
66 changes: 42 additions & 24 deletions test/spec/and.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ describe("and", () => {
const problems = explainData(positioned_friend, value);

expect(problems).to.be.an("array").and.have.length(1);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].via")
.that.deep.equals(["positioned friend", "friend", "Keys(friend)"]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].path")
.that.deep.equals(["name"]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].predicate")
.that.is.a("function");
expect(problems).to.have.deep.property("[0].value").that.equals(value);
expect(problems).to.have.deep.nested
.property("[0].value")
.that.equals(value);
});

it("[not positioned]", () => {
Expand All @@ -46,20 +48,22 @@ describe("and", () => {
const problems = explainData(positioned_friend, value);

expect(problems).to.be.an("array").and.have.length(1);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].via")
.that.deep.equals([
"positioned friend",
"positioned",
"Keys(positioned)"
]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].path")
.that.deep.equals(["lon"]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].predicate")
.that.is.a("function");
expect(problems).to.have.deep.property("[0].value").that.equals(value);
expect(problems).to.have.deep.nested
.property("[0].value")
.that.equals(value);
});

it("[neither]", () => {
Expand All @@ -70,61 +74,75 @@ describe("and", () => {
const problems = explainData(positioned_friend, value);

expect(problems).to.be.an("array").and.have.length(1);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].via")
.that.deep.equals([
"positioned friend",
"positioned",
"Keys(positioned)"
]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].path")
.that.deep.equals(["lon"]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].predicate")
.that.is.a("function");
expect(problems).to.have.deep.property("[0].value").that.equals(value);
expect(problems).to.have.deep.nested
.property("[0].value")
.that.equals(value);
});
});

describe("works on predicates", () => {
it("[not an int]", () => {
const problems = explainData(big_even, "1002");
expect(problems).to.be.an("array").and.have.length(1);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].via")
.that.deep.equals(["big even", "isInteger"]);
expect(problems).to.have.deep.property("[0].path").that.deep.equals([]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].path")
.that.deep.equals([]);
expect(problems).to.have.deep.nested
.property("[0].predicate")
.that.is.a("function");
expect(problems).to.have.deep.property("[0].value").that.equals("1002");
expect(problems).to.have.deep.nested
.property("[0].value")
.that.equals("1002");
});

it("[not big]", () => {
const problems = explainData(big_even, 1000);
expect(problems).to.be.an("array").and.have.length(1);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].via")
.that.deep.equals(["big even", "[anonymous function]"]);
expect(problems).to.have.deep.property("[0].path").that.deep.equals([]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].path")
.that.deep.equals([]);
expect(problems).to.have.deep.nested
.property("[0].predicate")
.that.is.a("function");
expect(problems).to.have.deep.property("[0].value").that.equals(1000);
expect(problems).to.have.deep.nested
.property("[0].value")
.that.equals(1000);
});

it("[not even]", () => {
const problems = explainData(big_even, 1001);
expect(problems).to.be.an("array").and.have.length(1);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].via")
.that.deep.equals(["big even", "even"]);
expect(problems).to.have.deep.property("[0].path").that.deep.equals([]);
expect(problems).to.have.deep
expect(problems).to.have.deep.nested
.property("[0].path")
.that.deep.equals([]);
expect(problems).to.have.deep.nested
.property("[0].predicate")
.that.is.a("function");
expect(problems).to.have.deep.property("[0].value").that.equals(1001);
expect(problems).to.have.deep.nested
.property("[0].value")
.that.equals(1001);
});
});
});
Expand Down
Loading

0 comments on commit 0471cdd

Please sign in to comment.