Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

set() didn't work and test.js wasn't testing set() properly #1

Merged
merged 1 commit into from

2 participants

@ejeklint

set() wasn't called with value in test, nor was set calling traverse() with value, nor was recursive call of traverse called with value. Now it is.

@ejeklint ejeklint set now works
set() wasn't called with value in test, nor was set calling traverse() with value, nor was recursive call of traverse called with value. Now it is.
26f85e4
@janl janl merged commit e6877cf into janl:master
@janl
Owner

Tee hee :)

@ejeklint

Wohoo, celebrating my first github pull request! :D

@janl
Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 14, 2011
  1. @ejeklint

    set now works

    ejeklint authored
    set() wasn't called with value in test, nor was set calling traverse() with value, nor was recursive call of traverse called with value. Now it is.
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 12 deletions.
  1. +2 −2 jsonpointer.js
  2. +11 −10 test.js
View
4 jsonpointer.js
@@ -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.");
Something went wrong with that request. Please try again.