Merge pull request #5 from profelis/development

speedup, strict mode, typedefs, generics support
This commit is contained in:
Dima Granetchi
2015-01-25 03:47:18 +02:00
18 changed files with 171 additions and 147 deletions
+5 -5
View File
@@ -7,22 +7,22 @@ import bindx.macro.BindMacros;
class Bind {
@:noUsing macro static public function bind(field:Expr, listener:Expr):Expr {
return BindMacros.internalBind(field, listener, true);
return BindMacros.bind(field, listener, true);
}
@:noUsing macro static public function bindTo(field:Expr, target:Expr):Expr {
return BindMacros.internalBindTo(field, target);
return BindMacros.bindTo(field, target);
}
@:noUsing macro static public function unbind(field:Expr, ?listener:Expr):Expr {
return BindMacros.internalBind(field, listener, false);
return BindMacros.bind(field, listener, false);
}
@:noUsing macro static public function notify(field:Expr, ?oldValue:Expr, ?newValue:Expr):Expr {
return BindMacros.internalNotify(field, oldValue, newValue);
return BindMacros.notify(field, oldValue, newValue);
}
@:noUsing macro static public function unbindAll(object:ExprOf<IBindable>):Expr {
return BindMacros.internalUnbindAll(object);
return BindMacros.unbindAll(object);
}
}
+7 -7
View File
@@ -1,29 +1,29 @@
package bindx;
import haxe.macro.Expr;
import haxe.macro.Context;
import bindx.macro.BindExtMacros;
using haxe.macro.Tools;
using bindx.macro.MacroUtils;
@:access(bindx.macro.BindxExtMacro)
class BindExt {
@:noUsing macro static public function expr<T>(expr:ExprOf<T>, listener:ExprOf<Null<T>->Null<T>->Void>):ExprOf<Void->Void> {
return BindxExtMacro.internalBindExpr(expr, listener);
return BindxExtMacro.bindExpr(expr, listener);
}
@:noUsing macro static public function exprTo<T>(expr:ExprOf<T>, target:ExprOf<T>):ExprOf<Void->Void> {
var type = Context.typeof(expr).toComplexType();
return BindxExtMacro.internalBindExpr(expr, macro function (_, to:Null<$type>) $target = to);
var type = expr.getComplexType();
return BindxExtMacro.bindExpr(expr, macro function (_, to:Null<$type>) $target = to);
}
@:noUsing macro static public function chain<T>(expr:ExprOf<T>, listener:Expr):ExprOf<Void->Void> {
return BindxExtMacro.internalBindChain(expr, listener);
return BindxExtMacro.bindChain(expr, listener);
}
@:noUsing macro static public function chainTo<T>(expr:ExprOf<T>, target:ExprOf<T>):ExprOf<Void->Void> {
var type = Context.typeof(expr).toComplexType();
return BindxExtMacro.internalBindChain(expr, macro function (_, to:Null<$type>) $target = to);
var type = expr.getComplexType();
return BindxExtMacro.bindChain(expr, macro function (_, to:Null<$type>) $target = to);
}
}
+1 -1
View File
@@ -82,7 +82,7 @@ class SignalTools {
if (meta != null) for (m in std.Reflect.fields(meta)) {
var data = std.Reflect.field(meta, m);
if (std.Reflect.hasField(data, BIND_SIGNAL_META)) {
var signal:bindx.BindSignal.Signal<Dynamic> = cast Reflect.field(bindable, m);
var signal:bindx.BindSignal.Signal<Dynamic> = cast std.Reflect.field(bindable, m);
if (signal != null) {
signal.removeAll();
var args:Array<Dynamic> = std.Reflect.field(data, BIND_SIGNAL_META);
+24 -23
View File
@@ -11,6 +11,7 @@ import bindx.macro.BindMacros;
using Lambda;
using StringTools;
using bindx.macro.MacroUtils;
using haxe.macro.Tools;
private typedef FieldExpr = {
@@ -31,7 +32,7 @@ private typedef Chain = {
@:access(bindx.macro.BindMacros)
class BindxExtMacro {
static inline function internalBindChain(expr:Expr, listener:Expr):Expr {
static inline function bindChain(expr:Expr, listener:Expr):Expr {
var zeroListener = listenerName(0, "");
var chain = null;
try { chain = warnPrepareChain(expr); } catch (e:GenericError) e.contextError();
@@ -42,18 +43,8 @@ class BindxExtMacro {
return res;
}
static inline function unwrapFormatedString(expr:Expr):Expr {
return if (MacroStringTools.isFormatExpr(expr)) {
var f = switch (expr.expr) {
case EConst(CString(s)): s;
case _: null;
}
if (f != null) MacroStringTools.formatString(f, expr.pos) else expr;
} else expr;
}
static function internalBindExpr(expr:Expr, listener:Expr):Expr {
var type = Context.typeof(expr).toComplexType();
static function bindExpr(expr:Expr, listener:Expr):Expr {
var type = expr.getComplexType();
var listenerNameExpr = macro listener;
var fieldListenerName = "fieldListener";
var fieldListenerNameExpr = macro $i{fieldListenerName};
@@ -96,7 +87,7 @@ class BindxExtMacro {
if (!binded.exists(key)) {
var ecall = switch (c.expr.expr) {
case EField(e, field):
var type = Context.typeof(e);
var type = e.deepTypeof();
var classRef = type.getClass();
var field = classRef.findField(field);
field.kind.match(FMethod(_));
@@ -246,6 +237,7 @@ class BindxExtMacro {
inline static function listenerName(idx:Int, prefix) return '${prefix}listener$idx';
static function prepareChain(fields:Array<FieldExpr>, expr:Expr, prefix = ""):Chain {
var bsp = BindableMacros.bindingSignalProvider;
var res:Chain = { init:[], bind:[], unbind:[], expr:null };
var prevListenerName = listenerName(0, prefix);
@@ -259,7 +251,7 @@ class BindxExtMacro {
while (++i < fields.length - 1) {
var field = fields[i + 1];
var prev = fields[i];
var type = Context.typeof(field.e).toComplexType();
var type = field.e.getComplexType();
var listenerName = listenerName(i+1, prefix);
var listenerNameExpr = macro $i { listenerName };
@@ -283,7 +275,7 @@ class BindxExtMacro {
}
if (prev.bindable) {
var unbind = BindableMacros.bindingSignalProvider.getClassFieldUnbindExpr(valueExpr, prev.field, prevListenerNameExpr );
var unbind = bsp.getClassFieldUnbindExpr(valueExpr, prev.field, prevListenerNameExpr );
res.bind.push(macro var $value:Null<$type> = null );
res.unbind.push(macro if ($valueExpr != null) { $unbind; $valueExpr = null; } );
@@ -291,7 +283,7 @@ class BindxExtMacro {
fieldListenerBody.push(macro if ($valueExpr != null) $unbind );
fieldListenerBody.push(macro $valueExpr = n );
fieldListenerBody.push(macro if (n != null)
$ { BindableMacros.bindingSignalProvider.getClassFieldBindExpr(macro n, prev.field, prevListenerNameExpr ) });
$ { bsp.getClassFieldBindExpr(macro n, prev.field, prevListenerNameExpr ) });
}
var callPrevArgs = prev.params != null ? [] : [macro o != null ? o.$fieldName : null, macro n != null ? n.$fieldName : null];
var callPrev = macro $prevListenerNameExpr($a { callPrevArgs } );
@@ -299,8 +291,7 @@ class BindxExtMacro {
if (field.params != null) {
fieldListenerBody.unshift(macro $i { oldValue } = n);
fieldListenerBody.unshift(macro try { n = $e; } catch (e:Dynamic) { });
fieldListenerBody.unshift(macro var n:Null < $type > = null);
fieldListenerBody.unshift(macro var n:Null<$type> = try { $e; } catch (_:Dynamic) { null; });
fieldListenerBody.unshift(macro var o:Null<$type> = $i{oldValue} );
res.init.push(macro var $oldValue:Null<$type> = null);
@@ -310,7 +301,7 @@ class BindxExtMacro {
} else {
if (prev.bindable) {
fieldListenerBody.unshift(macro if (o != null)
${BindableMacros.bindingSignalProvider.getClassFieldUnbindExpr(macro o, prev.field, prevListenerNameExpr )}
${bsp.getClassFieldUnbindExpr(macro o, prev.field, prevListenerNameExpr )}
);
}
fieldListener = macro function $listenerName (o:Null<$type>, n:Null<$type>):Void $b { fieldListenerBody };
@@ -322,15 +313,15 @@ class BindxExtMacro {
prevListenerNameExpr = listenerNameExpr;
}
if (zeroListener == null || zeroListener.f.bindable == false)
if (zeroListener == null || !zeroListener.f.bindable)
throw new GenericError('${expr.toString()} is not bindable.', expr.pos);
var zeroName = zeroListener.f.e.toString();
if (zeroName != "this")
res.init.unshift(macro var $zeroName = $i{zeroName});
res.bind.push(BindableMacros.bindingSignalProvider.getClassFieldBindExpr(macro $i{zeroName}, zeroListener.f.field, zeroListener.l ));
res.unbind.push(BindableMacros.bindingSignalProvider.getClassFieldUnbindExpr(macro $i{zeroName}, zeroListener.f.field, zeroListener.l ));
res.bind.push(bsp.getClassFieldBindExpr(macro $i{zeroName}, zeroListener.f.field, zeroListener.l ));
res.unbind.push(bsp.getClassFieldUnbindExpr(macro $i{zeroName}, zeroListener.f.field, zeroListener.l ));
if (zeroListener.f.params != null) {
res.bind.push(macro ${zeroListener.l}());
@@ -340,5 +331,15 @@ class BindxExtMacro {
}
return res;
}
static inline function unwrapFormatedString(expr:Expr):Expr {
return if (MacroStringTools.isFormatExpr(expr)) {
var f = switch (expr.expr) {
case EConst(CString(s)): s;
case _: null;
}
if (f != null) MacroStringTools.formatString(f, expr.pos) else expr;
} else expr;
}
}
#end
+10 -10
View File
@@ -8,30 +8,30 @@ import haxe.macro.Type;
import haxe.macro.Context;
using haxe.macro.Tools;
using bindx.macro.MetaUtils;
using Lambda;
using bindx.macro.MacroUtils;
@:access(bindx.macro.BindableMacros)
class BindMacros {
static inline function internalBind(field:Expr, listener:Expr, doBind:Bool):Expr {
static inline function bind(field:Expr, listener:Expr, doBind:Bool):Expr {
var fieldData = warnCheckField(field);
return if (doBind) BindableMacros.bindingSignalProvider.getClassFieldBindExpr(fieldData.e, fieldData.field, listener);
else BindableMacros.bindingSignalProvider.getClassFieldUnbindExpr(fieldData.e, fieldData.field, listener);
var bsp = BindableMacros.bindingSignalProvider;
return if (doBind) bsp.getClassFieldBindExpr(fieldData.e, fieldData.field, listener);
else bsp.getClassFieldUnbindExpr(fieldData.e, fieldData.field, listener);
}
static inline function internalBindTo(field:Expr, target:Expr):Expr {
static inline function bindTo(field:Expr, target:Expr):Expr {
var fieldData = warnCheckField(field);
return BindableMacros.bindingSignalProvider.getClassFieldBindToExpr(fieldData.e, fieldData.field, target);
}
static inline function internalNotify(field:Expr, ?oldValue:Expr, ?newValue:Expr):Expr {
static inline function notify(field:Expr, ?oldValue:Expr, ?newValue:Expr):Expr {
var fieldData = warnCheckField(field);
return BindableMacros.bindingSignalProvider.getClassFieldChangedExpr(fieldData.e, fieldData.field, oldValue, newValue);
}
static inline function internalUnbindAll(object:ExprOf<IBindable>):Expr {
var type = Context.typeof(object).follow();
static inline function unbindAll(object:ExprOf<IBindable>):Expr {
var type = object.deepTypeof();
if (!isBindable(type.getClass())) {
Context.error('\'${object.toString()}\' must be bindx.IBindable', object.pos);
}
@@ -55,7 +55,7 @@ class BindMacros {
var error:GenericError = null;
switch (f.expr) {
case EField(e, field):
var type = Context.typeof(e);
var type = e.deepTypeof();
var classType = switch (type) { case TInst(c, _): c.get(); case _: null; };
if (classType == null) {
error = new FatalError('Type \'${e.toString()}\' is unknown', e.pos);
+2 -3
View File
@@ -6,9 +6,8 @@ import haxe.macro.Type;
import haxe.macro.Context;
import bindx.BindSignal;
using bindx.macro.MetaUtils;
using bindx.macro.MacroUtils;
using haxe.macro.Tools;
using Lambda;
class BindSignalProvider implements IBindingSignalProvider {
@@ -113,7 +112,7 @@ class BindSignalProvider implements IBindingSignalProvider {
name: signalName,
kind: FProp("get", "never", type, null),
pos: field.pos,
access: [APrivate],
access: [APrivate]
});
var getter = macro function foo() {
+4 -4
View File
@@ -8,7 +8,7 @@ import haxe.macro.Context;
using haxe.macro.Tools;
using Lambda;
using StringTools;
using bindx.macro.MetaUtils;
using bindx.macro.MacroUtils;
class BindableMacros {
@@ -191,15 +191,15 @@ class BindableMacros {
static inline function injectBindableMeta(fields:Array<Field>, meta:MetadataEntry):Void {
for (f in fields) {
if (f.hasBindableMeta()) continue;
if (f.access.exists(function (it) return it.equals(APrivate))) continue;
if (f.access.indexOf(APrivate) > -1 || f.hasBindableMeta()) continue;
var forceParam = meta.findParam(FORCE);
if (isFieldBindable(f, fields, forceParam.isNotNullAndTrue()))
if (isFieldBindable(f, fields, forceParam.isNotNullAndTrue())) {
switch (f.kind) {
case FFun(_):
case _: f.meta.push({name:MetaUtils.BINDABLE_META, pos:f.pos, params:meta.params});
}
}
}
}
@@ -1,11 +1,11 @@
package bindx.macro;
#if macro
import haxe.macro.Type;
import haxe.macro.Expr;
import haxe.macro.Context;
using haxe.macro.Tools;
using Lambda;
class MetaUtils {
@@ -62,7 +62,7 @@ class ClassTypeMetaUtils {
return bindableMeta(classType) != null;
}
class ExprMetaUtils {
class ExprUtils {
static public inline function isTrue(expr:Expr):Bool
return expr.expr.match(EConst(CIdent("true")));
@@ -78,4 +78,13 @@ class ExprMetaUtils {
static public inline function isNullOrTrue(expr:Expr):Bool
return expr == null || isTrue(expr);
static public inline function getComplexType(expr:Expr):ComplexType {
return deepTypeof(expr).toComplexType();
}
static public inline function deepTypeof(expr:Expr):haxe.macro.Type {
return Context.typeof(expr).follow();
}
}
#end
+45 -16
View File
@@ -11,17 +11,17 @@ class BaseTest extends BuddySuite {
public function new() {
super();
describe("Using base functionality", {
describe("Using base functionality", function () {
var b:Bindable1;
var callNum:Int;
before({
before(function () {
b = new Bindable1();
callNum = 0;
});
it("bindx should bind/unbind fields (lazySignal=true)", {
it("bindx should bind/unbind fields (lazySignal=true)", function () {
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 fields (lazySignal=false)", {
it("bindx should bind/unbind fields (lazySignal=false)", function () {
var strFrom = b.str2 = "a";
var callNum2 = 0;
@@ -81,7 +81,7 @@ class BaseTest extends BuddySuite {
callNum2.should.be(1);
});
it("bindx should bind/unbind 'null' values (lazySignal=true)", {
it("bindx should bind/unbind 'null' values (lazySignal=true)", function () {
var strFrom = b.str = null;
var callNum2 = 0;
var listener = function (from:String, to:String) {
@@ -109,7 +109,7 @@ class BaseTest extends BuddySuite {
callNum2.should.be(1);
});
it("bindx should bind/unbind 'null' values (lazySignal=false)", {
it("bindx should bind/unbind 'null' values (lazySignal=false)", function () {
var strFrom = b.str2 = null;
var callNum2 = 0;
var listener = function (from:String, to:String) {
@@ -137,7 +137,7 @@ class BaseTest extends BuddySuite {
callNum2.should.be(1);
});
it("bindx should bind 2 objects (lazySignal=true)", {
it("bindx should bind 2 objects (lazySignal=true)", function() {
var callNum2 = 0;
var target = {a:""};
var s = "";
@@ -157,7 +157,7 @@ class BaseTest extends BuddySuite {
s.should.be(prev);
});
it("bindx should bind 2 objects (lazySignal=false)", {
it("bindx should bind 2 objects (lazySignal=false)", function () {
var callNum2 = 0;
var target = {a:""};
var s = "";
@@ -176,7 +176,7 @@ class BaseTest extends BuddySuite {
s.should.be(prev);
});
it("bindx should bind and notify methods (lazySignal=true)", {
it("bindx should bind and notify methods (lazySignal=true)", function () {
var listener = function () callNum++;
bind(b.bind, listener);
Bind.notify(b.bind);
@@ -189,7 +189,7 @@ class BaseTest extends BuddySuite {
callNum.should.be(1);
});
it("bindx should bind and notify methods (lazySignal=false)", {
it("bindx should bind and notify methods (lazySignal=false)", function () {
var listener = function () callNum++;
bind(b.bind2, listener);
Bind.notify(b.bind2);
@@ -202,7 +202,7 @@ class BaseTest extends BuddySuite {
callNum.should.be(1);
});
it("bindx should notify properties manual (lazySignal=true)", {
it("bindx should notify properties manual (lazySignal=true)", function () {
b.str = "3";
var f = "1";
var t = "2";
@@ -217,7 +217,7 @@ class BaseTest extends BuddySuite {
callNum.should.be(1);
});
it("bindx should notify properties manual (lazySignal=false)", {
it("bindx should notify properties manual (lazySignal=false)", function () {
b.str2 = "3";
var f = "1";
var t = "2";
@@ -232,7 +232,7 @@ class BaseTest extends BuddySuite {
callNum.should.be(1);
});
it("bindx should unbind all properties listeners (lazySignal=true)", {
it("bindx should unbind all properties listeners (lazySignal=true)", function () {
bind(b.str, function (from, to) callNum++);
bind(b.str, function (from, to) callNum++);
@@ -242,7 +242,7 @@ class BaseTest extends BuddySuite {
callNum.should.be(0);
});
it("bindx should unbind all properties listeners (lazySignal=false)", {
it("bindx should unbind all properties listeners (lazySignal=false)", function () {
bind(b.str2, function (from, to) callNum++);
bind(b.str2, function (from, to) callNum++);
@@ -252,7 +252,7 @@ class BaseTest extends BuddySuite {
callNum.should.be(0);
});
it("bindx should unbind all bindings (signal exists) (lazySignal=true/false)", {
it("bindx should unbind all bindings (signal exists) (lazySignal=true/false)", function () {
bind(b.str, function (_, _) callNum++); // create binding signal
bind(b.str2, function (_, _) callNum++);
bind(b.bind, function () callNum++);
@@ -273,7 +273,7 @@ class BaseTest extends BuddySuite {
callNum.should.be(0);
});
it("bindx should unbind all bindings (signal expected) (lazySignal=true/false)", {
it("bindx should unbind all bindings (signal expected) (lazySignal=true/false)", function () {
Bind.unbindAll(b);
try {
@@ -288,10 +288,39 @@ class BaseTest extends BuddySuite {
true.should.be(true);
});
it("bindx should resolve typedefs", function () {
var a:TypeBindable1 = new TypeBindable1();
Bind.bind(a.str, function (_, _) {
callNum ++;
});
a.str = "123";
callNum.should.be(1);
});
it("bindx should resolve parametric types", function () {
var b = new GenericBindable<TypeBindable1>();
b.a = new TypeBindable1();
Bind.bind(b.a.str, function (_, _) {
callNum ++;
});
b.a.str = "123";
callNum.should.be(1);
});
});
}
}
//@:generic
class GenericBindable<A> {
public var a:A;
public function new() {}
}
typedef TypeBindable1 = Bindable1;
class Bindable1 implements bindx.IBindable {
+8 -8
View File
@@ -11,7 +11,7 @@ class ChainBindTest extends BuddySuite {
public function new() {
describe("Using BindExt.chain", {
describe("Using BindExt.chain", function () {
var from:String;
var val:String;
@@ -19,7 +19,7 @@ class ChainBindTest extends BuddySuite {
var callNum:Int;
var target:{a:String};
before({
before(function () {
from = null;
val = "a";
b = new BindableChain(4);
@@ -27,7 +27,7 @@ class ChainBindTest extends BuddySuite {
callNum = 0;
});
it("BindExt.chain should bind chain changes (unset links)", {
it("BindExt.chain should bind chain changes (unset links)", function () {
b.c.c.d = val;
var listener = function (f:String, t:String) {
@@ -61,7 +61,7 @@ class ChainBindTest extends BuddySuite {
callNum.should.be(5);
});
it("BindExt.chain should bind chain changes (null links)", {
it("BindExt.chain should bind chain changes (null links)", function () {
b.c = null;
val = null;
@@ -84,7 +84,7 @@ class ChainBindTest extends BuddySuite {
callNum.should.be(3);
});
it("BindExt.chain should bind chain changes (0 gap)", {
it("BindExt.chain should bind chain changes (0 gap)", function () {
var b2 = new BindableChain(4);
b.c.c.f("tada").d = val;
b2.c.c.f("tada").d = val;
@@ -121,7 +121,7 @@ class ChainBindTest extends BuddySuite {
callNum.should.be(4);
});
it("BindExt.chain should bind chain changes (1 gap)", {
it("BindExt.chain should bind chain changes (1 gap)", function () {
b.c.nc.c.f("tada").d = "a";
var unbind = BindExt.chain(b.c.nc.c.f("tada").d, function (f:String, t:String) {
f.should.be(from);
@@ -166,7 +166,7 @@ class ChainBindTest extends BuddySuite {
callNum.should.be(3);
});
it("BindExt.chain should bind chain changes (double gap)", {
it("BindExt.chain should bind chain changes (double gap)", function () {
b.c.nc.nc.d = "a";
BindExt.chain(b.c.nc.nc.d, function (f, t:String) {
@@ -205,7 +205,7 @@ class ChainBindTest extends BuddySuite {
callNum.should.be(2);
});
it("BindExt.chain should bind default fields", {
it("BindExt.chain should bind default fields", function () {
b.d = val = "a";
var unbind = BindExt.chain(b.d, function (f:String, t:String) {
+4 -4
View File
@@ -11,18 +11,18 @@ class ExprBindTest extends BuddySuite {
public function new() {
describe("Using BindExt.expr", {
describe("Using BindExt.expr", function () {
var callNum:Int;
var from:String;
var target:{a:String};
before({
before(function () {
target = {a:null};
from = null;
callNum = 0;
});
it("BindExt.chain should bind simple expr", {
it("BindExt.chain should bind simple expr", function () {
var a = new BaseTest.Bindable1();
var b = new BaseTest.Bindable1();
a.str = "a1";
@@ -51,7 +51,7 @@ class ExprBindTest extends BuddySuite {
callNum.should.be(3);
});
it("BindExt.chain should bind complex expresions", {
it("BindExt.chain should bind complex expresions", function () {
var a = new BaseTest.Bindable1();
var b = new BaseTest.Bindable1();
var c = new BaseTest.Bindable1();
+3 -3
View File
@@ -10,17 +10,17 @@ class ForceTest extends BuddySuite {
public function new() {
describe("Using @:bindable(force=true)", {
describe("Using @:bindable(force=true)", function () {
var b:BindableForce;
var callNum:Int;
before({
before(function () {
b = new BindableForce();
callNum = 0;
});
it("bindx should correct work with 'force' fields", {
it("bindx should correct work with 'force' fields", function () {
Bind.bind(b.str, function (_, _) callNum++);
Bind.bind(b.str2, function (_, _) callNum++);
Bind.bind(b.str3, function (_, _) callNum++);
+3 -3
View File
@@ -10,18 +10,18 @@ class InheritanceTest extends BuddySuite {
public function new() {
super();
describe("Using classes inheritance", {
describe("Using classes inheritance", function () {
var b:BindableChild;
var bp:BindableParent;
var callNum:Int;
before({
before(function () {
b = new BindableChild();
bp = new BindableParent();
callNum = 0;
});
it("bindx should support class/interface inheritance", {
it("bindx should support class/interface inheritance", function () {
b.i = 1;
b.s = "a";
Bind.bind(b.i, function (_, _) callNum++);
+4 -4
View File
@@ -12,13 +12,13 @@ class InlineTest extends BuddySuite {
public function new() {
describe("Using @:bindable(inlineSetter=true/false, inlineSignalGetter=true/false)", {
describe("Using @:bindable(inlineSetter=true/false, inlineSignalGetter=true/false)", function () {
var b:BindableInline;
var cd:Classdef;
var foundFields:Int;
before({
before(function () {
foundFields = 0;
b = new BindableInline();
var rttiData:String = untyped BindableInline.__rtti;
@@ -26,7 +26,7 @@ class InlineTest extends BuddySuite {
cd = switch (rtti) { case TClassdecl(c): c; case _: null; };
});
it("bindx should generate inline setter", {
it("bindx should generate inline setter", function () {
for (c in cd.fields) {
switch (c.name) {
case "set_str":
@@ -41,7 +41,7 @@ class InlineTest extends BuddySuite {
foundFields.should.be(2);
});
it("bindx should generate inline signal getter", {
it("bindx should generate inline signal getter", function () {
for (c in cd.fields) {
switch (c.name) {
case "get_str3Changed":
+5 -5
View File
@@ -10,17 +10,17 @@ class MetaTest extends BuddySuite {
public function new() {
describe("Using @bindable meta inheritance", {
describe("Using @bindable meta inheritance", function () {
var b:BindableMeta;
var callNum:Int;
before({
before(function () {
b = new BindableMeta();
callNum = 0;
});
it("bindx inherit metadata bindable for public fields", {
it("bindx inherit metadata bindable for public fields", function () {
b.str = "a";
Bind.bind(b.str, function(_, _) callNum++);
@@ -28,7 +28,7 @@ class MetaTest extends BuddySuite {
callNum.should.be(1);
});
it("bindx inherit metadata bindable for public fields", {
it("bindx inherit metadata bindable for public fields", function () {
b.str2 = "a";
Bind.bind(b.str2, function(_, _) callNum++);
@@ -36,7 +36,7 @@ class MetaTest extends BuddySuite {
callNum.should.be(1);
});
it("bindx inherit metadata params", {
it("bindx inherit metadata params", function () {
@:privateAccess b.strChanged.should.not.be(null);
@:privateAccess b.str2Changed.should.not.be(null);
});
+8 -8
View File
@@ -10,17 +10,17 @@ class SignalTest extends BuddySuite {
public function new() {
super();
describe("Using BindSignal", {
describe("Using BindSignal", function () {
var fs:FieldSignal<String>;
var callNum:Int;
before({
before(function () {
fs = new FieldSignal<String>();
callNum = 0;
});
it("signal listeners should listen signal", {
it("signal listeners should listen signal", function () {
var f = "1";
var t = "2";
function listener(from:String, to:String) {
@@ -49,7 +49,7 @@ class SignalTest extends BuddySuite {
callNum.should.be(3);
});
it("signal should correct add/remove listeners", {
it("signal should correct add/remove listeners", function () {
function listener2(_, _) {
callNum ++;
}
@@ -79,7 +79,7 @@ class SignalTest extends BuddySuite {
callNum.should.be(4); // all listeners removed
});
it("signal should correct dispatch in listener", {
it("signal should correct dispatch in listener", function () {
function listener(_, _) {
fs.remove(listener);
fs.dispatch(null, null);
@@ -97,17 +97,17 @@ class SignalTest extends BuddySuite {
});
});
describe("Using MethodSignal", {
describe("Using MethodSignal", function () {
var ms:MethodSignal;
var callNum:Int;
before({
before(function () {
ms = new MethodSignal();
callNum = 0;
});
it("signal listeners should listen signal", {
it("signal listeners should listen signal", function () {
function listener() {
callNum ++;
ms.remove(listener);
+14 -14
View File
@@ -10,17 +10,17 @@ class TestProperty extends BuddySuite {
public function new() {
super();
describe("Using bind properties", {
describe("Using bind properties", function () {
var b:BindableProperty;
var callNum:Int;
before({
before(function () {
b = new BindableProperty();
callNum = 0;
});
it("bindx should bind/unbind fields (lazySignal=true)", {
it("bindx should bind/unbind fields (lazySignal=true)", function () {
var strFrom = b.str = "a";
var callNum2 = 0;
@@ -50,7 +50,7 @@ class TestProperty extends BuddySuite {
callNum2.should.be(1);
});
it("bindx should bind/unbind fields (lazySignal=false)", {
it("bindx should bind/unbind fields (lazySignal=false)", function () {
var strFrom = b.str2 = "a";
var callNum2 = 0;
@@ -80,7 +80,7 @@ class TestProperty extends BuddySuite {
callNum2.should.be(1);
});
it("bindx should bind/unbind 'null' values (lazySignal=true)", {
it("bindx should bind/unbind 'null' values (lazySignal=true)", function () {
var strFrom = b.str = null;
var callNum2 = 0;
var listener = function (from:String, to:String) {
@@ -108,7 +108,7 @@ class TestProperty extends BuddySuite {
callNum2.should.be(1);
});
it("bindx should bind/unbind 'null' values (lazySignal=false)", {
it("bindx should bind/unbind 'null' values (lazySignal=false)", function () {
var strFrom = b.str2 = null;
var callNum2 = 0;
var listener = function (from:String, to:String) {
@@ -136,7 +136,7 @@ class TestProperty extends BuddySuite {
callNum2.should.be(1);
});
it("bindx should bind 2 objects (lazySignal=true)", {
it("bindx should bind 2 objects (lazySignal=true)", function () {
var callNum2 = 0;
var target = {a:""};
var s = "";
@@ -156,7 +156,7 @@ class TestProperty extends BuddySuite {
s.should.be(prev);
});
it("bindx should bind 2 objects (lazySignal=false)", {
it("bindx should bind 2 objects (lazySignal=false)", function () {
var callNum2 = 0;
var target = {a:""};
var s = "";
@@ -175,7 +175,7 @@ class TestProperty extends BuddySuite {
s.should.be(prev);
});
it("bindx should notify properties manual (lazySignal=true)", {
it("bindx should notify properties manual (lazySignal=true)", function () {
b.str = "3";
var f = "1";
var t = "2";
@@ -190,7 +190,7 @@ class TestProperty extends BuddySuite {
callNum.should.be(1);
});
it("bindx should notify properties manual (lazySignal=false)", {
it("bindx should notify properties manual (lazySignal=false)", function () {
b.str2 = "3";
var f = "1";
var t = "2";
@@ -205,7 +205,7 @@ class TestProperty extends BuddySuite {
callNum.should.be(1);
});
it("bindx should unbind all properties listeners (lazySignal=true)", {
it("bindx should unbind all properties listeners (lazySignal=true)", function () {
bind(b.str, function (from, to) callNum++);
bind(b.str, function (from, to) callNum++);
@@ -215,7 +215,7 @@ class TestProperty extends BuddySuite {
callNum.should.be(0);
});
it("bindx should unbind all properties listeners (lazySignal=false)", {
it("bindx should unbind all properties listeners (lazySignal=false)", function () {
bind(b.str2, function (from, to) callNum++);
bind(b.str2, function (from, to) callNum++);
@@ -225,7 +225,7 @@ class TestProperty extends BuddySuite {
callNum.should.be(0);
});
it("bindx should unbind all bindings (signal exists) (lazySignal=true/false)", {
it("bindx should unbind all bindings (signal exists) (lazySignal=true/false)", function () {
bind(b.str, function (_, _) callNum++); // create binding signal
bind(b.str2, function (_, _) callNum++);
@@ -242,7 +242,7 @@ class TestProperty extends BuddySuite {
callNum.should.be(0);
});
it("bindx should unbind all bindings (signal expected) (lazySignal=true/false)", {
it("bindx should unbind all bindings (signal expected) (lazySignal=true/false)", function () {
Bind.unbindAll(b);
try {
+11 -25
View File
@@ -3,28 +3,14 @@ package ;
import buddy.BuddySuite;
import buddy.SuitesRunner;
class Tests extends BuddySuite {
public static function main() {
var reporter = new buddy.reporting.TravisHxReporter();
var runner = new SuitesRunner([
new BaseTest(),
new InheritanceTest(),
new InlineTest(),
new MetaTest(),
new SignalTest(),
new TestProperty(),
new ChainBindTest(),
new ExprBindTest(),
], reporter);
runner.run();
#if sys
Sys.exit(runner.statusCode());
#else
return runner.statusCode();
#end
}
}
@:build(buddy.GenerateMain.withSuites([
new BaseTest(),
new InheritanceTest(),
new InlineTest(),
new MetaTest(),
new SignalTest(),
new TestProperty(),
new ChainBindTest(),
new ExprBindTest(),
]))
class Tests extends BuddySuite {}