Remove chai tests, using plain old assert instead

This commit is contained in:
Tony Garnock-Jones 2019-08-31 22:44:54 +01:00
parent 9ab66ae44d
commit 632a6be4b9
5 changed files with 181 additions and 208 deletions

View File

@ -15,8 +15,6 @@
"main": "src/index.js", "main": "src/index.js",
"author": "Tony Garnock-Jones <tonyg@leastfixedpoint.com>", "author": "Tony Garnock-Jones <tonyg@leastfixedpoint.com>",
"devDependencies": { "devDependencies": {
"chai": "^4.2.0",
"chai-immutable": "^2.0.0-rc.3",
"mocha": "^5.2.0", "mocha": "^5.2.0",
"nyc": "^14.1.1" "nyc": "^14.1.1"
}, },

View File

@ -17,30 +17,30 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
const expect = require('chai').expect; const assert = require('assert');
const Immutable = require('immutable'); const Immutable = require('immutable');
const Bag = require('../src/bag.js'); const Bag = require('../src/bag.js');
describe('immutable bag', function () { describe('immutable bag', function () {
it('should be initializable from a set', function () { it('should be initializable from a set', function () {
var b = Bag.fromSet(Immutable.Set(['a', 'b', 'c'])); var b = Bag.fromSet(Immutable.Set(['a', 'b', 'c']));
expect(b.count()).to.equal(3); assert.strictEqual(b.count(), 3);
expect(Bag.get(b, 'a')).to.equal(1); assert.strictEqual(Bag.get(b, 'a'), 1);
expect(Bag.get(b, 'z')).to.equal(0); assert.strictEqual(Bag.get(b, 'z'), 0);
}); });
it('should be initializable from an array', function () { it('should be initializable from an array', function () {
var b = Bag.fromSet(['a', 'b', 'c', 'a']); var b = Bag.fromSet(['a', 'b', 'c', 'a']);
expect(b.count()).to.equal(3); assert.strictEqual(b.count(), 3);
expect(Bag.get(b, 'a')).to.equal(1); assert.strictEqual(Bag.get(b, 'a'), 1);
expect(Bag.get(b, 'z')).to.equal(0); assert.strictEqual(Bag.get(b, 'z'), 0);
}); });
it('should be immutable', function () { it('should be immutable', function () {
var b = Bag.Bag(); var b = Bag.Bag();
Bag.change(b, 'a', 1); Bag.change(b, 'a', 1);
Bag.change(b, 'a', 1); Bag.change(b, 'a', 1);
expect(b).to.equal(Bag.Bag()); assert(Immutable.is(b, Bag.Bag()));
}); });
it('should count up', function () { it('should count up', function () {
@ -48,10 +48,10 @@ describe('immutable bag', function () {
var change1, change2; var change1, change2;
({bag: b, net: change1} = Bag.change(b, 'a', 1)); ({bag: b, net: change1} = Bag.change(b, 'a', 1));
({bag: b, net: change2} = Bag.change(b, 'a', 1)); ({bag: b, net: change2} = Bag.change(b, 'a', 1));
expect(change1).to.equal(Bag.ABSENT_TO_PRESENT); assert.strictEqual(change1, Bag.ABSENT_TO_PRESENT);
expect(change2).to.equal(Bag.PRESENT_TO_PRESENT); assert.strictEqual(change2, Bag.PRESENT_TO_PRESENT);
expect(Bag.get(b, 'a')).to.equal(2); assert.strictEqual(Bag.get(b, 'a'), 2);
expect(Bag.get(b, 'z')).to.equal(0); assert.strictEqual(Bag.get(b, 'z'), 0);
}); });
it('should count down', function () { it('should count down', function () {
@ -59,18 +59,18 @@ describe('immutable bag', function () {
var c1, c2, c3, c4; var c1, c2, c3, c4;
({bag: b, net: c1} = Bag.change(b, 'a', 1)); ({bag: b, net: c1} = Bag.change(b, 'a', 1));
({bag: b, net: c2} = Bag.change(b, 'a', -1)); ({bag: b, net: c2} = Bag.change(b, 'a', -1));
expect(b.count()).to.equal(1); assert.strictEqual(b.count(), 1);
expect(c1).to.equal(Bag.PRESENT_TO_PRESENT); assert.strictEqual(c1, Bag.PRESENT_TO_PRESENT);
expect(c2).to.equal(Bag.PRESENT_TO_PRESENT); assert.strictEqual(c2, Bag.PRESENT_TO_PRESENT);
({bag: b, net: c3} = Bag.change(b, 'a', -1)); ({bag: b, net: c3} = Bag.change(b, 'a', -1));
expect(b.count()).to.equal(0); assert.strictEqual(b.count(), 0);
expect(c3).to.equal(Bag.PRESENT_TO_ABSENT); assert.strictEqual(c3, Bag.PRESENT_TO_ABSENT);
expect(Bag.get(b, 'a')).to.equal(0); assert.strictEqual(Bag.get(b, 'a'), 0);
expect(Bag.get(b, 'z')).to.equal(0); assert.strictEqual(Bag.get(b, 'z'), 0);
({bag: b, net: c4} = Bag.change(b, 'a', -1)); ({bag: b, net: c4} = Bag.change(b, 'a', -1));
expect(b.count()).to.equal(1); assert.strictEqual(b.count(), 1);
expect(c4).to.equal(Bag.ABSENT_TO_PRESENT); assert.strictEqual(c4, Bag.ABSENT_TO_PRESENT);
expect(Bag.get(b, 'a')).to.equal(-1); assert.strictEqual(Bag.get(b, 'a'), -1);
}); });
it('should be clamped', function() { it('should be clamped', function() {
@ -79,53 +79,53 @@ describe('immutable bag', function () {
({bag: b} = Bag.change(b, 'a', -1, true)); ({bag: b} = Bag.change(b, 'a', -1, true));
({bag: b} = Bag.change(b, 'a', -1, true)); ({bag: b} = Bag.change(b, 'a', -1, true));
({bag: b} = Bag.change(b, 'a', -1, true)); ({bag: b} = Bag.change(b, 'a', -1, true));
expect(b.count()).to.equal(0); assert.strictEqual(b.count(), 0);
expect(Bag.get(b, 'a')).to.equal(0); assert.strictEqual(Bag.get(b, 'a'), 0);
}); });
}); });
describe('mutable bag', function () { describe('mutable bag', function () {
it('should be initializable from a set', function () { it('should be initializable from a set', function () {
var b = new Bag.MutableBag(Immutable.Set(['a', 'b', 'c'])); var b = new Bag.MutableBag(Immutable.Set(['a', 'b', 'c']));
expect(b.count()).to.equal(3); assert.strictEqual(b.count(), 3);
expect(b.get('a')).to.equal(1); assert.strictEqual(b.get('a'), 1);
expect(b.get('z')).to.equal(0); assert.strictEqual(b.get('z'), 0);
}); });
it('should be initializable from an array', function () { it('should be initializable from an array', function () {
var b = new Bag.MutableBag(['a', 'b', 'c', 'a']); var b = new Bag.MutableBag(['a', 'b', 'c', 'a']);
expect(b.count()).to.equal(3); assert.strictEqual(b.count(), 3);
expect(b.get('a')).to.equal(1); assert.strictEqual(b.get('a'), 1);
expect(b.get('z')).to.equal(0); assert.strictEqual(b.get('z'), 0);
}); });
it('should be mutable', function () { it('should be mutable', function () {
var b = new Bag.MutableBag(); var b = new Bag.MutableBag();
b.change('a', 1); b.change('a', 1);
b.change('a', 1); b.change('a', 1);
expect(b.get('a')).to.equal(2); assert.strictEqual(b.get('a'), 2);
expect(b.get('z')).to.equal(0); assert.strictEqual(b.get('z'), 0);
}); });
it('should count up', function () { it('should count up', function () {
var b = new Bag.MutableBag(); var b = new Bag.MutableBag();
expect(b.change('a', 1)).to.equal(Bag.ABSENT_TO_PRESENT); assert.strictEqual(b.change('a', 1), Bag.ABSENT_TO_PRESENT);
expect(b.change('a', 1)).to.equal(Bag.PRESENT_TO_PRESENT); assert.strictEqual(b.change('a', 1), Bag.PRESENT_TO_PRESENT);
expect(b.get('a')).to.equal(2); assert.strictEqual(b.get('a'), 2);
expect(b.get('z')).to.equal(0); assert.strictEqual(b.get('z'), 0);
}); });
it('should count down', function () { it('should count down', function () {
var b = new Bag.MutableBag(['a']); var b = new Bag.MutableBag(['a']);
expect(b.change('a', 1)).to.equal(Bag.PRESENT_TO_PRESENT); assert.strictEqual(b.change('a', 1), Bag.PRESENT_TO_PRESENT);
expect(b.change('a', -1)).to.equal(Bag.PRESENT_TO_PRESENT); assert.strictEqual(b.change('a', -1), Bag.PRESENT_TO_PRESENT);
expect(b.count()).to.equal(1); assert.strictEqual(b.count(), 1);
expect(b.change('a', -1)).to.equal(Bag.PRESENT_TO_ABSENT); assert.strictEqual(b.change('a', -1), Bag.PRESENT_TO_ABSENT);
expect(b.count()).to.equal(0); assert.strictEqual(b.count(), 0);
expect(b.get('a')).to.equal(0); assert.strictEqual(b.get('a'), 0);
expect(b.get('z')).to.equal(0); assert.strictEqual(b.get('z'), 0);
expect(b.change('a', -1)).to.equal(Bag.ABSENT_TO_PRESENT); assert.strictEqual(b.change('a', -1), Bag.ABSENT_TO_PRESENT);
expect(b.count()).to.equal(1); assert.strictEqual(b.count(), 1);
expect(b.get('a')).to.equal(-1); assert.strictEqual(b.get('a'), -1);
}); });
}); });

View File

@ -17,7 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
var expect = require('chai').expect; const assert = require('assert');
var Immutable = require('immutable'); var Immutable = require('immutable');
var Dataflow = require('../src/dataflow.js'); var Dataflow = require('../src/dataflow.js');
@ -37,11 +37,11 @@ function DerivedCell(graph, name, valueThunk) {
} }
function expectSetsEqual(a, bArray) { function expectSetsEqual(a, bArray) {
return expect(Immutable.is(a, Immutable.Set(bArray))).to.equal(true); assert(Immutable.is(a, Immutable.Set(bArray)));
} }
function checkDamagedNodes(g, expectedObjects) { function checkDamagedNodes(g, expectedObjects) {
return expectSetsEqual(g.damagedNodes, expectedObjects); expectSetsEqual(g.damagedNodes, expectedObjects);
} }
describe('dataflow', () => { describe('dataflow', () => {
@ -55,7 +55,7 @@ describe('dataflow', () => {
g.withSubject('s', () => { c.value; }); g.withSubject('s', () => { c.value; });
c.value = 234; c.value = 234;
expect(g.damagedNodes.size).to.equal(1); assert.strictEqual(g.damagedNodes.size, 1);
var subjects = Immutable.Set(); var subjects = Immutable.Set();
g.repairDamage(function (subjectId) { subjects = subjects.add(subjectId); }); g.repairDamage(function (subjectId) { subjects = subjects.add(subjectId); });
@ -69,26 +69,26 @@ describe('dataflow', () => {
var c = DerivedCell(g, 'c', () => 123); var c = DerivedCell(g, 'c', () => 123);
var d = DerivedCell(g, 'd', () => c.value * 2); var d = DerivedCell(g, 'd', () => c.value * 2);
it('should be properly initialized', () => { it('should be properly initialized', () => {
expect(c.value).to.equal(123); assert.strictEqual(c.value, 123);
expect(d.value).to.equal(246); assert.strictEqual(d.value, 246);
}); });
it('should lead initially to damaged everything', () => { it('should lead initially to damaged everything', () => {
expect(g.damagedNodes.size).to.equal(2); assert.strictEqual(g.damagedNodes.size, 2);
}); });
it('should repair idempotently after initialization', () => { it('should repair idempotently after initialization', () => {
g.repairDamage(function (c) { c.refresh(); }); g.repairDamage(function (c) { c.refresh(); });
expect(c.value).to.equal(123); assert.strictEqual(c.value, 123);
expect(d.value).to.equal(246); assert.strictEqual(d.value, 246);
}); });
it('should be inconsistent after modification but before repair', () => { it('should be inconsistent after modification but before repair', () => {
c.value = 124; c.value = 124;
expect(c.value).to.equal(124); assert.strictEqual(c.value, 124);
expect(d.value).to.equal(246); assert.strictEqual(d.value, 246);
}); });
it('should repair itself properly', () => { it('should repair itself properly', () => {
g.repairDamage(function (c) { c.refresh(); }); g.repairDamage(function (c) { c.refresh(); });
expect(c.value).to.equal(124); assert.strictEqual(c.value, 124);
expect(d.value).to.equal(248); assert.strictEqual(d.value, 248);
}); });
}); });
@ -111,7 +111,9 @@ describe('dataflow', () => {
function expectValues(vs) { function expectValues(vs) {
g.repairDamage(function (c) { c.refresh(); }); g.repairDamage(function (c) { c.refresh(); });
expect([xs.value.toJS(), sum.value, len.value, avg.value, scale.value, ans.value]).to.eql(vs); assert.deepStrictEqual(
[xs.value.toJS(), sum.value, len.value, avg.value, scale.value, ans.value],
vs);
} }
it('initially', () => { it('initially', () => {
@ -157,52 +159,52 @@ describe('dataflow', () => {
it('should make rootward props visible further out', () => { it('should make rootward props visible further out', () => {
var ss = buildScopes(); var ss = buildScopes();
g.defineObservableProperty(ss.root, 'p', 123); g.defineObservableProperty(ss.root, 'p', 123);
expect(ss.root.p).to.equal(123); assert.strictEqual(ss.root.p, 123);
expect(ss.mid.p).to.equal(123); assert.strictEqual(ss.mid.p, 123);
expect(ss.outer.p).to.equal(123); assert.strictEqual(ss.outer.p, 123);
expect('p' in ss.root).to.equal(true); assert('p' in ss.root);
expect('p' in ss.mid).to.equal(true); assert('p' in ss.mid);
expect('p' in ss.outer).to.equal(true); assert('p' in ss.outer);
}); });
it('should make changes at root visible at leaves', () => { it('should make changes at root visible at leaves', () => {
var ss = buildScopes(); var ss = buildScopes();
g.defineObservableProperty(ss.root, 'p', 123); g.defineObservableProperty(ss.root, 'p', 123);
expect(ss.outer.p).to.equal(123); assert.strictEqual(ss.outer.p, 123);
ss.root.p = 234; ss.root.p = 234;
expect(ss.root.p).to.equal(234); assert.strictEqual(ss.root.p, 234);
expect(ss.outer.p).to.equal(234); assert.strictEqual(ss.outer.p, 234);
}); });
it('should make changes at leaves visible at root', () => { it('should make changes at leaves visible at root', () => {
var ss = buildScopes(); var ss = buildScopes();
g.defineObservableProperty(ss.root, 'p', 123); g.defineObservableProperty(ss.root, 'p', 123);
expect(ss.outer.p).to.equal(123); assert.strictEqual(ss.outer.p, 123);
ss.outer.p = 234; ss.outer.p = 234;
expect(ss.root.p).to.equal(234); assert.strictEqual(ss.root.p, 234);
expect(ss.outer.p).to.equal(234); assert.strictEqual(ss.outer.p, 234);
}); });
it('should hide definitions at leaves from roots', () => { it('should hide definitions at leaves from roots', () => {
var ss = buildScopes(); var ss = buildScopes();
g.defineObservableProperty(ss.outer, 'p', 123); g.defineObservableProperty(ss.outer, 'p', 123);
expect(ss.outer.p).to.equal(123); assert.strictEqual(ss.outer.p, 123);
expect(ss.mid.p).to.equal(undefined); assert.strictEqual(ss.mid.p, undefined);
expect(ss.root.p).to.equal(undefined); assert.strictEqual(ss.root.p, undefined);
expect('p' in ss.root).to.equal(false); assert(!('p' in ss.root));
expect('p' in ss.mid).to.equal(false); assert(!('p' in ss.mid));
expect('p' in ss.outer).to.equal(true); assert('p' in ss.outer);
}); });
it('should hide middle definitions from roots but show to leaves', () => { it('should hide middle definitions from roots but show to leaves', () => {
var ss = buildScopes(); var ss = buildScopes();
g.defineObservableProperty(ss.mid, 'p', 123); g.defineObservableProperty(ss.mid, 'p', 123);
expect(ss.outer.p).to.equal(123); assert.strictEqual(ss.outer.p, 123);
expect(ss.mid.p).to.equal(123); assert.strictEqual(ss.mid.p, 123);
expect(ss.root.p).to.equal(undefined); assert.strictEqual(ss.root.p, undefined);
expect('p' in ss.root).to.equal(false); assert(!('p' in ss.root));
expect('p' in ss.mid).to.equal(true); assert('p' in ss.mid);
expect('p' in ss.outer).to.equal(true); assert('p' in ss.outer);
}); });
}); });

View File

@ -17,10 +17,6 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
const chai = require('chai');
const expect = chai.expect;
chai.use(require('chai-immutable'));
const Immutable = require('immutable'); const Immutable = require('immutable');
const Syndicate = require('../src/index.js'); const Syndicate = require('../src/index.js');

View File

@ -17,11 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
const chai = require('chai'); const assert = require('assert');
const expect = chai.expect;
const assert = chai.assert;
chai.use(require('chai-immutable'));
const Immutable = require('immutable'); const Immutable = require('immutable');
const Syndicate = require('../src/index.js'); const Syndicate = require('../src/index.js');
@ -50,6 +46,10 @@ function _analyzeAssertion(a) {
return Skeleton.analyzeAssertion(Immutable.fromJS(a)); return Skeleton.analyzeAssertion(Immutable.fromJS(a));
} }
function assertImmutableEqual(a, b) {
assert(Immutable.is(Immutable.fromJS(a), Immutable.fromJS(b)));
}
describe('skeleton', () => { describe('skeleton', () => {
const A = Record.makeConstructor('A', ['x', 'y']); const A = Record.makeConstructor('A', ['x', 'y']);
@ -58,20 +58,20 @@ describe('skeleton', () => {
describe('pattern analysis', () => { describe('pattern analysis', () => {
it('should handle leaf captures', () => { it('should handle leaf captures', () => {
expect(Immutable.fromJS(_analyzeAssertion(A(B(_$), _$)))) assertImmutableEqual(_analyzeAssertion(A(B(_$), _$)),
.to.equal(Immutable.fromJS({assertion: Observe(A(B(_$), _$)), {assertion: Observe(A(B(_$), _$)),
skeleton: [A.constructorInfo, [B.constructorInfo, null], null], skeleton: [A.constructorInfo, [B.constructorInfo, null], null],
constPaths: Immutable.fromJS([]), constPaths: Immutable.fromJS([]),
constVals: Immutable.fromJS([]), constVals: Immutable.fromJS([]),
capturePaths: Immutable.fromJS([[0, 0], [1]])})); capturePaths: Immutable.fromJS([[0, 0], [1]])});
}); });
it('should handle atomic constants', () => { it('should handle atomic constants', () => {
expect(Immutable.fromJS(_analyzeAssertion(A(B("x"), _$)))) assertImmutableEqual(_analyzeAssertion(A(B("x"), _$)),
.to.equal(Immutable.fromJS({assertion: Observe(A(B("x"), _$)), {assertion: Observe(A(B("x"), _$)),
skeleton: [A.constructorInfo, [B.constructorInfo, null], null], skeleton: [A.constructorInfo, [B.constructorInfo, null], null],
constPaths: Immutable.fromJS([[0, 0]]), constPaths: Immutable.fromJS([[0, 0]]),
constVals: Immutable.fromJS(["x"]), constVals: Immutable.fromJS(["x"]),
capturePaths: Immutable.fromJS([[1]])})); capturePaths: Immutable.fromJS([[1]])});
}); });
it('should handle complex constants (1)', () => { it('should handle complex constants (1)', () => {
// Marker: (***) // Marker: (***)
@ -81,15 +81,15 @@ describe('skeleton', () => {
// that situation without the static analysis half of the code. // that situation without the static analysis half of the code.
// TODO later. // TODO later.
const complexPlaceholder = new Object(); const complexPlaceholder = new Object();
const analysis = Immutable.fromJS(_analyzeAssertion(A(complexPlaceholder, C(_$)))); const analysis = _analyzeAssertion(A(complexPlaceholder, C(_$)));
const expected = Immutable.fromJS({ const expected = {
assertion: Observe(A(complexPlaceholder, C(_$))), assertion: Observe(A(complexPlaceholder, C(_$))),
skeleton: [A.constructorInfo, null, [C.constructorInfo, null]], skeleton: [A.constructorInfo, null, [C.constructorInfo, null]],
constPaths: Immutable.fromJS([[0]]), constPaths: Immutable.fromJS([[0]]),
constVals: Immutable.fromJS([complexPlaceholder]), constVals: Immutable.fromJS([complexPlaceholder]),
capturePaths: Immutable.fromJS([[1, 0]]), capturePaths: Immutable.fromJS([[1, 0]]),
}); };
expect(analysis).to.equal(expected); assertImmutableEqual(analysis, expected);
}); });
it('should handle complex constants (2)', () => { it('should handle complex constants (2)', () => {
// Marker: (***) // Marker: (***)
@ -98,30 +98,30 @@ describe('skeleton', () => {
// will end up being complex at runtime. We can't properly test // will end up being complex at runtime. We can't properly test
// that situation without the static analysis half of the code. // that situation without the static analysis half of the code.
// TODO later. // TODO later.
expect(Immutable.fromJS(_analyzeAssertion(A(B(B("y")), Capture(C(__)))))) assertImmutableEqual(_analyzeAssertion(A(B(B("y")), Capture(C(__)))),
.to.equal(Immutable.fromJS({assertion: Observe(A(B(B("y")), Capture(C(__)))), {assertion: Observe(A(B(B("y")), Capture(C(__)))),
skeleton: [A.constructorInfo, skeleton: [A.constructorInfo,
[B.constructorInfo, [B.constructorInfo, null]], [B.constructorInfo, [B.constructorInfo, null]],
[C.constructorInfo, null]], [C.constructorInfo, null]],
constPaths: Immutable.fromJS([[0, 0, 0]]), constPaths: Immutable.fromJS([[0, 0, 0]]),
constVals: Immutable.fromJS(["y"]), constVals: Immutable.fromJS(["y"]),
capturePaths: Immutable.fromJS([[1]])})); capturePaths: Immutable.fromJS([[1]])});
}); });
it('should handle list patterns with discards', () => { it('should handle list patterns with discards', () => {
expect(Immutable.fromJS(_analyzeAssertion([__, __]))) assertImmutableEqual(_analyzeAssertion([__, __]),
.to.equal(Immutable.fromJS({assertion: Observe([__, __]), {assertion: Observe([__, __]),
skeleton: [2, null, null], skeleton: [2, null, null],
constPaths: Immutable.fromJS([]), constPaths: Immutable.fromJS([]),
constVals: Immutable.fromJS([]), constVals: Immutable.fromJS([]),
capturePaths: Immutable.fromJS([])})); capturePaths: Immutable.fromJS([])});
}); });
it('should handle list patterns with constants and captures', () => { it('should handle list patterns with constants and captures', () => {
expect(Immutable.fromJS(_analyzeAssertion(["hi", _$, _$]))) assertImmutableEqual(_analyzeAssertion(["hi", _$, _$]),
.to.equal(Immutable.fromJS({assertion: Observe(["hi", _$, _$]), {assertion: Observe(["hi", _$, _$]),
skeleton: [3, null, null, null], skeleton: [3, null, null, null],
constPaths: Immutable.fromJS([[0]]), constPaths: Immutable.fromJS([[0]]),
constVals: Immutable.fromJS(["hi"]), constVals: Immutable.fromJS(["hi"]),
capturePaths: Immutable.fromJS([[1],[2]])})); capturePaths: Immutable.fromJS([[1],[2]])});
}); });
}); });
@ -129,10 +129,11 @@ describe('skeleton', () => {
let trace = skeletonTrace((i, traceHolder) => { let trace = skeletonTrace((i, traceHolder) => {
i.addHandler(_analyzeAssertion(A(B(_$), _$)), eventCallback(traceHolder, "AB")); i.addHandler(_analyzeAssertion(A(B(_$), _$)), eventCallback(traceHolder, "AB"));
i.addHandler(_analyzeAssertion(A(B("x"), _$)), eventCallback(traceHolder, "ABx")); i.addHandler(_analyzeAssertion(A(B("x"), _$)), eventCallback(traceHolder, "ABx"));
let complexConstantPattern1 = {skeleton: [A.constructorInfo, null, [C.constructorInfo, null]], let complexConstantPattern1 =
constPaths: Immutable.fromJS([[0]]), {skeleton: [A.constructorInfo, null, [C.constructorInfo, null]],
constVals: Immutable.fromJS([B("y")]), constPaths: Immutable.fromJS([[0]]),
capturePaths: Immutable.fromJS([[1, 0]])}; constVals: Immutable.fromJS([B("y")]),
capturePaths: Immutable.fromJS([[1, 0]])};
// ^ See comment in 'should handle complex constants (1)' test above (marked (***)). // ^ See comment in 'should handle complex constants (1)' test above (marked (***)).
i.addHandler(complexConstantPattern1, eventCallback(traceHolder, "AByC")); i.addHandler(complexConstantPattern1, eventCallback(traceHolder, "AByC"));
let complexConstantPattern2 = {skeleton: [A.constructorInfo, let complexConstantPattern2 = {skeleton: [A.constructorInfo,
@ -151,15 +152,16 @@ describe('skeleton', () => {
// trace.forEach((e) => { console.log(e) }); // trace.forEach((e) => { console.log(e) });
expect(trace) it('should work', () => {
.to.equal(Immutable.List([ assertImmutableEqual(trace,
Event("AB", Skeleton.EVENT_ADDED, ["x", C(1)]), [Event("AB", Skeleton.EVENT_ADDED, ["x", C(1)]),
Event("ABx", Skeleton.EVENT_ADDED, [C(1)]), Event("ABx", Skeleton.EVENT_ADDED, [C(1)]),
Event("AB", Skeleton.EVENT_ADDED, ["y", C(2)]), Event("AB", Skeleton.EVENT_ADDED, ["y", C(2)]),
Event("AByC", Skeleton.EVENT_ADDED, [2]), Event("AByC", Skeleton.EVENT_ADDED, [2]),
Event("AB", Skeleton.EVENT_ADDED, [B("y"), C(2)]), Event("AB", Skeleton.EVENT_ADDED, [B("y"), C(2)]),
Event("ABByC", Skeleton.EVENT_ADDED, [C(2)]), Event("ABByC", Skeleton.EVENT_ADDED, [C(2)]),
Event("AB", Skeleton.EVENT_ADDED, ["z", C(3)])])); Event("AB", Skeleton.EVENT_ADDED, ["z", C(3)])]);
});
}); });
describe('simple detail-erasing trace', () => { describe('simple detail-erasing trace', () => {
@ -173,10 +175,9 @@ describe('skeleton', () => {
}); });
it('should have one add and one remove', () => { it('should have one add and one remove', () => {
expect(trace) assertImmutableEqual(trace,
.to.equal(Immutable.List([ [Event("2-EVENT", Skeleton.EVENT_ADDED, []),
Event("2-EVENT", Skeleton.EVENT_ADDED, []), Event("2-EVENT", Skeleton.EVENT_REMOVED, [])]);
Event("2-EVENT", Skeleton.EVENT_REMOVED, [])]));
}); });
}); });
@ -188,9 +189,9 @@ describe('skeleton', () => {
}); });
it('should get two events', () => { it('should get two events', () => {
expect(trace).to.equal(Immutable.List([ assertImmutableEqual(trace,
Event("X", Skeleton.EVENT_ADDED, [123, 234]), [Event("X", Skeleton.EVENT_ADDED, [123, 234]),
Event("X", Skeleton.EVENT_REMOVED, [123, 234])])); Event("X", Skeleton.EVENT_REMOVED, [123, 234])]);
}); });
}); });
@ -202,9 +203,9 @@ describe('skeleton', () => {
}); });
it('should get two events', () => { it('should get two events', () => {
expect(trace).to.equal(Immutable.List([ assertImmutableEqual(trace,
Event("X", Skeleton.EVENT_ADDED, [["hi", 123, 234]]), [Event("X", Skeleton.EVENT_ADDED, [["hi", 123, 234]]),
Event("X", Skeleton.EVENT_REMOVED, [["hi", 123, 234]])])); Event("X", Skeleton.EVENT_REMOVED, [["hi", 123, 234]])]);
}); });
}); });
@ -219,8 +220,8 @@ describe('skeleton', () => {
}); });
it('should get one event', () => { it('should get one event', () => {
expect(trace).to.equal(Immutable.List([ assertImmutableEqual(trace,
Event("X", Skeleton.EVENT_ADDED, [123, 234])])); [Event("X", Skeleton.EVENT_ADDED, [123, 234])]);
}); });
}); });
@ -247,91 +248,67 @@ describe('skeleton', () => {
}); });
it('should have 8 entries', () => { it('should have 8 entries', () => {
expect(trace.size).to.equal(8); assert.strictEqual(trace.size, 8);
}); });
it('should have a correct 3-EVENT subtrace', () => { it('should have a correct 3-EVENT subtrace', () => {
expect(trace.filter((e) => { return Event._label(e) === "3-EVENT"; })) assertImmutableEqual(trace.filter((e) => { return Event._label(e) === "3-EVENT"; }),
.to.equal(Immutable.List([ [Event("3-EVENT", Skeleton.EVENT_ADDED, [123, 234]),
Event("3-EVENT", Skeleton.EVENT_ADDED, [123, 234]), Event("3-EVENT", Skeleton.EVENT_ADDED, [999, 999]),
Event("3-EVENT", Skeleton.EVENT_ADDED, [999, 999]), Event("3-EVENT", Skeleton.EVENT_MESSAGE, [303, 404]),
Event("3-EVENT", Skeleton.EVENT_MESSAGE, [303, 404]), Event("3-EVENT", Skeleton.EVENT_REMOVED, [999, 999]),
Event("3-EVENT", Skeleton.EVENT_REMOVED, [999, 999]), Event("3-EVENT", Skeleton.EVENT_REMOVED, [123, 234])]);
Event("3-EVENT", Skeleton.EVENT_REMOVED, [123, 234])]));
}); });
it('should have a correct 2-EVENT subtrace', () => { it('should have a correct 2-EVENT subtrace', () => {
expect(trace.filter((e) => { return Event._label(e) === "2-EVENT"; })) assertImmutableEqual(trace.filter((e) => { return Event._label(e) === "2-EVENT"; }),
.to.equal(Immutable.List([ [Event("2-EVENT", Skeleton.EVENT_ADDED, []),
Event("2-EVENT", Skeleton.EVENT_ADDED, []), Event("2-EVENT", Skeleton.EVENT_MESSAGE, []),
Event("2-EVENT", Skeleton.EVENT_MESSAGE, []), Event("2-EVENT", Skeleton.EVENT_REMOVED, [])]);
Event("2-EVENT", Skeleton.EVENT_REMOVED, [])]));
}); });
}); });
function expectMatch(a, b, r) {
assert(Immutable.is(Skeleton.match(Immutable.fromJS(a), Immutable.fromJS(b)), r));
}
describe('matching a single pattern against a value', () => { describe('matching a single pattern against a value', () => {
it('should accept matching simple records', () => { it('should accept matching simple records', () => {
expect(Skeleton.match(Immutable.fromJS(A(1, 2)), expectMatch(A(1, 2), A(1, 2), Immutable.List());
Immutable.fromJS(A(1, 2))))
.to.equal(Immutable.List());
}); });
it('should capture from matching simple records', () => { it('should capture from matching simple records', () => {
expect(Skeleton.match(Immutable.fromJS(A(1, _$)), expectMatch(A(1, _$), A(1, 2), Immutable.List([2]));
Immutable.fromJS(A(1, 2))))
.to.equal(Immutable.List([2]));
}); });
it('should reject mismatching simple records', () => { it('should reject mismatching simple records', () => {
expect(Skeleton.match(Immutable.fromJS(A(1, 2)), expectMatch(A(1, 2), A(1, "hi"), false);
Immutable.fromJS(A(1, "hi"))))
.to.equal(false);
}); });
it('should accept matching simple lists', () => { it('should accept matching simple lists', () => {
expect(Skeleton.match(Immutable.fromJS([1, 2, 3]), expectMatch([1, 2, 3], [1, 2, 3], Immutable.List());
Immutable.fromJS([1, 2, 3])))
.to.equal(Immutable.List());
}); });
it('should accept matching nested lists', () => { it('should accept matching nested lists', () => {
expect(Skeleton.match(Immutable.fromJS([1, [2, 4], 3]), expectMatch([1, [2, 4], 3], [1, [2, 4], 3], Immutable.List());
Immutable.fromJS([1, [2, 4], 3])))
.to.equal(Immutable.List());
}); });
it('should capture matches from simple lists', () => { it('should capture matches from simple lists', () => {
expect(Skeleton.match(Immutable.fromJS([1, Capture(2), 3]), expectMatch([1, Capture(2), 3], [1, 2, 3], Immutable.List([2]));
Immutable.fromJS([1, 2, 3])))
.to.equal(Immutable.List([2]));
}); });
it('should capture discards from simple lists', () => { it('should capture discards from simple lists', () => {
expect(Skeleton.match(Immutable.fromJS([1, Capture(__), 3]), expectMatch([1, Capture(__), 3], [1, 2, 3], Immutable.List([2]));
Immutable.fromJS([1, 2, 3])))
.to.equal(Immutable.List([2]));
}); });
it('should capture discards from nested lists', () => { it('should capture discards from nested lists', () => {
expect(Skeleton.match(Immutable.fromJS([1, Capture(__), 3]), expectMatch([1, Capture(__), 3], [1, [2, 4], 3], Immutable.fromJS([[2, 4]]));
Immutable.fromJS([1, [2, 4], 3])))
.to.equal(Immutable.fromJS([[2, 4]]));
}); });
it('should capture nested discards from nested lists', () => { it('should capture nested discards from nested lists', () => {
expect(Skeleton.match(Immutable.fromJS([1, Capture([__, 4]), 3]), expectMatch([1, Capture([__, 4]), 3], [1, [2, 4], 3], Immutable.fromJS([[2, 4]]));
Immutable.fromJS([1, [2, 4], 3])))
.to.equal(Immutable.fromJS([[2, 4]]));
}); });
it('should reject nested mismatches from nested lists', () => { it('should reject nested mismatches from nested lists', () => {
expect(Skeleton.match(Immutable.fromJS([1, Capture([__, 5]), 3]), expectMatch([1, Capture([__, 5]), 3], [1, [2, 4], 3], false);
Immutable.fromJS([1, [2, 4], 3])))
.to.equal(false);
}); });
it('should reject mismatching captures from simple lists', () => { it('should reject mismatching captures from simple lists', () => {
expect(Skeleton.match(Immutable.fromJS([1, Capture(9), 3]), expectMatch([1, Capture(9), 3], [1, 2, 3], false);
Immutable.fromJS([1, 2, 3])))
.to.equal(false);
}); });
it('should reject simple lists varying in arity', () => { it('should reject simple lists varying in arity', () => {
expect(Skeleton.match(Immutable.fromJS([1, 2, 3, 4]), expectMatch([1, 2, 3, 4], [1, 2, 3], false);
Immutable.fromJS([1, 2, 3])))
.to.equal(false);
}); });
it('should reject simple lists varying in order', () => { it('should reject simple lists varying in order', () => {
expect(Skeleton.match(Immutable.fromJS([1, 3, 2]), expectMatch([1, 3, 2], [1, 2, 3], false);
Immutable.fromJS([1, 2, 3])))
.to.equal(false);
}); });
}); });
}); });