Skip to content

Commit

Permalink
Add empty list / record optimisation tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gozala committed Jul 10, 2015
1 parent 300ac71 commit 2c6e350
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ test("can update sub-records", assert => {
assert.ok(l5.password.isFocused === false)
})


test("can use instances as fields", assert => {
const Field = Record({isFocused: false,
value: ""})
Expand All @@ -452,12 +453,18 @@ test("can use instances as fields", assert => {

const l1 = Login()

assert.ok(l1.user instanceof Field)
assert.ok(l1.password instanceof Field)
assert.ok(l1.user.value === "")
assert.ok(l1.user.isFocused === true)
assert.ok(l1.password.value === "")
assert.ok(l1.password.isFocused === false)
assert.ok(l1.user instanceof Field,
'l1.user is Field instance')
assert.ok(l1.password instanceof Field,
'l1.password is Field instance')
assert.ok(l1.user.value === "",
'l1.user.value is ""')
assert.ok(l1.user.isFocused === true,
'l1.user.isFocused is true')
assert.ok(l1.password.value === "",
'l1.password.value is ""')
assert.ok(l1.password.isFocused === false,
'l1.password.isFocused is false')

const l2 = Login({user: {isFocused: false, value: "gozala"},
password: {isFocused: true}})
Expand Down
11 changes: 11 additions & 0 deletions src/test/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -974,3 +974,14 @@ test('identity preserved on no redundunt changes', assert => {
assert.equal(ps.mergeIn([2], {y: 5}), ps)
assert.equal(ps.mergeIn([2], {x: 3, y: 5}), ps)
})

test('empty list optimization', assert => {
assert.equal(Points(), Points())
assert.equal(Points(void(0)), Points())
assert.equal(Points(null), Points())
assert.equal(Points([]), Points())
assert.notEqual(Points([Point({x: 1})]), Points())
assert.equal(Points([Point({x: 1})]).clear(), Points())
assert.equal(Points([Point({x: 1})]).clear(),
Points([Point({x: 1}), Point({y: 2})]).clear())
})
15 changes: 15 additions & 0 deletions src/test/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,18 @@ test("identical no change in deep updates", assert => {

assert.equal(l1, l1.update('start', p => p.set('x', 5)))
})


test('empty record optimization', assert => {
const Point = Record({x: 0, y: 0}, 'Point')

assert.equal(Point(), Point())
assert.notEqual(Point({x: 1}), Point())
assert.equal(Point({x: 1}).clear(), Point())
assert.equal(Point({x: 1}).clear(), Point({y: 2}).clear())
assert.equal(Point({}), Point())
assert.notEqual(Point({z: 3}), Point())
assert.ok(Point({z: 3}).equals(Point()))
assert.notEqual(Point({x:0}), Point())
assert.ok(Point({x: 0}).equals(Point()))
});

0 comments on commit 2c6e350

Please sign in to comment.