Test structs in skeletons; small resulting fixes
This commit is contained in:
parent
925ebb7bea
commit
b8c967f941
|
@ -46,7 +46,7 @@ function classOf(v) {
|
||||||
} else if (v instanceof Immutable.List) {
|
} else if (v instanceof Immutable.List) {
|
||||||
return v.size;
|
return v.size;
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Assertion contains unsupported data type: " + v.toString());
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,7 @@ Structure.prototype.equals = function (other) {
|
||||||
if (!other.meta.equals(this.meta)) return false;
|
if (!other.meta.equals(this.meta)) return false;
|
||||||
for (let i = 0; i < this.length; i++) {
|
for (let i = 0; i < this.length; i++) {
|
||||||
if (this[i] === other[i]) continue;
|
if (this[i] === other[i]) continue;
|
||||||
|
if (typeof this[i].equals !== 'function') return false;
|
||||||
if (!this[i].equals(other[i])) return false;
|
if (!this[i].equals(other[i])) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -13,13 +13,14 @@ const Struct = Syndicate.Struct;
|
||||||
const Event = Struct.makeConstructor('Event', ['label', 'type', 'values']);
|
const Event = Struct.makeConstructor('Event', ['label', 'type', 'values']);
|
||||||
|
|
||||||
function eventCallback(traceHolder, label) {
|
function eventCallback(traceHolder, label) {
|
||||||
return (e, vs) => {
|
return (e, vs) => { traceHolder.push(Event(label, e, vs)) };
|
||||||
traceHolder.trace = traceHolder.trace.push(Event(label, e, vs));
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function skeletonTrace(f) {
|
function skeletonTrace(f) {
|
||||||
let traceHolder = {trace: Immutable.List()};
|
let traceHolder = {
|
||||||
|
trace: Immutable.List(),
|
||||||
|
push: function (e) { this.trace = this.trace.push(e); }
|
||||||
|
};
|
||||||
let i = new Skeleton.Index();
|
let i = new Skeleton.Index();
|
||||||
f(i, traceHolder);
|
f(i, traceHolder);
|
||||||
return traceHolder.trace;
|
return traceHolder.trace;
|
||||||
|
@ -31,6 +32,48 @@ describe('skeleton tests', () => {
|
||||||
const B = Struct.makeConstructor('B', ['v']);
|
const B = Struct.makeConstructor('B', ['v']);
|
||||||
const C = Struct.makeConstructor('C', ['v']);
|
const C = Struct.makeConstructor('C', ['v']);
|
||||||
|
|
||||||
|
describe('nested structs', () => {
|
||||||
|
let trace = skeletonTrace((i, traceHolder) => {
|
||||||
|
i.addHandler([A.meta, [B.meta, null], null],
|
||||||
|
Immutable.fromJS([]),
|
||||||
|
Immutable.fromJS([]),
|
||||||
|
Immutable.fromJS([[0, 0], [1]]),
|
||||||
|
eventCallback(traceHolder, "AB"));
|
||||||
|
i.addHandler([A.meta, [B.meta, null], null],
|
||||||
|
Immutable.fromJS([[0, 0]]),
|
||||||
|
Immutable.fromJS(["x"]),
|
||||||
|
Immutable.fromJS([[1]]),
|
||||||
|
eventCallback(traceHolder, "ABx"));
|
||||||
|
i.addHandler([A.meta, null, [C.meta, null]],
|
||||||
|
Immutable.fromJS([[0]]),
|
||||||
|
Immutable.fromJS([B("y")]),
|
||||||
|
Immutable.fromJS([[1, 0]]),
|
||||||
|
eventCallback(traceHolder, "AByC"));
|
||||||
|
i.addHandler([A.meta, [B.meta, null], [C.meta, null]],
|
||||||
|
Immutable.fromJS([[0, 0]]),
|
||||||
|
Immutable.fromJS([B("y")]),
|
||||||
|
Immutable.fromJS([[1]]),
|
||||||
|
eventCallback(traceHolder, "ABByC"));
|
||||||
|
|
||||||
|
i.addAssertion(A(B("x"),C(1)));
|
||||||
|
i.addAssertion(A(B("y"),C(2)));
|
||||||
|
i.addAssertion(A(B(B("y")),C(2)));
|
||||||
|
i.addAssertion(A(B("z"),C(3)));
|
||||||
|
});
|
||||||
|
|
||||||
|
// trace.forEach((e) => { console.log(e.toString()) });
|
||||||
|
|
||||||
|
expect(trace)
|
||||||
|
.to.equal(Immutable.List([
|
||||||
|
Event("AB", Skeleton.EVENT_ADDED, ["x", C(1)]),
|
||||||
|
Event("ABx", Skeleton.EVENT_ADDED, [C(1)]),
|
||||||
|
Event("AB", Skeleton.EVENT_ADDED, ["y", C(2)]),
|
||||||
|
Event("AByC", Skeleton.EVENT_ADDED, [2]),
|
||||||
|
Event("AB", Skeleton.EVENT_ADDED, [B("y"), C(2)]),
|
||||||
|
Event("ABByC", Skeleton.EVENT_ADDED, [C(2)]),
|
||||||
|
Event("AB", Skeleton.EVENT_ADDED, ["z", C(3)])]));
|
||||||
|
});
|
||||||
|
|
||||||
describe('simple detail-erasing trace', () => {
|
describe('simple detail-erasing trace', () => {
|
||||||
let trace = skeletonTrace((i, traceHolder) => {
|
let trace = skeletonTrace((i, traceHolder) => {
|
||||||
i.addHandler([2, null, null],
|
i.addHandler([2, null, null],
|
||||||
|
@ -102,7 +145,6 @@ describe('skeleton tests', () => {
|
||||||
Event("2-EVENT", Skeleton.EVENT_MESSAGE, []),
|
Event("2-EVENT", Skeleton.EVENT_MESSAGE, []),
|
||||||
Event("2-EVENT", Skeleton.EVENT_REMOVED, [])]));
|
Event("2-EVENT", Skeleton.EVENT_REMOVED, [])]));
|
||||||
});
|
});
|
||||||
// trace.forEach((e) => { console.log(e.toString()) });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue