From 06327788846ae54467bdc74a45089631205786d1 Mon Sep 17 00:00:00 2001 From: Tobie Langel Date: Sun, 14 Oct 2007 11:35:59 +0000 Subject: [PATCH] Add more tests to Hash. --- CHANGELOG | 2 ++ test/unit/hash.html | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 79b0dea..20a2e7e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Add more tests to Hash. [Mislav Marohnić] + * Performance enhancements to $A. Closes #9464. [Samuel Lebeau] * Make Function#argumentNames work with named functions. Closes #9826. [Samuel Lebeau] diff --git a/test/unit/hash.html b/test/unit/hash.html index 9d2d186..7c283e8 100644 --- a/test/unit/hash.html +++ b/test/unit/hash.html @@ -54,7 +54,7 @@ }; new Test.Unit.Runner({ - testSet: function(){ with(this) { + testSet: function(){ with(this) { var h = $H({a: 'A'}) assertEqual('B', h.set('b', 'B')); @@ -65,16 +65,21 @@ }}, testGet: function(){ with(this) { - assertEqual('A', $H({a: 'A'}).get('a')); + var h = $H({a: 'A'}); + assertEqual('A', h.get('a')); + assertUndefined(h.a); assertUndefined($H({}).get('a')); }}, - testUnset: function(){ with(this) { + testUnset: function(){ with(this) { var hash = $H(Fixtures.many); assertEqual('B', hash.unset('b')); assertHashEqual({a:'A', c: 'C', d:'D#'}, hash); assertUndefined(hash.unset('z')); assertHashEqual({a:'A', c: 'C', d:'D#'}, hash); + // not equivalent to Hash#remove + assertEqual('A', hash.unset('a', 'c')); + assertHashEqual({c: 'C', d:'D#'}, hash); }}, testToObject: function(){ with(this) { @@ -194,7 +199,15 @@ testToJSON: function(){ with(this) { assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}', $H({'b': [undefined, false, true, undefined], c: {a: 'hello!'}}).toJSON()); + }}, + + testAbilityToContainAnyKey: function(){ with(this) { + var h = $H({ _each: 'E', map: 'M', keys: 'K', pluck: 'P', unset: 'U' }); + assertEnumEqual($w('_each keys map pluck unset'), h.keys().sort()); + assertEqual('U', h.unset('unset')); + assertHashEqual({ _each: 'E', map: 'M', keys: 'K', pluck: 'P' }, h); }} + }, 'testlog'); // ]]>