Fix RecordConstructorInfo.equals
This commit is contained in:
parent
5ab78e8281
commit
48b800a7ce
|
@ -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",
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
@ -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', () => {
|
||||
|
|
Loading…
Reference in New Issue