Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added tests for issue #141 #144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,53 @@
});
});

describe('regression test for issue #141', function() {
var changeFail = { kind: 'E', path: ['foo'], lhs: true, rhs: false };
var changeSucceed = { kind: 'E', path: ['foo'], lhs: 1, rhs: 3 };

var revertLHSFalsey = { kind: 'E', path: ['foo'], lhs: -1, rhs: 1 };
var revertBothFalsey = { kind: 'E', path: ['foo'], lhs: -1, rhs: -3 };
var revertLHSTruthy = { kind: 'E', path: ['foo'], lhs: 1, rhs: 3 };
var revertBothTruthy = { kind: 'E', path: ['foo'], lhs: 1, rhs: 3 };

it('applies changes correctly when the new value is truthy', function() {
var target = { foo: changeSucceed.lhs };
deep.applyChange(target, changeSucceed);
expect(target.foo).to.equal(changeSucceed.rhs);
});

it('applies changes correctly when the new value is falsey', function() {
var target = { foo: changeFail.lhs };
deep.applyChange(target, changeFail);
expect(target.foo).to.equal(changeFail.rhs);
});

it('reverts changes correctly when both values are truthy', function() {
var target = { foo: 'hello' };
deep.revertChange(target, revertBothTruthy);
expect(target.foo).to.equal(revertBothTruthy.lhs);
});

it('reverts changes correctly when both values are falsey', function() {
var target = { foo: 'hello' };
deep.revertChange(target, revertBothFalsey);
expect(target.foo).to.equal(revertBothFalsey.lhs);
});

it('reverts changes correctly when the new value is truthy', function() {
var target = { foo: revertLHSTruthy.rhs };
deep.revertChange(target, revertLHSTruthy);
expect(target.foo).to.equal(revertLHSTruthy.lhs);
});

it('reverts changes correctly when the new value is falsey', function() {
var target = { foo: revertLHSFalsey.rhs };
deep.revertChange(target, revertLHSFalsey);
expect(target.foo).to.equal(revertLHSFalsey.lhs);
});

});

describe('Order independent hash testing', function () {
function sameHash(a, b) {
expect(deep.orderIndepHash(a)).to.equal(deep.orderIndepHash(b));
Expand Down