|
580 | 580 | });
|
581 | 581 | });
|
582 | 582 |
|
| 583 | + describe('regression test for issue #141', function() { |
| 584 | + var changeFail = { kind: 'E', path: ['foo'], lhs: true, rhs: false }; |
| 585 | + var changeSucceed = { kind: 'E', path: ['foo'], lhs: 1, rhs: 3 }; |
| 586 | + |
| 587 | + var revertLHSFalsey = { kind: 'E', path: ['foo'], lhs: -1, rhs: 1 }; |
| 588 | + var revertBothFalsey = { kind: 'E', path: ['foo'], lhs: -1, rhs: -3 }; |
| 589 | + var revertLHSTruthy = { kind: 'E', path: ['foo'], lhs: 1, rhs: 3 }; |
| 590 | + var revertBothTruthy = { kind: 'E', path: ['foo'], lhs: 1, rhs: 3 }; |
| 591 | + |
| 592 | + it('applies changes correctly when the new value is truthy', function() { |
| 593 | + var target = { foo: changeSucceed.lhs }; |
| 594 | + deep.applyChange(target, changeSucceed); |
| 595 | + expect(target.foo).to.equal(changeSucceed.rhs); |
| 596 | + }); |
| 597 | + |
| 598 | + it('applies changes correctly when the new value is falsey', function() { |
| 599 | + var target = { foo: changeFail.lhs }; |
| 600 | + deep.applyChange(target, changeFail); |
| 601 | + expect(target.foo).to.equal(changeFail.rhs); |
| 602 | + }); |
| 603 | + |
| 604 | + it('reverts changes correctly when both values are truthy', function() { |
| 605 | + var target = { foo: 'hello' }; |
| 606 | + deep.revertChange(target, revertBothTruthy); |
| 607 | + expect(target.foo).to.equal(revertBothTruthy.lhs); |
| 608 | + }); |
| 609 | + |
| 610 | + it('reverts changes correctly when both values are falsey', function() { |
| 611 | + var target = { foo: 'hello' }; |
| 612 | + deep.revertChange(target, revertBothFalsey); |
| 613 | + expect(target.foo).to.equal(revertBothFalsey.lhs); |
| 614 | + }); |
| 615 | + |
| 616 | + it('reverts changes correctly when the new value is truthy', function() { |
| 617 | + var target = { foo: revertLHSTruthy.rhs }; |
| 618 | + deep.revertChange(target, revertLHSTruthy); |
| 619 | + expect(target.foo).to.equal(revertLHSTruthy.lhs); |
| 620 | + }); |
| 621 | + |
| 622 | + it('reverts changes correctly when the new value is falsey', function() { |
| 623 | + var target = { foo: revertLHSFalsey.rhs }; |
| 624 | + deep.revertChange(target, revertLHSFalsey); |
| 625 | + expect(target.foo).to.equal(revertLHSFalsey.lhs); |
| 626 | + }); |
| 627 | + |
| 628 | + }); |
| 629 | + |
583 | 630 | describe('Order independent hash testing', function () {
|
584 | 631 | function sameHash(a, b) {
|
585 | 632 | expect(deep.orderIndepHash(a)).to.equal(deep.orderIndepHash(b));
|
|
0 commit comments