Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Unified Diff: js/tests/object.js

Issue 1204793003: Add tests for sk.object functions and sk.stateReflector. (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | js/tests/stateReflector.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: js/tests/object.js
diff --git a/js/tests/object.js b/js/tests/object.js
new file mode 100644
index 0000000000000000000000000000000000000000..7d5a161adcb17ae3f3a50f17f003e9fd61ab16b5
--- /dev/null
+++ b/js/tests/object.js
@@ -0,0 +1,52 @@
+describe('sk.object functions',
+ function() {
+ function testGetDelta() {
+ var test = function(o, d, expected) {
+ assert.deepEqual(sk.object.getDelta(o, d), expected);
+ }
+ test({}, {}, {});
+ test({a: "foo"}, {a: "foo"}, {});
+ var first = {}; // Ensure getDelta does not modify its arguments.
+ test(first, {a: "foo"}, {});
+ assert.deepEqual(first, {});
+ var second = {}; // Ensure getDelta does not modify its arguments.
+ test({a: "foo"}, second, {a: "foo"});
+ assert.deepEqual(second, {});
+ test({a: "foo"}, {a: "bar"}, {a: "foo"});
+ test({a: "foo", b: "bar"}, {a: true, c: "bar"}, {a: "foo", b: "bar"});
+ test(["one", 2, 3.0], [1, "2", 3], {'0': "one"});
+ test({a: undefined, b: NaN, c: null}, {a: true, b: true, c: true},
+ {a: undefined, b: NaN, c: null});
+ test({a: undefined, b: NaN, c: false}, {a: null, b: null, c: null},
+ {b: NaN, c: false});
+ var noop = function () {};
+ test({a: test, b: noop}, {a: test, b: function () {}}, {b: noop});
+ }
+
+ function testApplyDelta() {
+ var test = function(delta, o, expected) {
+ assert.deepEqual(sk.object.applyDelta(delta, o), expected);
+ }
+ test({}, {}, {});
+ test({}, {a: "foo"}, {a: "foo"});
+ var first = {a: "bar"}; // Ensure applyDelta does not modify its arguments.
+ test(first, {a: "foo"}, {a: "bar"});
+ assert.deepEqual(first, {a: "bar"});
+ var second = {a: "bar"}; // Ensure applyDelta does not modify its arguments.
+ test({a: "foo"}, second, {a: "foo"});
+ assert.deepEqual(second, {a: "bar"});
+ test({a: "foo"}, {a: "bar", b: "baz"}, {a: "foo", b: "baz"});
+ test({a: "foo", b: "baz"}, {a: "bar"}, {a: "foo"});
+ test({a: "foo", b: "bar"}, {a: true, c: "bar"},
+ {a: "foo", c: "bar"});
+ test(["one"], [1, "2", 3], {'0': "one", '1': "2", '2': 3});
+ test({b: NaN, c: false}, {a: null, b: null, c: null},
+ {a: null, b: NaN, c: false});
+ }
+
+ it('should be able get differences and apply differences', function() {
+ testGetDelta();
+ testApplyDelta();
+ });
+ }
+);
« no previous file with comments | « no previous file | js/tests/stateReflector.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698