From 60cbdf0e6a22e20dcd8d609546c742be313ed953 Mon Sep 17 00:00:00 2001 From: Dima Granetchi Date: Thu, 13 Nov 2014 14:26:53 +0200 Subject: [PATCH] more tests --- test/BaseTest.hx | 37 +++++++++++++++++++++++++------------ test/SignalTest.hx | 18 ++++++++++++++++++ test/TestProperty.hx | 37 ++++++++++++++++++++++++++++++------- 3 files changed, 73 insertions(+), 19 deletions(-) create mode 100644 test/SignalTest.hx diff --git a/test/BaseTest.hx b/test/BaseTest.hx index ef5d872..1514f49 100644 --- a/test/BaseTest.hx +++ b/test/BaseTest.hx @@ -21,7 +21,7 @@ class BaseTest extends BuddySuite { callNum = 0; }); - it ("bindx should bind/unbind properties (lazySignal=true)", { + it ("bindx should bind/unbind fields (lazySignal=true)", { var strFrom = b.str = "a"; var callNum2 = 0; @@ -51,7 +51,7 @@ class BaseTest extends BuddySuite { callNum2.should.be(1); }); - it ("bindx should bind/unbind properties (lazySignal=false)", { + it ("bindx should bind/unbind fields (lazySignal=false)", { var strFrom = b.str2 = "a"; var callNum2 = 0; @@ -137,6 +137,9 @@ class BaseTest extends BuddySuite { callNum2.should.be(1); }); + it("bindx should bind 2 objects (lazySignal=true)"); + it("bindx should bind 2 objects (lazySignal=false)"); + it("bindx should bind and notify methods (lazySignal=true)", { var listener = function () callNum++; bind(b.bind, listener); @@ -217,16 +220,21 @@ class BaseTest extends BuddySuite { it("bindx should unbind all bindings (signal exists) (lazySignal=true/false)", { bind(b.str, function (_, _) callNum++); // create binding signal - bind(b.str2, function (_, _) callNum++); // create binding signal + bind(b.str2, function (_, _) callNum++); bind(b.bind, function () callNum++); bind(b.bind2, function () callNum++); Bind.unbindAll(b); - b.str = b.str + "1"; - b.str2 = b.str2 + "1"; - Bind.notify(b.bind); - Bind.notify(b.bind2); + try { + b.str = b.str + "1"; + b.str2 = b.str2 + "1"; + Bind.notify(b.bind); + Bind.notify(b.bind2); + } + catch (e:Dynamic) { + fail(); + } callNum.should.be(0); }); @@ -234,12 +242,17 @@ class BaseTest extends BuddySuite { it("bindx should unbind all bindings (signal expected) (lazySignal=true/false)", { Bind.unbindAll(b); - b.str = b.str + "1"; - b.str2 = b.str2 + "1"; - Bind.notify(b.bind); - Bind.notify(b.bind2); + try { + b.str = b.str + "1"; + b.str2 = b.str2 + "1"; + Bind.notify(b.bind); + Bind.notify(b.bind2); + } + catch (e:Dynamic) { + fail(); + } - callNum.should.be(0); + true.should.be(true); }); }); } diff --git a/test/SignalTest.hx b/test/SignalTest.hx new file mode 100644 index 0000000..846c144 --- /dev/null +++ b/test/SignalTest.hx @@ -0,0 +1,18 @@ +package ; + +import bindx.Bind; +import bindx.Bind.bind in bind; +import buddy.*; + +using buddy.Should; + +class SignalTest extends BuddySuite { + + public function new() { + super(); + + describe("BindSignal functionality tests", { + it("signals should dispatch data"); + }); + } +} \ No newline at end of file diff --git a/test/TestProperty.hx b/test/TestProperty.hx index a78a94f..47f06da 100644 --- a/test/TestProperty.hx +++ b/test/TestProperty.hx @@ -1,13 +1,24 @@ package ; import bindx.Bind; +import bindx.Bind.bind in bind; +import buddy.*; -class TestProperty extends haxe.unit.TestCase { +using buddy.Should; + +class TestProperty extends BuddySuite { public function new() { super(); + + describe("Bindx modify field setter", { + it("bindx should bind/unbind fields with setter (lazySignal=true)"); + it("bindx should bind/unbind fields with setter (lazySignal=false)"); + it("bindx should bind 2 objects (custom setter) (lazySignal=true)"); + it("bindx should bind 2 objects (custom setter) (lazySignal=false)"); + }); } - function test1() { + /*function test1() { var p = new BindableProperty(); p.s = "1"; var callNum = 0; @@ -40,20 +51,32 @@ class TestProperty extends haxe.unit.TestCase { p.s = "123"; assertEquals(t.a, p.s); } + */ } class BindableProperty implements bindx.IBindable { public function new() { } - @:bindable - public var s(default, set):String; + @:bindable(lazySignal=true) + public var str(default, set):String; - function set_s(v) { + function set_str(v) { if (v == null) { - return s = ""; + return str = ""; } - s = v; + str = v; + return v; + } + + @:bindable(lazySignal=false) + public var str2(default, set):String; + + function set_str2(v) { + if (v == null) { + return str2 = ""; + } + str2 = v; return v; } } \ No newline at end of file