Permalink
Browse files

another test, and better semantics

  • Loading branch information...
James MacAulay
James MacAulay committed Feb 5, 2013
1 parent c6da5ed commit eb7428616983c58ee916396bf45fd10202d8f091
Showing with 12 additions and 6 deletions.
  1. +4 −4 src/hash/simple_hash.coffee
  2. +8 −2 tests/batman/hash_test.coffee
@@ -65,11 +65,11 @@ class Batman.SimpleHash
prefixedKey: (key) -> "_"+key
unprefixedKey: (key) -> key.slice(1)
hashKeyFor: (obj) ->
- typeString = _objectToString.call(obj)
- if typeString is "[object Array]"
- typeString
+ if hashKey = obj?.hashKey?()
+ hashKey
else
- obj?.hashKey?() or obj
+ typeString = _objectToString.call(obj)
+ if typeString is "[object Array]" then typeString else obj
equality: (lhs, rhs) ->
return true if lhs is rhs
return true if lhs isnt lhs and rhs isnt rhs # when both are NaN
@@ -466,6 +466,13 @@ test "replace(hash) works with other batman hashes as expected", ->
deepEqual @hash.toObject(), foo: 'otherFoo', baz: 'otherBaz'
+test "using mutating arrays as keys", ->
+ arr = []
+ @hash.set(arr, "array value")
+ arr.push(1)
+
+ strictEqual @hash.get(arr), "array value"
+
test "using arrays of Batman.Model objects with mutable IDs as keys", ->
class Product extends Batman.Model
@encode 'id'
@@ -477,5 +484,4 @@ test "using arrays of Batman.Model objects with mutable IDs as keys", ->
product.set('id', 5)
strictEqual @hash.get(arr), "array value"
-
-
+

0 comments on commit eb74286

Please sign in to comment.