diff options
author | Chad Austin <caustin@gmail.com> | 2014-05-02 02:52:02 -0700 |
---|---|---|
committer | Bruce Mitchener <bruce.mitchener@gmail.com> | 2014-05-21 22:53:54 +0700 |
commit | e87094f40709d68dcb56e6576cf1a3b82b758d80 (patch) | |
tree | 3797fb759736be5cd76c41568106b1848d2e56e1 | |
parent | 8ae137e8663b82f1fb41dd65deb76c8efd627641 (diff) |
write a bunch of unit tests for the desired javascript inheritance api
-rw-r--r-- | tests/embind/embind.test.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js index 53d3988a..258cb404 100644 --- a/tests/embind/embind.test.js +++ b/tests/embind/embind.test.js @@ -1640,6 +1640,75 @@ module({ }); }); + /* ENABLE THESE AS THEY PASS + BaseFixture.extend("new-style class inheritance", function() { + var Empty = cm.AbstractClass.extend({}); + + test("can extend, construct, and delete", function() { + var instance = new Empty; + instance.delete(); + }); + + test("properties set in constructor are externally visible", function() { + var HasProperty = cm.AbstractClass.extend({ + initialize: function(x) { + this.property = x; + } + }); + var instance = new HasProperty(10); + assert.equal(10, instance.set_property); + instance.delete(); + }); + + test("pass derived object to c++", function() { + var Implementation = cm.AbstractClass.extend({ + abstractMethod: function() { + return "abc"; + }, + }); + var instance = new Implementation; + var result = cm.callAbstractMethod(instance); + instance.delete(); + assert.equal("abc", result); + }); + + test("properties set in constructor are visible in overridden methods", function() { + var HasProperty = cm.AbstractClass.extend({ + initialize: function(x) { + this.x = x; + }, + abstractMethod: function() { + return this.x; + }, + }); + var instance = new HasProperty("xyz"); + var result = cm.callAbstractMethod(instance); + instance.delete(); + assert.equal("xyz", result); + }); + + test("interface methods are externally visible", function() { + var instance = new Empty; + var result = cm.callOptionalMethod(instance, "_123"); + instance.delete(); + assert.equal("optional_123", result); + }); + + test("can call parent implementation from within derived implementation", function() { + var parent = cm.AbstractClass; + var ExtendsOptionalMethod = parent.extend({ + optionalMethod: function(s) { + return "optionaljs_" + parent.prototype.optionalMethod.call(this, s); + }, + }); + var instance = new ExtendsOptionalMethod; + var result = cm.callOptionalMethod(instance, "_123"); + instance.delete(); + assert.equal("optionaljs_optional_123", result); + }); + }); + */ + BaseFixture.extend("registration order", function() { test("registration of tuple elements out of order leaves them in order", function() { var ot = cm.getOrderedTuple(); |