Fix RecordConstructorInfo.equals

This commit is contained in:
Tony Garnock-Jones 2019-06-13 23:04:09 +01:00
parent 5ab78e8281
commit 48b800a7ce
3 changed files with 17 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "preserves",
"version": "0.0.10",
"version": "0.0.11",
"description": "Experimental data serialization format",
"homepage": "https://gitlab.com/tonyg/preserves",
"license": "MIT",

View File

@ -396,7 +396,7 @@ function RecordConstructorInfo(label, arity) {
RecordConstructorInfo.prototype.equals = function (other) {
return (other instanceof RecordConstructorInfo) &&
(this.label === other.label) &&
is(this.label, other.label) &&
(this.arity === other.arity);
};

View File

@ -31,6 +31,21 @@ describe('record constructors', () => {
expect(Capture.constructorInfo.arity).to.equal(1);
expect(Observe.constructorInfo.arity).to.equal(1);
});
})
describe('RecordConstructorInfo', () => {
const C1 = Record.makeBasicConstructor(Immutable.List([1]), ['x', 'y']);
const C2 = Record.makeBasicConstructor(Immutable.List([1]), ['z', 'w']);
it('instance comparison should ignore pointer and fieldname differences', () => {
expect(is(C1(9,9), C2(9,9))).to.be.true;
expect(is(C1(9,9), C2(9,8))).to.be.false;
});
it('comparison based on pointer equality should not work', () => {
expect(C1.constructorInfo === C2.constructorInfo).to.be.false;
});
it('comparison based on .equals should work', () => {
expect(is(C1.constructorInfo, C2.constructorInfo)).to.be.true;
});
});
describe('records', () => {