Permalink
Browse files

Merge pull request #1 from ejeklint/master

set() didn't work and test.js wasn't testing set() properly
  • Loading branch information...
2 parents 8f818ef + 26f85e4 commit e6877cfc11b08a5a8157c3244199d78ced56c76a @janl committed Jul 14, 2011
Showing with 13 additions and 12 deletions.
  1. +2 −2 jsonpointer.js
  2. +11 −10 test.js
View
@@ -17,7 +17,7 @@ var traverse = function(obj, pointer, value) {
return obj[part];
}
} else { // keep traversin!
- return traverse(obj[part], pointer);
+ return traverse(obj[part], pointer, value);
}
} else {
throw("Value for pointer '" + pointer + "' not found.");
@@ -43,7 +43,7 @@ var get = function(obj, pointer) {
var set = function(obj, pointer, value) {
validate_input(obj, pointer);
pointer = pointer.split("/").slice(1);
- return traverse(obj, pointer);
+ return traverse(obj, pointer, value);
}
exports.get = get
View
21 test.js
@@ -18,16 +18,17 @@ assert.equal(jsonpointer.get(obj, "/d/e/0/a"), 3);
assert.equal(jsonpointer.get(obj, "/d/e/1/b"), 4);
assert.equal(jsonpointer.get(obj, "/d/e/2/c"), 5);
-assert.equal(jsonpointer.set(obj, "/a"), 1);
-assert.equal(jsonpointer.set(obj, "/b/c"), 2);
-assert.equal(jsonpointer.set(obj, "/d/e/0/a"), 3);
-assert.equal(jsonpointer.set(obj, "/d/e/1/b"), 4);
-assert.equal(jsonpointer.set(obj, "/d/e/2/c"), 5);
+// set returns old value
+assert.equal(jsonpointer.set(obj, "/a", 2), 1);
+assert.equal(jsonpointer.set(obj, "/b/c", 3), 2);
+assert.equal(jsonpointer.set(obj, "/d/e/0/a", 4), 3);
+assert.equal(jsonpointer.set(obj, "/d/e/1/b", 5), 4);
+assert.equal(jsonpointer.set(obj, "/d/e/2/c", 6), 5);
-assert.equal(jsonpointer.get(obj, "/a"), 1);
-assert.equal(jsonpointer.get(obj, "/b/c"), 2);
-assert.equal(jsonpointer.get(obj, "/d/e/0/a"), 3);
-assert.equal(jsonpointer.get(obj, "/d/e/1/b"), 4);
-assert.equal(jsonpointer.get(obj, "/d/e/2/c"), 5);
+assert.equal(jsonpointer.get(obj, "/a"), 2);
+assert.equal(jsonpointer.get(obj, "/b/c"), 3);
+assert.equal(jsonpointer.get(obj, "/d/e/0/a"), 4);
+assert.equal(jsonpointer.get(obj, "/d/e/1/b"), 5);
+assert.equal(jsonpointer.get(obj, "/d/e/2/c"), 6);
console.log("All tests pass.");

0 comments on commit e6877cf

Please sign in to comment.