diff options
author | Chad Austin <chad@imvu.com> | 2013-04-09 18:01:15 -0700 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-18 20:08:05 +0300 |
commit | 17639c372a5f41177177c21c56731b103ad738ad (patch) | |
tree | 5f0e512d5824bf3581410af529461bc50b21ba76 /tests/embind/embind.test.js | |
parent | 927c8a5e44da6c5cc539fa7d4e0a2168dafa3d36 (diff) |
allow optional implementation of non-abstract virtual methods
Diffstat (limited to 'tests/embind/embind.test.js')
-rwxr-xr-x | tests/embind/embind.test.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js index 8155fd11..4a8665f4 100755 --- a/tests/embind/embind.test.js +++ b/tests/embind/embind.test.js @@ -1464,6 +1464,28 @@ module({ assert.equal(expected, cm.callAbstractMethod(impl)); impl.delete(); }); + + test("can implement optional methods in JavaScript", function() { + var expected = "my JS string"; + function MyImplementation() { + this.rv = expected; + } + MyImplementation.prototype.optionalMethod = function() { + return this.rv; + }; + + var impl = cm.AbstractClass.implement(new MyImplementation); + assert.equal(expected, impl.optionalMethod(expected)); + assert.equal(expected, cm.callOptionalMethod(impl, expected)); + impl.delete(); + }); + + test("if not implemented then optional method runs default", function() { + var impl = cm.AbstractClass.implement({}); + assert.equal("optionalfoo", impl.optionalMethod("foo")); + assert.equal("optionalfoo", cm.callOptionalMethod(impl, "foo")); + impl.delete(); + }); }); BaseFixture.extend("registration order", function() { |