From 7eba4bf7e9c4aa4fbb80c4354191e8d26536e57b Mon Sep 17 00:00:00 2001 From: Dima Granetchi Date: Sat, 15 Nov 2014 15:21:11 +0200 Subject: [PATCH] inheritance tests --- src/bindx/Bind.hx | 13 +++++----- test/InheritanceTest.hx | 55 ++++++++++++++++++++++------------------- test/SignalTest.hx | 2 +- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/bindx/Bind.hx b/src/bindx/Bind.hx index ec2e52e..c42480e 100644 --- a/src/bindx/Bind.hx +++ b/src/bindx/Bind.hx @@ -32,7 +32,7 @@ class Bind { @:noUsing macro static public function unbindAll(object:ExprOf):Expr { return internalUnbindAll(object); - } + } #if macro @@ -94,13 +94,14 @@ class Bind { } public static function isBindable(classType:ClassType):Bool { + if (classType.module == "bindx.IBindable" && classType.name == "IBindable") + return true; + var t = classType; while (t != null) { - for (it in t.interfaces) { - var t = it.t.get(); - if (t.module == "bindx.IBindable" && t.name == "IBindable") - return true; - } + for (it in t.interfaces) + if (isBindable(it.t.get())) + return true; t = t.superClass != null ? t.superClass.t.get() : null; } return false; diff --git a/test/InheritanceTest.hx b/test/InheritanceTest.hx index c710b16..aa2616d 100644 --- a/test/InheritanceTest.hx +++ b/test/InheritanceTest.hx @@ -9,38 +9,43 @@ using buddy.Should; class InheritanceTest extends BuddySuite { public function new() { super(); - + describe("Using classes inheritance", { - it("bindx should support class inheritance"); + var b:BindableChild; + var bp:BindableParent; + var callNum:Int; + + before({ + b = new BindableChild(); + bp = new BindableParent(); + callNum = 0; + }); + + it("bindx should support class/interface inheritance", { + b.i = 1; + b.s = "a"; + Bind.bind(b.i, function (_, _) callNum++); + Bind.bind(b.s, function (_, _) callNum++); + + b.i = 2; + b.s = "b"; + callNum.should.be(2); + + bp.i = 1; + Bind.bind(bp.i, function (_, _) callNum++); + bp.i = 2; + callNum.should.be(3); + }); }); } - /* - function testChild() { - var c = new BindableChild(); - c.i = 0; - c.s = "0"; - var iChanged = 0; - Bind.bind(c.i, function (from, to) { - assertEquals(from, 0); - assertEquals(to, 1); - iChanged ++; - }); - c.i = 1; - assertEquals(iChanged, 1); +} - var sChanged = 0; - Bind.bind(c.s, function (from, to) { - assertEquals(from, "0"); - assertEquals(to, "1"); - sChanged ++; - }); - c.s = "1"; - assertEquals(sChanged, 1); - }*/ +interface IIBindable extends IBindable { + } @:bindable -class BindableParent implements IBindable { +class BindableParent implements IIBindable { public function new() {} public var i:Int; diff --git a/test/SignalTest.hx b/test/SignalTest.hx index 357cbb2..db7056c 100644 --- a/test/SignalTest.hx +++ b/test/SignalTest.hx @@ -97,7 +97,7 @@ class SignalTest extends BuddySuite { }); }); - describe("MethodSignal functionality tests", { + describe("Using MethodSignal", { var ms:MethodSignal; var callNum:Int;