Mercurial > browser-couch
changeset 13:07e8dc256570
Added unit tests for Dictionary and fixed a bug or two in the Dictionary's implementation.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Fri, 10 Apr 2009 14:41:22 -0700 |
parents | 9ed45c82a731 |
children | fbee4473dbdd |
files | browser-couch.js tests.js |
diffstat | 2 files changed, 15 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/browser-couch.js Fri Apr 10 14:29:26 2009 -0700 +++ b/browser-couch.js Fri Apr 10 14:41:22 2009 -0700 @@ -116,11 +116,7 @@ }; this.get = function Dictionary_get(key) { - var index = keyIndex[key]; - if (index) - return keysAndValues[index][1]; - else - throw new Error("key not in dictionary: " + key); + return keysAndValues[keyIndex[key]][1]; }; this.set = function Dictionary_set(key, value) {
--- a/tests.js Fri Apr 10 14:29:26 2009 -0700 +++ b/tests.js Fri Apr 10 14:41:22 2009 -0700 @@ -43,7 +43,20 @@ runNextTest(); }, - testBasic_async: function(self) { + testDictionary: function(self) { + var dict = new BrowserCouch._Dictionary(); + dict.set('foo', {a: 'hello'}); + dict.set('bar', {b: 'goodbye'}); + self.assertEqual(dict.get('foo').a, 'hello'); + self.assertEqual(dict.get('bar').b, 'goodbye'); + self.assertEqual(dict.getNthValue(0).b, 'goodbye'); + self.assertEqual(dict.getNthValue(1).a, 'hello'); + self.assertEqual(dict.getLength(), 2); + self.assertEqual(dict.has('foo'), true); + self.assertEqual(dict.has('bar'), true); + self.assertEqual(dict.has('spatula'), false); + }, + testDbView_async: function(self) { BrowserCouch.get( "blarg", function(db) {