From dde9c0759e83f716e2f89a88d07a74d90c63b9dc Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Mon, 20 Feb 2017 09:43:19 +0100 Subject: [PATCH 01/25] Null exception throwing removed to handle types not based on classes (typedef, enum). --- src/hex/control/payload/ExecutionPayload.hx | 8 ++++---- test/hex/control/payload/ExecutionPayloadTest.hx | 6 ------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/hex/control/payload/ExecutionPayload.hx b/src/hex/control/payload/ExecutionPayload.hx index 6cbfb90..a50d312 100644 --- a/src/hex/control/payload/ExecutionPayload.hx +++ b/src/hex/control/payload/ExecutionPayload.hx @@ -32,10 +32,10 @@ class ExecutionPayload this._type = Type.getClass( this._data ); } - if ( !Std.is( this._data, this._type ) ) + /*if ( !Std.is( this._data, this._type ) ) { throw new IllegalArgumentException( "ExecutionPayload data '" + this._data + "' should be an instance of type '" + this._type + "'" ); - } + }*/ this._name = name; } @@ -73,10 +73,10 @@ class ExecutionPayload public function withClassName( className : String ) : ExecutionPayload { this._type = Type.resolveClass( className.split( '<' )[ 0 ] ); - if ( this._type == null ) + /*if ( this._type == null ) { throw new IllegalArgumentException( "type '" + className + "' not found" ); - } + }*/ this._className = className; return this; diff --git a/test/hex/control/payload/ExecutionPayloadTest.hx b/test/hex/control/payload/ExecutionPayloadTest.hx index c21f1c8..1dc7585 100644 --- a/test/hex/control/payload/ExecutionPayloadTest.hx +++ b/test/hex/control/payload/ExecutionPayloadTest.hx @@ -45,12 +45,6 @@ class ExecutionPayloadTest } #end - @Test( "Test constructor throws IllegalArgumentException" ) - public function testConstructorThrowsIllegalArgumentException() : Void - { - Assert.constructorCallThrows( IllegalArgumentException, ExecutionPayload, [ this._data, String ], "constructor should throw IllegalArgumentException" ); - } - /*@Test( "Test overwriting type property" ) public function testOverwritingType() : Void { From 9c360bd78c58bf77426833cb7a1bfd30fb5e03d0 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Mon, 20 Feb 2017 10:05:18 +0100 Subject: [PATCH 02/25] spaces removed from class name stored in payload --- src/hex/control/payload/ExecutionPayload.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hex/control/payload/ExecutionPayload.hx b/src/hex/control/payload/ExecutionPayload.hx index a50d312..9a73111 100644 --- a/src/hex/control/payload/ExecutionPayload.hx +++ b/src/hex/control/payload/ExecutionPayload.hx @@ -78,7 +78,7 @@ class ExecutionPayload throw new IllegalArgumentException( "type '" + className + "' not found" ); }*/ - this._className = className; + this._className = className.split( " " ).join( '' ); return this; } } From 46bb327fad63185744adb0fb46e383d3ea9e8a39 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Mon, 20 Feb 2017 14:00:42 +0100 Subject: [PATCH 03/25] useless annotation removed --- test/hex/event/GenericConnection.hx | 1 - 1 file changed, 1 deletion(-) diff --git a/test/hex/event/GenericConnection.hx b/test/hex/event/GenericConnection.hx index bb61240..4d166ed 100644 --- a/test/hex/event/GenericConnection.hx +++ b/test/hex/event/GenericConnection.hx @@ -6,6 +6,5 @@ package hex.event; */ interface GenericConnection { - @:astSource function onChangeValue( value : U ) : Void; } \ No newline at end of file From 536b3990b711d213336e3398279739c9506b8756 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Mon, 20 Feb 2017 15:13:09 +0100 Subject: [PATCH 04/25] Test added for Trigger with method and enum argument. --- test/hex/event/MockColor.hx | 11 +++++++++++ test/hex/event/TriggerTest.hx | 6 ++++++ 2 files changed, 17 insertions(+) create mode 100644 test/hex/event/MockColor.hx diff --git a/test/hex/event/MockColor.hx b/test/hex/event/MockColor.hx new file mode 100644 index 0000000..5522155 --- /dev/null +++ b/test/hex/event/MockColor.hx @@ -0,0 +1,11 @@ +package hex.event; + +/** + * @author Francis Bourre + */ +enum MockColor +{ + Red; + Green; + Blue; +} \ No newline at end of file diff --git a/test/hex/event/TriggerTest.hx b/test/hex/event/TriggerTest.hx index 130e0e4..62b5810 100644 --- a/test/hex/event/TriggerTest.hx +++ b/test/hex/event/TriggerTest.hx @@ -22,6 +22,8 @@ class TriggerTest model.genericOutput.connect( genericMockDriver ); var callbackResult; model.callbacks.connect( function ( s : String, i : Int ) callbackResult = { s: s, i: i } ); + var colorResult = MockColor.Red; + model.colorCallbacks.connect( function ( color : MockColor ) colorResult = color ); model.changeAllValues( 3, "test", this ); Assert.equals( 1, intMockDriver.callbackCallCount ); @@ -32,6 +34,7 @@ class TriggerTest Assert.equals( this, genericMockDriver.callbackParam ); Assert.equals( "test", callbackResult.s ); Assert.equals( 3, callbackResult.i ); + Assert.equals( MockColor.Blue, colorResult ); model.stringOutput.disconnectAll(); model.genericOutput.disconnectAll(); @@ -58,6 +61,8 @@ private class MockModel implements ITriggerOwner public var genericOutput( default, never ) : ITrigger>; public var callbacks( default, never ) : ITriggerInt->Void>; + + public var colorCallbacks( default, never ) : ITriggerVoid>; public function new(){} @@ -67,6 +72,7 @@ private class MockModel implements ITriggerOwner this.stringOutput.onChangeStringValue( s ); this.genericOutput.onChangeValue( o ); this.callbacks.trigger( s, i ); + this.colorCallbacks.trigger( MockColor.Blue ); } } From 6a69e7807b6a4de0d63789c043a77b3b54aed961 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Tue, 21 Feb 2017 10:19:44 +0100 Subject: [PATCH 05/25] Trigger can handle method signatures with implicit types (no fully qualified name). --- src/hex/event/TriggerBuilder.hx | 34 ++++++++++++++++++++++++++---- test/hex/event/MockTypedef.hx | 9 ++++++++ test/hex/event/TriggerTest.hx | 37 +++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 test/hex/event/MockTypedef.hx diff --git a/src/hex/event/TriggerBuilder.hx b/src/hex/event/TriggerBuilder.hx index d88301e..3b861ac 100644 --- a/src/hex/event/TriggerBuilder.hx +++ b/src/hex/event/TriggerBuilder.hx @@ -14,6 +14,7 @@ import hex.event.ITrigger; import hex.util.MacroUtil; using haxe.macro.Context; +using haxe.macro.Tools; /** * ... @@ -189,14 +190,39 @@ class TriggerBuilder static function _buildClassVOFromTFunction( triggerDefinition : { args: Array, ret: ComplexType, triggerParamType : Null } ) : ClassVO { - var className = '__Trigger_Class__' + (TriggerBuilder._ID++); - var dispatcherClass : TypeDefinition = null; + var getPack = function( className : String ) : { pack: Array, className: String } + { + var pack = className.split( "." ); + var className = pack[ pack.length -1 ]; + pack.splice( pack.length - 1, 1 ); - dispatcherClass = TriggerBuilder._getClassSkeleton( className, triggerDefinition.triggerParamType ); + return { pack: pack, className: className }; + } var l = triggerDefinition.args.length; - var args = [ for ( i in 0...l ) { name: 'arg' + i, type: triggerDefinition.args[ i ], opt: false } ]; + var args = []; + for ( i in 0...l ) + { + var t = triggerDefinition.args[ i ]; + switch( t ) + { + case TPath( p ): + var ttype = t.toType().toString().split('<')[0]; + var tPack = getPack( ttype ); + //do the dirty job of setting the right pack for each argument if the developer forgets to set it. + p.pack = tPack.pack; + + case _: + } + args.push( { name: 'arg' + i, type: t, opt: false } ); + } + var className = '__Trigger_Class__' + (TriggerBuilder._ID++); + var dispatcherClass : TypeDefinition = null; + + //build class + dispatcherClass = TriggerBuilder._getClassSkeleton( className, triggerDefinition.triggerParamType ); + var newField : Field = { meta: null, diff --git a/test/hex/event/MockTypedef.hx b/test/hex/event/MockTypedef.hx new file mode 100644 index 0000000..c33ea4d --- /dev/null +++ b/test/hex/event/MockTypedef.hx @@ -0,0 +1,9 @@ +package hex.event; + +/** + * @author Francis Bourre + */ +typedef MockTypedef = +{ + var name : String; +} \ No newline at end of file diff --git a/test/hex/event/TriggerTest.hx b/test/hex/event/TriggerTest.hx index 62b5810..ad16570 100644 --- a/test/hex/event/TriggerTest.hx +++ b/test/hex/event/TriggerTest.hx @@ -1,5 +1,7 @@ package hex.event; +import hex.event.MockTypedef; +import hex.data.IParser; import hex.structures.Size; import hex.unittest.assertion.Assert; @@ -20,11 +22,19 @@ class TriggerTest model.intOutput.connect( intMockDriver ); model.stringOutput.connect( stringMockDriver ); model.genericOutput.connect( genericMockDriver ); + var callbackResult; model.callbacks.connect( function ( s : String, i : Int ) callbackResult = { s: s, i: i } ); + var colorResult = MockColor.Red; model.colorCallbacks.connect( function ( color : MockColor ) colorResult = color ); + var parserResult = ''; + model.triggerParser.connect( function ( parser : IParser ) parserResult = parser.parse( 'test' ) ); + + var parserResult2; + model.triggerParser2.connect( function ( parser : IParser ) parserResult2 = parser.parse( 'test' ) ); + model.changeAllValues( 3, "test", this ); Assert.equals( 1, intMockDriver.callbackCallCount ); Assert.equals( 1, stringMockDriver.callbackCallCount ); @@ -35,6 +45,8 @@ class TriggerTest Assert.equals( "test", callbackResult.s ); Assert.equals( 3, callbackResult.i ); Assert.equals( MockColor.Blue, colorResult ); + Assert.equals('test was parsed', parserResult ); + Assert.equals('test', parserResult2.name ); model.stringOutput.disconnectAll(); model.genericOutput.disconnectAll(); @@ -63,6 +75,11 @@ private class MockModel implements ITriggerOwner public var callbacks( default, never ) : ITriggerInt->Void>; public var colorCallbacks( default, never ) : ITriggerVoid>; + + public var triggerParser( default, never ) : ITrigger->Void>; + + public var triggerParser2( default, never ) : ITrigger->Void>; + public function new(){} @@ -73,9 +90,29 @@ private class MockModel implements ITriggerOwner this.genericOutput.onChangeValue( o ); this.callbacks.trigger( s, i ); this.colorCallbacks.trigger( MockColor.Blue ); + this.triggerParser.trigger( new MockParser() ); + this.triggerParser2.trigger( new MockParser2() ); } } +private class MockParser implements IParser +{ + public function new() {} + public function parse( serializedContent : Dynamic, target : Dynamic = null ) : String + { + return serializedContent + " was parsed"; + } +} + +private class MockParser2 implements IParser +{ + public function new() {} + public function parse( serializedContent : Dynamic, target : Dynamic = null ) : MockTypedef + { + return {name:serializedContent}; + } +} + private class IntMockDriver implements IIntConnection { public var callbackCallCount : Int = 0; From 87b569653ce34b2a5f575d9561a6ac0da6ffc6e5 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Wed, 22 Feb 2017 09:59:33 +0100 Subject: [PATCH 06/25] More code coverage --- src/hex/collection/LocatorMessage.hx | 10 +-- src/hex/control/AsyncHandlerUtil.hx | 1 - src/hex/control/forward/ForwarderBuilder.hx | 4 +- src/hex/control/payload/ExecutionPayload.hx | 11 ---- src/hex/data/GUID.hx | 8 +++ src/hex/domain/DefaultDomain.hx | 2 - src/hex/domain/DomainUtil.hx | 12 ++-- src/hex/domain/NoDomain.hx | 2 - src/hex/module/ModuleMessage.hx | 4 +- src/hex/util/MacroUtil.hx | 10 +-- src/hex/util/PerformanceUtil.hx | 72 --------------------- test/hex/HexCoreSuite.hx | 17 ++++- test/hex/collection/LocatorMessageTest.hx | 7 +- test/hex/control/AsyncHandlerUtilTest.hx | 6 ++ test/hex/control/payload/PayloadUtilTest.hx | 6 ++ test/hex/core/HashCodeFactoryTest.hx | 6 ++ test/hex/data/GUIDTest.hx | 6 ++ test/hex/domain/DomainUtilTest.hx | 6 ++ test/hex/module/CoreModuleSuite.hx | 11 ++++ test/hex/module/ModuleMessageTest.hx | 30 +++++++++ test/hex/util/ClassUtilTest.hx | 6 ++ 21 files changed, 131 insertions(+), 106 deletions(-) delete mode 100644 src/hex/util/PerformanceUtil.hx create mode 100644 test/hex/module/CoreModuleSuite.hx create mode 100644 test/hex/module/ModuleMessageTest.hx diff --git a/src/hex/collection/LocatorMessage.hx b/src/hex/collection/LocatorMessage.hx index 3742a40..c93fa05 100644 --- a/src/hex/collection/LocatorMessage.hx +++ b/src/hex/collection/LocatorMessage.hx @@ -1,5 +1,6 @@ package hex.collection; +import hex.error.PrivateConstructorException; import hex.event.MessageType; /** @@ -8,11 +9,12 @@ import hex.event.MessageType; */ class LocatorMessage { - inline static public var REGISTER = new MessageType( "onRegister" ); - inline static public var UNREGISTER = new MessageType( "onUnregister" ); - + /** @private */ function new() { - + throw new PrivateConstructorException(); } + + inline static public var REGISTER = new MessageType( "onRegister" ); + inline static public var UNREGISTER = new MessageType( "onUnregister" ); } \ No newline at end of file diff --git a/src/hex/control/AsyncHandlerUtil.hx b/src/hex/control/AsyncHandlerUtil.hx index 8bc0a3a..022d483 100644 --- a/src/hex/control/AsyncHandlerUtil.hx +++ b/src/hex/control/AsyncHandlerUtil.hx @@ -1,6 +1,5 @@ package hex.control; -import haxe.Constraints.Function; import haxe.ds.StringMap; import haxe.macro.Context; import haxe.macro.Expr; diff --git a/src/hex/control/forward/ForwarderBuilder.hx b/src/hex/control/forward/ForwarderBuilder.hx index d9ca513..4ddf380 100644 --- a/src/hex/control/forward/ForwarderBuilder.hx +++ b/src/hex/control/forward/ForwarderBuilder.hx @@ -1,5 +1,6 @@ package hex.control.forward; +#if macro import haxe.macro.Context; import haxe.macro.Expr; import hex.error.PrivateConstructorException; @@ -106,4 +107,5 @@ class ForwarderBuilder } return a; } -} \ No newline at end of file +} +#end \ No newline at end of file diff --git a/src/hex/control/payload/ExecutionPayload.hx b/src/hex/control/payload/ExecutionPayload.hx index 9a73111..0fdfffe 100644 --- a/src/hex/control/payload/ExecutionPayload.hx +++ b/src/hex/control/payload/ExecutionPayload.hx @@ -1,6 +1,5 @@ package hex.control.payload; -import hex.error.IllegalArgumentException; import hex.error.NullPointerException; /** @@ -31,11 +30,6 @@ class ExecutionPayload { this._type = Type.getClass( this._data ); } - - /*if ( !Std.is( this._data, this._type ) ) - { - throw new IllegalArgumentException( "ExecutionPayload data '" + this._data + "' should be an instance of type '" + this._type + "'" ); - }*/ this._name = name; } @@ -73,11 +67,6 @@ class ExecutionPayload public function withClassName( className : String ) : ExecutionPayload { this._type = Type.resolveClass( className.split( '<' )[ 0 ] ); - /*if ( this._type == null ) - { - throw new IllegalArgumentException( "type '" + className + "' not found" ); - }*/ - this._className = className.split( " " ).join( '' ); return this; } diff --git a/src/hex/data/GUID.hx b/src/hex/data/GUID.hx index 3817e5e..863e327 100644 --- a/src/hex/data/GUID.hx +++ b/src/hex/data/GUID.hx @@ -1,11 +1,19 @@ package hex.data; +import hex.error.PrivateConstructorException; + /** * ... * @author Krisztian Fekete */ class GUID { + /** @private */ + function new() + { + throw new PrivateConstructorException(); + } + inline public static function randomIntegerWithinRange( min : Int, max : Int ) : Int { return Math.floor( Math.random() * ( 1 + max - min ) + min ); diff --git a/src/hex/domain/DefaultDomain.hx b/src/hex/domain/DefaultDomain.hx index 3420abb..6611307 100644 --- a/src/hex/domain/DefaultDomain.hx +++ b/src/hex/domain/DefaultDomain.hx @@ -1,7 +1,5 @@ package hex.domain; -import hex.domain.Domain; - /** * ... * @author Francis Bourre diff --git a/src/hex/domain/DomainUtil.hx b/src/hex/domain/DomainUtil.hx index a7f1f77..239e383 100644 --- a/src/hex/domain/DomainUtil.hx +++ b/src/hex/domain/DomainUtil.hx @@ -1,7 +1,6 @@ package hex.domain; -import hex.error.IllegalArgumentException; -import hex.util.ClassUtil; +import hex.error.PrivateConstructorException; /** * ... @@ -11,10 +10,11 @@ class DomainUtil { static var _domain = new Map(); - function new() - { - - } + /** @private */ + function new() + { + throw new PrivateConstructorException(); + } static public function getDomain( domainName : String, type : Class ) : DomainType { diff --git a/src/hex/domain/NoDomain.hx b/src/hex/domain/NoDomain.hx index 4933ce7..4350197 100644 --- a/src/hex/domain/NoDomain.hx +++ b/src/hex/domain/NoDomain.hx @@ -1,7 +1,5 @@ package hex.domain; -import hex.domain.Domain; - /** * ... * @author Francis Bourre diff --git a/src/hex/module/ModuleMessage.hx b/src/hex/module/ModuleMessage.hx index 4581bc4..f61e738 100644 --- a/src/hex/module/ModuleMessage.hx +++ b/src/hex/module/ModuleMessage.hx @@ -1,5 +1,6 @@ package hex.module; +import hex.error.PrivateConstructorException; import hex.event.MessageType; /** @@ -11,8 +12,9 @@ class ModuleMessage inline public static var INITIALIZED = new MessageType( "onModuleInitialisation" ); inline public static var RELEASED = new MessageType( "onModuleRelease" ); + /** @private */ function new() { - + throw new PrivateConstructorException(); } } \ No newline at end of file diff --git a/src/hex/util/MacroUtil.hx b/src/hex/util/MacroUtil.hx index 137b005..9ade916 100644 --- a/src/hex/util/MacroUtil.hx +++ b/src/hex/util/MacroUtil.hx @@ -6,6 +6,7 @@ import haxe.macro.Expr.TypeParam; import haxe.macro.Expr.TypePath; import haxe.macro.Type.ClassType; import haxe.macro.TypeTools; +import hex.error.PrivateConstructorException; /** * ... @@ -13,10 +14,11 @@ import haxe.macro.TypeTools; */ class MacroUtil { - function new() - { - - } + /** @private */ + function new() + { + throw new PrivateConstructorException(); + } macro public static function classImplementsInterface( classRef : haxe.macro.Expr.ExprOf, interfaceRef : haxe.macro.Expr.ExprOf ) : Expr { diff --git a/src/hex/util/PerformanceUtil.hx b/src/hex/util/PerformanceUtil.hx deleted file mode 100644 index f3f7560..0000000 --- a/src/hex/util/PerformanceUtil.hx +++ /dev/null @@ -1,72 +0,0 @@ -package hex.util; - -/** - * ... - * @author duke - */ -class PerformanceUtil -{ - static var timers = new Map(); - - /** - * Start speed test. - * @param name Name of test. - */ - public static function startTimer( name : String = "test" ) : Void - { - PerformanceUtil.timers[ name ] = new PerformanceVO( Date.now().getTime(), getMemory() ); - trace( "*** TEST STARTED: " + name + " ***" ); - } - - /** - * Stop speed test. It outputs the result - * @param name The name of started test. - */ - public static function stopTimer( name : String = "test") : Void - { - if ( PerformanceUtil.timers[ name ] != null ) - { - trace( "*** TEST FINISHED: " + name + " time: " + - ( Date.now().getTime() - PerformanceUtil.timers[ name ].startTime ) + " ms memory: " + - ( Math.round( ( PerformanceUtil.getMemory() - PerformanceUtil.timers[ name ].memory ) / 1024 * 100) / 100 ) + " KB ***" ); - - PerformanceUtil.timers.remove( name ); - } - else - { - trace( "*** NO TEST FOUND: " + name + " ***" ); - } - } - - static function getMemory( ):Float - { - #if flash - return flash.system.System.totalMemory; - #elseif js - if ( Reflect.hasField(js.Browser.window, "performance" ) ) - { - var perf:Dynamic = Reflect.field(js.Browser.window, "performance" ); - return Reflect.hasField(perf, "memory") ? Reflect.field(Reflect.field( perf, "memory"), "totalJSHeapSize") : null; //usedJSHeapSize - } - else - { - return 0; - } - #else - return 0; - #end - } - -} - -private class PerformanceVO -{ - public var memory : Float; - public var startTime : Float; - - public function new( startTime : Float, memory : Float ) - { - this.startTime = startTime; - this.memory = memory; - } -} \ No newline at end of file diff --git a/test/hex/HexCoreSuite.hx b/test/hex/HexCoreSuite.hx index 8587c0a..bdbfc78 100644 --- a/test/hex/HexCoreSuite.hx +++ b/test/hex/HexCoreSuite.hx @@ -8,6 +8,7 @@ import hex.di.CoreDiSuite; import hex.domain.CoreDomainSuite; import hex.event.CoreEventSuite; import hex.model.CoreModelSuite; +import hex.module.CoreModuleSuite; import hex.service.CoreServiceSuite; import hex.structures.CoreStructuresSuite; import hex.util.CoreUtilSuite; @@ -19,5 +20,19 @@ import hex.util.CoreUtilSuite; class HexCoreSuite { @Suite( "HexCore" ) - public var list : Array> = [ CoreCollectionSuite, CoreControlSuite, CoreCoreSuite, CoreDataSuite, CoreDiSuite, CoreDomainSuite, CoreEventSuite, CoreModelSuite, CoreServiceSuite, CoreStructuresSuite, CoreUtilSuite ]; + public var list : Array> = + [ + CoreCollectionSuite, + CoreControlSuite, + CoreCoreSuite, + CoreDataSuite, + CoreDiSuite, + CoreDomainSuite, + CoreEventSuite, + CoreModelSuite, + CoreModuleSuite, + CoreServiceSuite, + CoreStructuresSuite, + CoreUtilSuite + ]; } diff --git a/test/hex/collection/LocatorMessageTest.hx b/test/hex/collection/LocatorMessageTest.hx index a9b9822..de30dfd 100644 --- a/test/hex/collection/LocatorMessageTest.hx +++ b/test/hex/collection/LocatorMessageTest.hx @@ -1,6 +1,5 @@ package hex.collection; -import hex.event.MessageType; import hex.unittest.assertion.Assert; /** @@ -9,6 +8,12 @@ import hex.unittest.assertion.Assert; */ class LocatorMessageTest { + @Test( "test constructor is private" ) + public function testPrivateConstructor() : Void + { + Assert.constructorIsPrivate( LocatorMessage ); + } + @Test( "test 'REGISTER' property" ) public function testRegisterProperty() : Void { diff --git a/test/hex/control/AsyncHandlerUtilTest.hx b/test/hex/control/AsyncHandlerUtilTest.hx index 77c97aa..8cc4c57 100644 --- a/test/hex/control/AsyncHandlerUtilTest.hx +++ b/test/hex/control/AsyncHandlerUtilTest.hx @@ -16,6 +16,12 @@ class AsyncHandlerUtilTest { var result : Int; + @Test( "test constructor is private" ) + public function testPrivateConstructor() : Void + { + Assert.constructorIsPrivate( AsyncHandlerUtil ); + } + @Test( "test simple lambda" ) public function testSimpleLambda() { diff --git a/test/hex/control/payload/PayloadUtilTest.hx b/test/hex/control/payload/PayloadUtilTest.hx index 4f054ae..a41fc8c 100644 --- a/test/hex/control/payload/PayloadUtilTest.hx +++ b/test/hex/control/payload/PayloadUtilTest.hx @@ -13,6 +13,12 @@ import hex.unittest.assertion.Assert; */ class PayloadUtilTest { + @Test( "test constructor is private" ) + public function testPrivateConstructor() : Void + { + Assert.constructorIsPrivate( PayloadUtil ); + } + @Test( "Test mapping" ) public function testMapping() : Void { diff --git a/test/hex/core/HashCodeFactoryTest.hx b/test/hex/core/HashCodeFactoryTest.hx index 1323510..417580c 100644 --- a/test/hex/core/HashCodeFactoryTest.hx +++ b/test/hex/core/HashCodeFactoryTest.hx @@ -5,6 +5,12 @@ import hex.unittest.assertion.Assert; class HashCodeFactoryTest { + @Test( "test constructor is private" ) + public function testPrivateConstructor() : Void + { + Assert.constructorIsPrivate( HashCodeFactory ); + } + @Test( "Test constructor can't be called" ) public function testConstructorNullException() : Void { diff --git a/test/hex/data/GUIDTest.hx b/test/hex/data/GUIDTest.hx index 6248c9d..2c8b2cb 100644 --- a/test/hex/data/GUIDTest.hx +++ b/test/hex/data/GUIDTest.hx @@ -8,6 +8,12 @@ import hex.unittest.assertion.Assert; */ class GUIDTest { + @Test( "test constructor is private" ) + public function testPrivateConstructor() : Void + { + Assert.constructorIsPrivate( GUID ); + } + @Test( "Test randomIntegerWithinRange function" ) public function testRandomIntegerWithinRange() : Void { diff --git a/test/hex/domain/DomainUtilTest.hx b/test/hex/domain/DomainUtilTest.hx index abca3ed..b08b090 100644 --- a/test/hex/domain/DomainUtilTest.hx +++ b/test/hex/domain/DomainUtilTest.hx @@ -8,6 +8,12 @@ import hex.unittest.assertion.Assert; */ class DomainUtilTest { + @Test( "test constructor is private" ) + public function testPrivateConstructor() : Void + { + Assert.constructorIsPrivate( DomainUtil ); + } + @Test( "Test 'getDomain' method" ) public function testDomainCreation() : Void { diff --git a/test/hex/module/CoreModuleSuite.hx b/test/hex/module/CoreModuleSuite.hx new file mode 100644 index 0000000..24ffc85 --- /dev/null +++ b/test/hex/module/CoreModuleSuite.hx @@ -0,0 +1,11 @@ +package hex.module; + +/** + * ... + * @author Francis Bourre + */ +class CoreModuleSuite +{ + @Suite( "Module" ) + public var list : Array> = [ ModuleMessageTest ]; +} \ No newline at end of file diff --git a/test/hex/module/ModuleMessageTest.hx b/test/hex/module/ModuleMessageTest.hx new file mode 100644 index 0000000..33567ba --- /dev/null +++ b/test/hex/module/ModuleMessageTest.hx @@ -0,0 +1,30 @@ +package hex.module; + +import hex.unittest.assertion.Assert; + +/** + * ... + * @author Francis Bourre + */ +class ModuleMessageTest +{ + @Test( "test constructor is private" ) + public function testPrivateConstructor() : Void + { + Assert.constructorIsPrivate( ModuleMessage ); + } + + @Test( "test 'INITIALIZED' property" ) + public function testInitializedProperty() : Void + { + var message = ModuleMessage.INITIALIZED; + Assert.equals( "onModuleInitialisation", message ); + } + + @Test( "test 'RELEASED' property" ) + public function testReleasedProperty() : Void + { + var message = ModuleMessage.RELEASED; + Assert.equals( "onModuleRelease", message ); + } +} \ No newline at end of file diff --git a/test/hex/util/ClassUtilTest.hx b/test/hex/util/ClassUtilTest.hx index 98b9a11..e42bbed 100644 --- a/test/hex/util/ClassUtilTest.hx +++ b/test/hex/util/ClassUtilTest.hx @@ -11,6 +11,12 @@ class ClassUtilTest { public static inline var STATIC_REF : String = "static_ref"; + @Test( "test constructor is private" ) + public function testPrivateConstructor() : Void + { + Assert.constructorIsPrivate( ClassUtil ); + } + @Test( "Test getClassReference" ) public function testGetClassReference() : Void { From d31bd6715bfc3c3ace184d6c92042561fcd43001 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Wed, 22 Feb 2017 14:00:55 +0100 Subject: [PATCH 07/25] Removed some useless log layouts and added more code coverage --- src/hex/collection/HashMap.hx | 2 +- src/hex/error/Exception.hx | 2 +- src/hex/error/IllegalArgumentException.hx | 1 + src/hex/error/IllegalStateException.hx | 1 + src/hex/error/NoSuchElementException.hx | 1 + src/hex/error/NullPointerException.hx | 1 + src/hex/error/PrivateConstructorException.hx | 1 + .../error/UnsupportedOperationException.hx | 1 + src/hex/error/VirtualMethodException.hx | 1 + src/hex/log/layout/LogLayoutHTMLView.hx | 431 ------------------ src/hex/log/layout/LogProxyLayout.hx | 133 ------ src/hex/log/layout/SimpleBrowserLayout.hx | 171 ------- test/hex/HexCoreSuite.hx | 2 + test/hex/collection/HashMapTest.hx | 48 ++ test/hex/collection/LocatorTest.hx | 16 +- test/hex/error/CoreErrorSuite.hx | 14 + test/hex/error/ExceptionTest.hx | 20 + 17 files changed, 108 insertions(+), 738 deletions(-) delete mode 100644 src/hex/log/layout/LogLayoutHTMLView.hx delete mode 100644 src/hex/log/layout/LogProxyLayout.hx delete mode 100644 src/hex/log/layout/SimpleBrowserLayout.hx create mode 100644 test/hex/error/CoreErrorSuite.hx create mode 100644 test/hex/error/ExceptionTest.hx diff --git a/src/hex/collection/HashMap.hx b/src/hex/collection/HashMap.hx index 9020e4e..d8a299e 100644 --- a/src/hex/collection/HashMap.hx +++ b/src/hex/collection/HashMap.hx @@ -176,7 +176,7 @@ class HashMap implements IHashMap { s = '_B' + o; } - else if ( Std.is( o, Float ) || Std.is( o, Int ) ) + else if ( Std.is( o, Float ) ) { s = '_N' + o; } diff --git a/src/hex/error/Exception.hx b/src/hex/error/Exception.hx index a2cab18..5d4ac5f 100644 --- a/src/hex/error/Exception.hx +++ b/src/hex/error/Exception.hx @@ -1,8 +1,8 @@ package hex.error; +import haxe.PosInfos; import hex.log.Logger; import hex.log.Stringifier; -import haxe.PosInfos; /** * ... diff --git a/src/hex/error/IllegalArgumentException.hx b/src/hex/error/IllegalArgumentException.hx index 0922dc8..9aedf8d 100644 --- a/src/hex/error/IllegalArgumentException.hx +++ b/src/hex/error/IllegalArgumentException.hx @@ -6,6 +6,7 @@ import haxe.PosInfos; * ... * @author Francis Bourre */ +@IgnoreCover class IllegalArgumentException extends Exception { public function new ( message : String, ?posInfos : PosInfos ) diff --git a/src/hex/error/IllegalStateException.hx b/src/hex/error/IllegalStateException.hx index a8caffc..052e38e 100644 --- a/src/hex/error/IllegalStateException.hx +++ b/src/hex/error/IllegalStateException.hx @@ -6,6 +6,7 @@ import haxe.PosInfos; * ... * @author Francis Bourre */ +@IgnoreCover class IllegalStateException extends Exception { public function new ( message : String, ?posInfos : PosInfos ) diff --git a/src/hex/error/NoSuchElementException.hx b/src/hex/error/NoSuchElementException.hx index e7f30c7..ab8aaa4 100644 --- a/src/hex/error/NoSuchElementException.hx +++ b/src/hex/error/NoSuchElementException.hx @@ -6,6 +6,7 @@ import haxe.PosInfos; * ... * @author Francis Bourre */ +@IgnoreCover class NoSuchElementException extends Exception { public function new ( message : String, ?posInfos : PosInfos ) diff --git a/src/hex/error/NullPointerException.hx b/src/hex/error/NullPointerException.hx index aeba096..c63ba4e 100644 --- a/src/hex/error/NullPointerException.hx +++ b/src/hex/error/NullPointerException.hx @@ -6,6 +6,7 @@ import haxe.PosInfos; * ... * @author Francis Bourre */ +@IgnoreCover class NullPointerException extends Exception { public function new ( message : String, ?posInfos : PosInfos ) diff --git a/src/hex/error/PrivateConstructorException.hx b/src/hex/error/PrivateConstructorException.hx index 7552b2c..ee517de 100644 --- a/src/hex/error/PrivateConstructorException.hx +++ b/src/hex/error/PrivateConstructorException.hx @@ -6,6 +6,7 @@ import haxe.PosInfos; * ... * @author Francis Bourre */ +@IgnoreCover class PrivateConstructorException extends Exception { public function new ( ?message : String = "This class can't be instantiated.", ?posInfos : PosInfos ) diff --git a/src/hex/error/UnsupportedOperationException.hx b/src/hex/error/UnsupportedOperationException.hx index 499595a..bda02ae 100644 --- a/src/hex/error/UnsupportedOperationException.hx +++ b/src/hex/error/UnsupportedOperationException.hx @@ -6,6 +6,7 @@ import haxe.PosInfos; * ... * @author Francis Bourre */ +@IgnoreCover class UnsupportedOperationException extends Exception { public function new ( message : String, ?posInfos : PosInfos ) diff --git a/src/hex/error/VirtualMethodException.hx b/src/hex/error/VirtualMethodException.hx index 0946cf2..b5f2152 100644 --- a/src/hex/error/VirtualMethodException.hx +++ b/src/hex/error/VirtualMethodException.hx @@ -6,6 +6,7 @@ import haxe.PosInfos; * ... * @author Francis Bourre */ +@IgnoreCover class VirtualMethodException extends Exception { public function new ( ?message : String = 'this method must be overridden', ?posInfos : PosInfos ) diff --git a/src/hex/log/layout/LogLayoutHTMLView.hx b/src/hex/log/layout/LogLayoutHTMLView.hx deleted file mode 100644 index 1f76cbc..0000000 --- a/src/hex/log/layout/LogLayoutHTMLView.hx +++ /dev/null @@ -1,431 +0,0 @@ -package hex.log.layout; - -#if js -import hex.domain.Domain; -import hex.log.layout.LogProxyLayout; -import js.html.DOMRect; -import js.html.Element; -import js.html.Event; -import js.html.HTMLDocument; -import js.html.InputElement; -import js.html.KeyboardEvent; -import js.html.SelectElement; -import js.html.TouchEvent; - -/** - * ... - * @author Francis Bourre - */ -class LogLayoutHTMLView -{ - static var TAP_THRESHOLD : UInt = 250; - - var _console : Element; - var _proxy : LogProxyLayout; - - var _toggleStartPosition : Array = [ 0, 0 ]; - var _transformPosition : Array = [ 0, 0 ]; - var _changePosition : Array = [ 0, 0 ]; - var _toggleButtonRect : DOMRect; - var _toggleBtnCenter : Array; - - var _swipeHorizontalVO : SwipeHorizontalVO = new SwipeHorizontalVO(); - - var _debugWrapperSelector : String; - - var _debugConsole : Element; - var _list : Element; - var _wrapper : Element; - var _toggleButton : Element; - var _leftArrowButton : Element; - var _rightArrowButton : Element; - - var _searchInput : InputElement; - var _domainInput : InputElement; - var _levelSelector : SelectElement; - - var _tapStartTime : Float; - var _levels : Map = new Map(); - - var _searchLength : Int = 0; - var _searchIndex : Int = 0; - - public var consoleWrapperTaget : String = ".debug-console-list-wrapper"; - - public function new( proxy : LogProxyLayout, wrapperSelector:String = "body" ) - { - this._proxy = proxy; - this._debugWrapperSelector = wrapperSelector; - this._init(); - } - - function _init() : Void - { - _buildView(); - _buildBehavior(); - } - - inline function _buildView():Void - { - var document : HTMLDocument = js.Browser.window.document; - var container:Element = document.querySelector(this._debugWrapperSelector); - - var debugWrapper = document.createDivElement(); - debugWrapper.style.position = "fixed"; - debugWrapper.innerHTML = ConsoleStyle.template; - container.appendChild(debugWrapper); - - var debugStyle = document.createStyleElement(); - debugStyle.innerHTML = ConsoleStyle.style; - container.appendChild(debugStyle); - - this._debugConsole = document.querySelector('.debug-console'); - this._list = document.querySelector('.debug-console-list'); - this._wrapper = document.querySelector('.debug-console-list-wrapper'); - this._toggleButton = document.querySelector('.debug-console-toggle'); - this._leftArrowButton = document.querySelector('.debug-console-control-caret--left'); - this._rightArrowButton = document.querySelector('.debug-console-control-caret--right'); - - this._searchInput = cast document.querySelector('.debug-console-control-item--search input'); - this._domainInput = cast document.querySelector('.debug-console-control-item--domain input'); - this._levelSelector = cast document.querySelector('.debug-console-control-item--level select'); - - for ( level in LogLevel.LEVELS ) - { - var option = document.createOptionElement(); - option.innerHTML = level.toString(); - option.value = level.toString(); - this._levels.set( level.toString(), level ); - this._levelSelector.appendChild( option ); - } - - this._toggleButtonRect = this._toggleButton.getBoundingClientRect(); - this._toggleBtnCenter = [ this._toggleButtonRect.width / 2, this._toggleButtonRect.height / 2]; - } - - inline function _buildBehavior():Void - { - this._leftArrowButton.addEventListener( 'click', this._onPreviousSearchButtonClick ); - this._rightArrowButton.addEventListener( 'click', this._onNextSearchButtonClick ); - this._toggleButton.addEventListener( 'click', this._toggleDebugConsole ); - this._toggleButton.addEventListener( 'touchstart', this._onToggleButtonTouchStart ); - this._toggleButton.addEventListener( 'touchmove', this._onToggleButtonTouchMove ); - this._toggleButton.addEventListener( 'touchend', this._onToggleButtonTouchEnd ); - - this._wrapper.addEventListener( 'touchstart', this._onWrapperTouchStart ); - this._wrapper.addEventListener( 'touchmove', this._onWrapperTouchMove ); - this._wrapper.addEventListener( 'touchend', this._onWrapperTouchEnd ); - - this._searchInput.addEventListener( "input", this._onSearchStart ); - this._searchInput.addEventListener("keypress", this._onSearchKeyPress); - this._domainInput.addEventListener( "input", this._onSetDomain ); - - this._levelSelector.addEventListener( "change", this._onChangeLevel ); - } - - function _onSearchStart( e : Event ) : Void - { - this._searchIndex = 0; - this._searchLength = 0; - if (this._searchInput.value.length < 2) return; - - this._searchLength = this._proxy.searchFor( this._searchInput.value, '', '' ); - if ( this._searchLength > 0 ) - { - js.Browser.window.document.getElementById( "searchedWord" + this._searchIndex ).scrollIntoView(); - } - } - - function _onSearchKeyPress( e : KeyboardEvent ) : Void - { - if (e.shiftKey && e.keyCode == KeyboardEvent.DOM_VK_RETURN) - { - this._onPreviousSearchButtonClick(e); - } else if(e.keyCode == KeyboardEvent.DOM_VK_RETURN) - { - this._onNextSearchButtonClick(e); - } - } - - function _onSetDomain( e : Event ) : Void - { - if (this._levelSelector.value.length < 2) return; - this._proxy.filter( this._levels.get( this._levelSelector.value ), Domain.getDomain( this._domainInput.value ) ); - } - - function _onChangeLevel( e : Event ) : Void - { - this._proxy.filter( this._levels.get( this._levelSelector.value ), Domain.getDomain( this._domainInput.value ) ); - } - - function _onToggleButtonTouchStart( e : TouchEvent ) : Void - { - e.preventDefault(); - this._toggleStartPosition = [ e.touches[ 0 ].pageX, e.touches[ 0 ].pageY ]; - this._changePosition = this._transformPosition; - - this._tapStartTime = ( Date.now() ).getTime(); - } - - function _onToggleButtonTouchMove( e : TouchEvent ) : Void - { - e.stopPropagation(); - e.preventDefault(); - - var touchList = e.touches[ 0 ]; - - this._changePosition = - [ - this._transformPosition[ 0 ] + touchList.pageX - this._toggleStartPosition[ 0 ], - this._transformPosition[ 1 ] + touchList.pageY - this._toggleStartPosition[ 1 ] - ]; - - this._toggleButton.style.transform = 'translate(' + _changePosition[ 0 ] + 'px, ' + _changePosition[ 1 ] + 'px)'; - } - - function _onToggleButtonTouchEnd( e : TouchEvent ) : Void - { - this._transformPosition[ 0 ] = this._changePosition[ 0 ]; - this._transformPosition[ 1 ] = this._changePosition[ 1 ]; - - if ( ( Date.now() ).getTime() - this._tapStartTime < LogLayoutHTMLView.TAP_THRESHOLD ) - { - this._toggleDebugConsole(); - } - } - - function _onWrapperTouchStart( e : TouchEvent ) : Void - { - var t = e.touches.item(0); - _swipeHorizontalVO.startX = t.screenX; - _swipeHorizontalVO.startY = t.screenY; - } - - function _onWrapperTouchMove( e : TouchEvent ) : Void - { - var t = e.touches.item(0); - _swipeHorizontalVO.endX = t.screenX; - _swipeHorizontalVO.endY = t.screenY; - } - - function _onWrapperTouchEnd( e : TouchEvent ) : Void - { - if ((((this._swipeHorizontalVO.endX - SwipeHorizontalVO.MIN_X > this._swipeHorizontalVO.startX) || (this._swipeHorizontalVO.endX + SwipeHorizontalVO.MIN_X < this._swipeHorizontalVO.startX)) && ((this._swipeHorizontalVO.endY < this._swipeHorizontalVO.startY + SwipeHorizontalVO.MAX_Y) && (this._swipeHorizontalVO.startY > this._swipeHorizontalVO.endY - SwipeHorizontalVO.MAX_Y) && (this._swipeHorizontalVO.endX > 0)))) { - if (_swipeHorizontalVO.endX > _swipeHorizontalVO.startX) - { - this._onNextSearchButtonClick(e); - } - else - { - this._onPreviousSearchButtonClick(e); - } - } - - this._swipeHorizontalVO.startX = this._swipeHorizontalVO.startY = this._swipeHorizontalVO.endX = this._swipeHorizontalVO.endY = 0; - } - - function _toggleDebugConsole() : Void - { - this._debugConsole.classList.toggle( 'hidden' ); - } - - function _onPreviousSearchButtonClick( e : Event ) : Void - { - e.stopPropagation(); - e.preventDefault(); - - if ( this._searchLength > 0 ) - { - this._removeSelectedClass(); - this._searchIndex = this._searchIndex > 0 ? this._searchIndex -1 : this._searchLength -1; - this._refreshSelectedItem(); - } - } - - function _onNextSearchButtonClick( e : Event ) : Void - { - e.stopPropagation(); - e.preventDefault(); - - if ( this._searchLength > 0 ) - { - this._removeSelectedClass(); - this._searchIndex = this._searchIndex < this._searchLength -1 ? this._searchIndex +1 : 0; - this._refreshSelectedItem(); - } - } - - function _removeSelectedClass() : Void - { - var item = js.Browser.window.document.getElementById( "searchedWord" + this._searchIndex ); - item.parentElement.parentElement.classList.remove("selected"); - } - - function _refreshSelectedItem():Void - { - var item = js.Browser.window.document.getElementById( "searchedWord" + this._searchIndex ); - item.scrollIntoView(); - item.parentElement.parentElement.classList.add("selected"); - } -} - -class SwipeHorizontalVO -{ - public static var MIN_X : Int = 30; //min x swipe for horizontal swipe - public static var MAX_X : Int = 30; //max x difference for vertical swipe - public static var MIN_Y : Int = 50; //min y swipe for vertical swipe - public static var MAX_Y : Int = 60; //max y difference for horizontal swipe - - public var startX : Int = 0; - public var startY : Int = 0; - public var endX : Int = 0; - public var endY : Int = 0; - - public function new() {} -} - -class ConsoleStyle -{ - public static var template = ' - - -'; - public static var style = ' -html, -body, -.debug-console { - margin: 0; - height: 100%; - width: 100%; -} - -.debug-console-toggle { - position: fixed; - z-index: 1001; - left: 10px; - top: 10px; -} - -.debug-console { - position: fixed; - z-index: 1000; - top: 0; - right: 0; - bottom: 0; - left: 0; - background: rgba(0, 0, 0, 0.8); -} - -.debug-console.hidden { - display: none; -} - -.debug-console, -.debug-console-list-wrapper, -.debug-console-control { - box-sizing: border-box; -} - -.debug-console-list-wrapper, -.debug-console-control { - position: absolute; - left: 0; - right: 0; -} - -.debug-console-list-wrapper { - top: 0; - height: calc(100% - 24px); - -webkit-overflow-scrolling: touch; - overflow-x: hidden; - overflow-y: scroll; -} - -.debug-console-list { - padding: 0; - margin: 10px; - list-style: none; -} - -.debug-console-list li { - margin: 0 0 2px 0; - color: lime; -} - -.debug-console-control { - bottom: 0; - height: 30px; - letter-spacing: -0.3125em; - padding: 5px 0% 5px 5px; -} - -.debug-console-control-item, -.debug-console-control-item--search .debug-console-control-item-input, -.debug-console-control-caret { - display: inline-block; - vertical-align: top; - letter-spacing: normal; - word-spacing: normal; - box-sizing: border-box; -} - -.debug-console-control-item { - padding-right: 1%; -} - -.debug-console-control-item-input { - box-sizing: border-box; - height: 20px; - line-height: 20px; - width: 100%; -} - -.debug-console-control-item--search { - letter-spacing: -0.3125em; -} - -.debug-console-control-caret--left { - width: 24px; - margin-right: 4px; -} -.debug-console-control-caret--right { - width: 24px; - margin-left: 4px; -} - -.debug-console-control-item--search { - width: 50%; - padding: 0 8px 0 0; -} - -.debug-console-control-item--search .debug-console-control-item-input { - width: calc(100% - 56px); -} - -.debug-console-control-item--domain, -.debug-console-control-item--level { - width: 25%; -} - -.highlight-word { background-color:#FFFF00; } - -.selected { background-color:#999900 } -'; -} -#end \ No newline at end of file diff --git a/src/hex/log/layout/LogProxyLayout.hx b/src/hex/log/layout/LogProxyLayout.hx deleted file mode 100644 index f9f0ffa..0000000 --- a/src/hex/log/layout/LogProxyLayout.hx +++ /dev/null @@ -1,133 +0,0 @@ -package hex.log.layout; - -import hex.domain.Domain; -import hex.domain.DomainUtil; -import hex.log.ILogListener; -import hex.log.LogLevel; -import hex.log.LoggerMessage; -import hex.model.ModelDispatcher; - -/** - * ... - * @author Francis Bourre - */ -class LogProxyLayout implements ILogListener -{ - private var _leftSearchSeparator : String; - private var _rightSearchSeparator : String; - - var _dispatcher : LogProxyLayoutDispatcher; - var _messages : Array; - var _filteredLevel : LogLevel; - var _filteredDomain : Domain; - - var _searchedWord : String = ""; - - public function new() - { - this._dispatcher = new LogProxyLayoutDispatcher(); - this._messages = []; - - this._filteredLevel = LogLevel.ALL; - this._filteredDomain = AllDomain.DOMAIN; - - Logger.getInstance().addListener( this ); - } - - public function onClear() : Void - { - this._dispatcher.onClear(); - } - - public function onLog( message : LoggerMessage ) : Void - { - //Create message - this._messages.push( message ); - - //Dispatch message - if ( ( this._filteredDomain == AllDomain.DOMAIN || this._filteredDomain == message.domain) && - ( this._filteredLevel == LogLevel.ALL || this._filteredLevel == message.level ) ) - { - this._dispatcher.onLog( message ); - } - } - - public function addListener( listener : ILogListener ) : Bool - { - return this._dispatcher.addListener( listener ); - } - - public function removeListener( listener : ILogListener) : Bool - { - return this._dispatcher.removeListener( listener ); - } - - public function filter( ?level : LogLevel, ?domain : Domain ) : Void - { - this._filteredLevel = level == null ? LogLevel.ALL : level; - this._filteredDomain = domain == null ? AllDomain.DOMAIN : domain; - this._dispatcher.onClear(); - this._render(); - } - - public function searchFor( word : String = "", leftSearchSeparator : String, rightSearchSeparator : String ) : Int - { - this._searchedWord = word; - this._leftSearchSeparator = leftSearchSeparator; - this._rightSearchSeparator = rightSearchSeparator; - this._dispatcher.onClear(); - - return this._render(); - } - - function _render() : Int - { - var searchLength : Int = 0; - - for ( message in this._messages ) - { - if ( ( this._filteredDomain == AllDomain.DOMAIN || this._filteredDomain == message.domain) && - ( this._filteredLevel == LogLevel.ALL || this._filteredLevel == message.level ) ) - { - var messageContent : String = "" + message.message; - if ( this._searchedWord.length > 0 && messageContent.indexOf( this._searchedWord ) != -1 ) - { - messageContent = ( messageContent.split( this._searchedWord ) ) - .join( this._getLeftSeparator( searchLength, this._leftSearchSeparator ) + this._searchedWord + this._rightSearchSeparator ); - searchLength++; - } - this._dispatcher.onLog( new LoggerMessage( messageContent, message.level, message.domain, message.posInfos ) ); - } - } - - return searchLength; - } - - function _getLeftSeparator( index : Int, separator : String ) : String - { - return separator.split( ">" ).join( " id='searchedWord" + index ) + "'>"; - } -} - -class AllDomain extends Domain -{ - public static var DOMAIN : AllDomain = DomainUtil.getDomain( "AllDomain", AllDomain ); -} - -class LogProxyLayoutDispatcher extends ModelDispatcher implements ILogListener -{ - public function new() - { - super(); - } - - public function onClear() : Void - { - - } - - public function onLog( message : LoggerMessage ) : Void - { - - } -} \ No newline at end of file diff --git a/src/hex/log/layout/SimpleBrowserLayout.hx b/src/hex/log/layout/SimpleBrowserLayout.hx deleted file mode 100644 index 816828b..0000000 --- a/src/hex/log/layout/SimpleBrowserLayout.hx +++ /dev/null @@ -1,171 +0,0 @@ -package hex.log.layout; - -#if js -import haxe.PosInfos; -import hex.domain.Domain; -import hex.error.NullPointerException; -import hex.log.LogLevel; -import hex.log.LoggerMessage; -import js.Browser; -import js.html.Element; -import js.html.SpanElement; - -/** - * ... - * @author Francis Bourre - */ -class SimpleBrowserLayout implements ILogListener -{ - var _console : Element; - var _levelStyle : Map; - - var _levelDisplay : Bool = true; - var _domainDisplay : Bool = true; - var _timeDisplay : Bool = true; - - public function new( targetID : String = "console", leveldisplay : Bool = true, domainDisplay : Bool = true, timeDisplay : Bool = true ) - { - this._setConsole( targetID ); - this.setDomainDisplay( domainDisplay ); - this.setLevelDisplay( leveldisplay ); - this.setDisplayTime( timeDisplay ); - - this._createLevelStyle(); - } - - public function setLevelDisplay( b : Bool ) : Void - { - this._levelDisplay = b; - } - - public function setDomainDisplay( b : Bool ) : Void - { - this._domainDisplay = b; - } - - public function setDisplayTime( b : Bool ) : Void - { - this._timeDisplay = b; - } - - function _createLevelStyle() - { - this._levelStyle = new Map(); - - this._levelStyle.set( LogLevel.DEBUG, "lightgrey" ); - this._levelStyle.set( LogLevel.INFO, "green" ); - this._levelStyle.set( LogLevel.WARN, "yellow" ); - this._levelStyle.set( LogLevel.ERROR, "orange" ); - this._levelStyle.set( LogLevel.FATAL, "red" ); - } - - function _setConsole( targetId : String ) : Void - { - this._console = Browser.document.querySelector( targetId ); - - if ( this._console == null ) - { - throw new NullPointerException( "Div named '" + targetId + "' was not found in '" + Stringifier.stringify( this ) + "'" ); - } - - this._console.style.whiteSpace = "pre"; - this._console.style.fontFamily = "Lucida Console"; - this._console.style.fontSize = "11px"; - } - - public function onLog( loggerMessage : LoggerMessage ) : Void - { - var message : Dynamic = loggerMessage.message; - var level : LogLevel = loggerMessage.level; - var domain : Domain = loggerMessage.domain; - var posInfos : PosInfos = loggerMessage.posInfos; - - var leftBracket = this._createElement( "[", this._getStyle( level ) ); - var rightBracket = this._createElement( "]", this._getStyle( level ) ); - var time = this._createElement( this._getTime(), this._getStyle( level ) ); - var levelName = this._createElement( level.toString(), this._getStyle( level ) + "+bold" ); - var domainName : String = ( domain != null && domain.getName() != null ) ? "@" + domain.getName() : ""; - var domain = this._createElement( domainName, this._getStyle( level ) ); - var message = this._createElement( "\t\t" + message, this._getStyle( level ) ); - var info = this._createElement( posInfos != null ? " at " + posInfos.className + "::" + posInfos.methodName + " line " + posInfos.lineNumber + " in file " + posInfos.fileName : "", this._getStyle( level ) ); - - this._log( this._getEncapsulateElements( [ leftBracket, levelName, domain, rightBracket, message, info] ) ); - } - - public function onClear() : Void - { - this._console.innerHTML = ""; - } - - function _getTime() : String - { - return "" + Date.now().getTime(); - } - - function _getStyle( level : LogLevel ) : String - { - return this._levelStyle.get( level ); - } - - function _log( element : Element ) : Void - { - element.style.marginLeft = "10px"; - element.appendChild( Browser.document.createTextNode("\n") ); - this._console.appendChild( element ); - this._console.scrollTop = this._console.scrollHeight; - } - - function _createElement( message : String, ?color : String ) : Element - { - var span : SpanElement = Browser.document.createSpanElement(); - span.innerHTML = message; - if ( color != null ) this._setAttributes( span, color ); - return span; - } - - function _getEncapsulateElements( elementList : Array ) : Element - { - var container : SpanElement = Browser.document.createSpanElement(); - - for ( element in elementList ) - { - container.appendChild( element ); - } - - return container; - } - - function _setAttributes( element : Element, color : String ) : Void - { - var colorAttributes : Array = color.split( "+" ); - for ( attr in colorAttributes ) - { - this._setAttribute( element, attr ); - } - } - - function _setAttribute( element:Element, attr:String ) : Void - { - switch( attr ) - { - case "bold": - element.style.fontWeight = "bold"; - - case "red": - element.style.color = "#e62323"; - - case "orange": - element.style.color = "#FF8000"; - - case "yellow": - element.style.color = "#ffcf18"; - - case "lightgrey": - element.style.color = "#d9d9d9"; - - case "green": - element.style.color = "#27fe11"; - } - } -} -#end \ No newline at end of file diff --git a/test/hex/HexCoreSuite.hx b/test/hex/HexCoreSuite.hx index bdbfc78..d1d3363 100644 --- a/test/hex/HexCoreSuite.hx +++ b/test/hex/HexCoreSuite.hx @@ -7,6 +7,7 @@ import hex.data.CoreDataSuite; import hex.di.CoreDiSuite; import hex.domain.CoreDomainSuite; import hex.event.CoreEventSuite; +import hex.error.CoreErrorSuite; import hex.model.CoreModelSuite; import hex.module.CoreModuleSuite; import hex.service.CoreServiceSuite; @@ -29,6 +30,7 @@ class HexCoreSuite CoreDiSuite, CoreDomainSuite, CoreEventSuite, + CoreErrorSuite, CoreModelSuite, CoreModuleSuite, CoreServiceSuite, diff --git a/test/hex/collection/HashMapTest.hx b/test/hex/collection/HashMapTest.hx index 6f0db65..e33f802 100644 --- a/test/hex/collection/HashMapTest.hx +++ b/test/hex/collection/HashMapTest.hx @@ -76,6 +76,54 @@ class HashMapTest Assert.methodCallThrows( NullPointerException, this._map, this._map.put, [mockKey, null], "'put' should throw NullPointerException" ); } + @Test( "Test 'put' and 'get' behaviors with Int" ) + public function testPutAndGetWithInt() : Void + { + var map = new HashMap(); + var mockKey = 3; + var mockValue = 4; + + var value = map.put( mockKey, mockValue ); + Assert.isNull( value, "'put' should return null when key was never registered" ); + Assert.equals( mockValue, map.get( mockKey ), "'get' should return value argument" ); + } + + @Test( "Test 'put' and 'get' behaviors with Float" ) + public function testPutAndGetWitFloat() : Void + { + var map = new HashMap(); + var mockKey = 3.1; + var mockValue = 4.2; + + var value = map.put( mockKey, mockValue ); + Assert.isNull( value, "'put' should return null when key was never registered" ); + Assert.equals( mockValue, map.get( mockKey ), "'get' should return value argument" ); + } + + @Test( "Test 'put' and 'get' behaviors with Bool" ) + public function testPutAndGetWithBool() : Void + { + var map = new HashMap(); + var mockKey = false; + var mockValue = true; + + var value = map.put( mockKey, mockValue ); + Assert.isNull( value, "'put' should return null when key was never registered" ); + Assert.equals( mockValue, map.get( mockKey ), "'get' should return value argument" ); + } + + @Test( "Test 'put' and 'get' behaviors with String" ) + public function testPutAndGetWithString() : Void + { + var map = new HashMap(); + var mockKey = 'a'; + var mockValue = 'b'; + + var value = map.put( mockKey, mockValue ); + Assert.isNull( value, "'put' should return null when key was never registered" ); + Assert.equals( mockValue, map.get( mockKey ), "'get' should return value argument" ); + } + @Test( "Test 'remove' behavior" ) public function testRemove() : Void { diff --git a/test/hex/collection/LocatorTest.hx b/test/hex/collection/LocatorTest.hx index c99e550..fc9f26d 100644 --- a/test/hex/collection/LocatorTest.hx +++ b/test/hex/collection/LocatorTest.hx @@ -230,13 +230,27 @@ class LocatorTest locator.register( 'test', true ); Assert.equals( 1, listener.callbackCallCount ); Assert.equals( 'test', listener.callbackKey ); - Assert.equals( true, listener.callbackValue ); + Assert.isTrue( listener.callbackValue ); listener.reset(); locator.unregister( 'test' ); Assert.equals( 1, listener.callbackCallCount ); Assert.equals( 'test', listener.callbackKey ); Assert.isFalse( listener.callbackValue ); + + locator.removeListener( listener ); + + listener.reset(); + locator.register( 'test', true ); + Assert.equals( 0, listener.callbackCallCount ); + Assert.isNull( listener.callbackKey ); + Assert.isFalse( listener.callbackValue ); + + listener.reset(); + locator.unregister( 'test' ); + Assert.equals( 0, listener.callbackCallCount ); + Assert.isNull( listener.callbackKey ); + Assert.isFalse( listener.callbackValue ); } } diff --git a/test/hex/error/CoreErrorSuite.hx b/test/hex/error/CoreErrorSuite.hx new file mode 100644 index 0000000..370916c --- /dev/null +++ b/test/hex/error/CoreErrorSuite.hx @@ -0,0 +1,14 @@ +package hex.error; + +/** + * ... + * @author Francis Bourre + */ +class CoreErrorSuite +{ + @Suite( "Error" ) + public var list : Array> = + [ + ExceptionTest + ]; +} \ No newline at end of file diff --git a/test/hex/error/ExceptionTest.hx b/test/hex/error/ExceptionTest.hx new file mode 100644 index 0000000..6bfdab3 --- /dev/null +++ b/test/hex/error/ExceptionTest.hx @@ -0,0 +1,20 @@ +package hex.error; + +import hex.unittest.assertion.Assert; + +/** + * ... + * @author Francis Bourre + */ +class ExceptionTest +{ + @Test( "Test 'name' property passed to constructor" ) + public function testConstructor() : Void + { + var e = new Exception( "message" ); + Assert.equals( "message", e.message ); + Assert.isNotNull( "message", e.name ); + Assert.isNotNull( "message", e.posInfos ); + Assert.isNotNull( "message", e.toString() ); + } +} \ No newline at end of file From 8b8bfb80cd092a13e3605f94fe89c24ff9530250 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Wed, 22 Feb 2017 14:48:16 +0100 Subject: [PATCH 08/25] More code coverage. Removed from coverage the log package that will be replaced by hexLog repository. --- src/hex/control/payload/ExecutionPayload.hx | 2 +- src/hex/log/DomainLogger.hx | 1 + src/hex/log/LogLevel.hx | 1 + src/hex/log/Logger.hx | 1 + src/hex/log/LoggerMessage.hx | 1 + src/hex/log/layout/JavaScriptConsoleLayout.hx | 1 + src/hex/log/layout/TraceLayout.hx | 1 + .../model/ModelDispatcherAutoBuildMacro.hx | 4 +- src/hex/structures/PointFactory.hx | 5 +- test/hex/collection/HashMapTest.hx | 48 ------------------- .../control/payload/ExecutionPayloadTest.hx | 9 ---- test/hex/control/payload/PayloadUtilTest.hx | 40 ++++++++++++++++ test/hex/core/HashCodeFactoryTest.hx | 7 +++ test/hex/structures/CoreStructuresSuite.hx | 8 +++- test/hex/structures/PointFactoryTest.hx | 24 ++++++++++ 15 files changed, 92 insertions(+), 61 deletions(-) create mode 100644 test/hex/structures/PointFactoryTest.hx diff --git a/src/hex/control/payload/ExecutionPayload.hx b/src/hex/control/payload/ExecutionPayload.hx index 0fdfffe..77628cf 100644 --- a/src/hex/control/payload/ExecutionPayload.hx +++ b/src/hex/control/payload/ExecutionPayload.hx @@ -60,7 +60,7 @@ class ExecutionPayload public function withName( name : String ) : ExecutionPayload { - this._name = name != null ? name : ""; + this._name = name; return this; } diff --git a/src/hex/log/DomainLogger.hx b/src/hex/log/DomainLogger.hx index bbeab32..8e215ba 100644 --- a/src/hex/log/DomainLogger.hx +++ b/src/hex/log/DomainLogger.hx @@ -9,6 +9,7 @@ import hex.log.Logger; * ... * @author Francis Bourre */ +@IgnoreCover class DomainLogger implements ILogger { var _domain : Domain; diff --git a/src/hex/log/LogLevel.hx b/src/hex/log/LogLevel.hx index 450a8f9..005195c 100644 --- a/src/hex/log/LogLevel.hx +++ b/src/hex/log/LogLevel.hx @@ -4,6 +4,7 @@ package hex.log; * ... * @author Francis Bourre */ +@IgnoreCover class LogLevel { static var _ALL = new LogLevel( 0 ); diff --git a/src/hex/log/Logger.hx b/src/hex/log/Logger.hx index 006a612..0ff6e55 100644 --- a/src/hex/log/Logger.hx +++ b/src/hex/log/Logger.hx @@ -9,6 +9,7 @@ import hex.domain.NoDomain; * ... * @author Francis Bourre */ +@IgnoreCover class Logger { static var _Instance : Logger = null; diff --git a/src/hex/log/LoggerMessage.hx b/src/hex/log/LoggerMessage.hx index f17221a..40c3366 100644 --- a/src/hex/log/LoggerMessage.hx +++ b/src/hex/log/LoggerMessage.hx @@ -8,6 +8,7 @@ import hex.event.MessageType; * ... * @author Francis Bourre */ +@IgnoreCover class LoggerMessage { inline public static var LOG = new MessageType( "onLog" ); diff --git a/src/hex/log/layout/JavaScriptConsoleLayout.hx b/src/hex/log/layout/JavaScriptConsoleLayout.hx index c1feb06..5bc0283 100644 --- a/src/hex/log/layout/JavaScriptConsoleLayout.hx +++ b/src/hex/log/layout/JavaScriptConsoleLayout.hx @@ -10,6 +10,7 @@ import js.Browser; * ... * @author Francis Bourre */ +@IgnoreCover class JavaScriptConsoleLayout implements ILogListener { public function new() diff --git a/src/hex/log/layout/TraceLayout.hx b/src/hex/log/layout/TraceLayout.hx index 572ff65..5e09d2e 100644 --- a/src/hex/log/layout/TraceLayout.hx +++ b/src/hex/log/layout/TraceLayout.hx @@ -9,6 +9,7 @@ import hex.log.LoggerMessage; * ... * @author Francis Bourre */ +@IgnoreCover class TraceLayout implements ILogListener { public function new() diff --git a/src/hex/model/ModelDispatcherAutoBuildMacro.hx b/src/hex/model/ModelDispatcherAutoBuildMacro.hx index db98fd0..d852ee9 100644 --- a/src/hex/model/ModelDispatcherAutoBuildMacro.hx +++ b/src/hex/model/ModelDispatcherAutoBuildMacro.hx @@ -1,5 +1,6 @@ package hex.model; +#if macro import haxe.macro.Context; import haxe.macro.Expr.Field; @@ -40,4 +41,5 @@ class ModelDispatcherAutoBuildMacro return fields; } -} \ No newline at end of file +} +#end \ No newline at end of file diff --git a/src/hex/structures/PointFactory.hx b/src/hex/structures/PointFactory.hx index 0229746..a9fbe8e 100644 --- a/src/hex/structures/PointFactory.hx +++ b/src/hex/structures/PointFactory.hx @@ -1,14 +1,17 @@ package hex.structures; +import hex.error.PrivateConstructorException; + /** * ... * @author Francis Bourre */ class PointFactory { + /** @private */ function new() { - + throw new PrivateConstructorException(); } inline static public function build( x : Int = 0, y : Int = 0 ) : Point diff --git a/test/hex/collection/HashMapTest.hx b/test/hex/collection/HashMapTest.hx index e33f802..6f0db65 100644 --- a/test/hex/collection/HashMapTest.hx +++ b/test/hex/collection/HashMapTest.hx @@ -76,54 +76,6 @@ class HashMapTest Assert.methodCallThrows( NullPointerException, this._map, this._map.put, [mockKey, null], "'put' should throw NullPointerException" ); } - @Test( "Test 'put' and 'get' behaviors with Int" ) - public function testPutAndGetWithInt() : Void - { - var map = new HashMap(); - var mockKey = 3; - var mockValue = 4; - - var value = map.put( mockKey, mockValue ); - Assert.isNull( value, "'put' should return null when key was never registered" ); - Assert.equals( mockValue, map.get( mockKey ), "'get' should return value argument" ); - } - - @Test( "Test 'put' and 'get' behaviors with Float" ) - public function testPutAndGetWitFloat() : Void - { - var map = new HashMap(); - var mockKey = 3.1; - var mockValue = 4.2; - - var value = map.put( mockKey, mockValue ); - Assert.isNull( value, "'put' should return null when key was never registered" ); - Assert.equals( mockValue, map.get( mockKey ), "'get' should return value argument" ); - } - - @Test( "Test 'put' and 'get' behaviors with Bool" ) - public function testPutAndGetWithBool() : Void - { - var map = new HashMap(); - var mockKey = false; - var mockValue = true; - - var value = map.put( mockKey, mockValue ); - Assert.isNull( value, "'put' should return null when key was never registered" ); - Assert.equals( mockValue, map.get( mockKey ), "'get' should return value argument" ); - } - - @Test( "Test 'put' and 'get' behaviors with String" ) - public function testPutAndGetWithString() : Void - { - var map = new HashMap(); - var mockKey = 'a'; - var mockValue = 'b'; - - var value = map.put( mockKey, mockValue ); - Assert.isNull( value, "'put' should return null when key was never registered" ); - Assert.equals( mockValue, map.get( mockKey ), "'get' should return value argument" ); - } - @Test( "Test 'remove' behavior" ) public function testRemove() : Void { diff --git a/test/hex/control/payload/ExecutionPayloadTest.hx b/test/hex/control/payload/ExecutionPayloadTest.hx index 1dc7585..2c5e3ce 100644 --- a/test/hex/control/payload/ExecutionPayloadTest.hx +++ b/test/hex/control/payload/ExecutionPayloadTest.hx @@ -45,15 +45,6 @@ class ExecutionPayloadTest } #end - /*@Test( "Test overwriting type property" ) - public function testOverwritingType() : Void - { - this._executionPayload.withClass( IMockType ); - Assert.notEquals( IMockData, this._executionPayload.getType(), "type should not be the same" ); - Assert.equals( IMockType, this._executionPayload.getType(), "type should be the same" ); - Assert.equals( "hex.control.payload.IMockType", this._executionPayload.getClassName(), "class name should be the same" ); - }*/ - @Test( "Test overwriting name property" ) public function testOverwritingName() : Void { diff --git a/test/hex/control/payload/PayloadUtilTest.hx b/test/hex/control/payload/PayloadUtilTest.hx index a41fc8c..e623786 100644 --- a/test/hex/control/payload/PayloadUtilTest.hx +++ b/test/hex/control/payload/PayloadUtilTest.hx @@ -58,6 +58,46 @@ class PayloadUtilTest injector.unmappedPayloads, "'CommandExecutor.mapPayload' should unmap right values" ); } + + @Test( "Test mapping with class name" ) + public function testMappingWithClassName() : Void + { + var injector = new MockDependencyInjectorForMapping(); + + var mockImplementation = new MockImplementation( "mockImplementation" ); + var anotherMockImplementation = new MockImplementation( "anotherMockImplementation" ); + + var mockPayload = new ExecutionPayload( mockImplementation, IMockType, "mockPayload" ).withClassName( 'MockImplementation' ); + var stringPayload = new ExecutionPayload( "test", String, "stringPayload" ); + var anotherMockPayload = new ExecutionPayload( anotherMockImplementation, IMockType, "anotherMockPayload" ).withClassName( 'MockImplementation' ); + + var payloads : Array = [ mockPayload, stringPayload, anotherMockPayload ]; + PayloadUtil.mapPayload( payloads, injector ); + + Assert.deepEquals( [[mockImplementation, 'MockImplementation', "mockPayload"], ["test", String, "stringPayload"], [anotherMockImplementation, 'MockImplementation', "anotherMockPayload"] ], + injector.mappedPayloads, + "'CommandExecutor.mapPayload' should map right values" ); + } + + @Test( "Test unmapping with class name" ) + public function testUnmappingWithClassName() : Void + { + var injector = new MockDependencyInjectorForMapping(); + + var mockImplementation = new MockImplementation( "mockImplementation" ); + var anotherMockImplementation = new MockImplementation( "anotherMockImplementation" ); + + var mockPayload = new ExecutionPayload( mockImplementation, IMockType, "mockPayload" ).withClassName( 'MockImplementation' ); + var stringPayload = new ExecutionPayload( "test", String, "stringPayload" ); + var anotherMockPayload = new ExecutionPayload( anotherMockImplementation, IMockType, "anotherMockPayload" ).withClassName( 'MockImplementation' ); + + var payloads : Array = [ mockPayload, stringPayload, anotherMockPayload ]; + PayloadUtil.unmapPayload( payloads, injector ); + + Assert.deepEquals( [['MockImplementation', "mockPayload"], [String, "stringPayload"], ['MockImplementation', "anotherMockPayload"] ], + injector.unmappedPayloads, + "'CommandExecutor.mapPayload' should unmap right values" ); + } } private class MockDependencyInjectorForMapping extends MockDependencyInjector diff --git a/test/hex/core/HashCodeFactoryTest.hx b/test/hex/core/HashCodeFactoryTest.hx index 417580c..5f1ce14 100644 --- a/test/hex/core/HashCodeFactoryTest.hx +++ b/test/hex/core/HashCodeFactoryTest.hx @@ -40,6 +40,13 @@ class HashCodeFactoryTest var anotherKey : Int = HashCodeFactory.getKey( o ); Assert.equals( key, anotherKey, "Two 'HashCodeFactory.getKEY' calls on the same target should return the same value" ); } + + @Test( "Test 'getNextName'" ) + public function testGetNextName() : Void + { + var previewKey : Int = HashCodeFactory.previewNextKey(); + Assert.equals( "" + previewKey, HashCodeFactory.getNextName(), "'HashCodeFactory.getNextName' and 'HashCodeFactory.previewNextKey' should return the same String value" ); + } } private class MockObject diff --git a/test/hex/structures/CoreStructuresSuite.hx b/test/hex/structures/CoreStructuresSuite.hx index 74ab04a..43265ef 100644 --- a/test/hex/structures/CoreStructuresSuite.hx +++ b/test/hex/structures/CoreStructuresSuite.hx @@ -7,5 +7,11 @@ package hex.structures; class CoreStructuresSuite { @Suite( "Structures" ) - public var list : Array> = [ PointTest, PointFTest, SizeTest ]; + public var list : Array> = + [ + PointTest, + PointFTest, + PointFactoryTest, + SizeTest + ]; } \ No newline at end of file diff --git a/test/hex/structures/PointFactoryTest.hx b/test/hex/structures/PointFactoryTest.hx new file mode 100644 index 0000000..2c4c5a7 --- /dev/null +++ b/test/hex/structures/PointFactoryTest.hx @@ -0,0 +1,24 @@ +package hex.structures; + +import hex.unittest.assertion.Assert; + +/** + * ... + * @author Francis Bourre + */ +class PointFactoryTest +{ + @Test( "test constructor is private" ) + public function testPrivateConstructor() : Void + { + Assert.constructorIsPrivate( PointFactory ); + } + + @Test( "test `build` method" ) + public function testBuildMethod() : Void + { + var p = PointFactory.build( 3, 5 ); + Assert.equals( 3, p.x ); + Assert.equals( 5, p.y ); + } +} \ No newline at end of file From c5af78e069d2d1bdc7cedf7dea008854b6be5e20 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Thu, 23 Feb 2017 07:40:39 +0100 Subject: [PATCH 09/25] More code coverage and useless layouts removed --- src/hex/log/Stringifier.hx | 33 +++-------- src/hex/log/layout/JavaScriptConsoleLayout.hx | 57 ------------------- src/hex/log/layout/TraceLayout.hx | 34 ----------- test/hex/HexCoreSuite.hx | 2 + test/hex/log/CoreLogSuite.hx | 11 ++++ test/hex/log/StringifierTest.hx | 38 +++++++++++++ 6 files changed, 59 insertions(+), 116 deletions(-) delete mode 100644 src/hex/log/layout/JavaScriptConsoleLayout.hx delete mode 100644 src/hex/log/layout/TraceLayout.hx create mode 100644 test/hex/log/CoreLogSuite.hx create mode 100644 test/hex/log/StringifierTest.hx diff --git a/src/hex/log/Stringifier.hx b/src/hex/log/Stringifier.hx index adc173b..6cf79fb 100644 --- a/src/hex/log/Stringifier.hx +++ b/src/hex/log/Stringifier.hx @@ -1,6 +1,5 @@ package hex.log; -import haxe.PosInfos; import hex.error.PrivateConstructorException; /** @@ -15,30 +14,22 @@ class Stringifier throw new PrivateConstructorException(); } - //-------------------------------------------------------------------- - // Private properties - //-------------------------------------------------------------------- - static var _STRATEGY : IStringifierStrategy; - //-------------------------------------------------------------------- - // Public API - //-------------------------------------------------------------------- - /** - * Sets the concrete stringifier to use for process. + * Sets the concrete stringifier to be used. * - * @param o Stringifier concrete implementation + * @param stringifier Stringifier concrete implementation * - * @see BasicStringifier + * @see hex.log.BasicStringifierStrategy */ - public static function setStringifier( o : IStringifierStrategy ) : Void + public static function setStringifier( stringifier : IStringifierStrategy ) : Void { - Stringifier._STRATEGY = o; + Stringifier._STRATEGY = stringifier; } /** - * Returns the current used stringifier. + * Returns the current stringifier used. */ public static function getStringifier() : IStringifierStrategy { @@ -48,9 +39,9 @@ class Stringifier /** * Process stringify processing. * - * @param target Object to stringify + * @param target Object to stringified */ - public static function stringify( target : Dynamic ) : String + public static function stringify( target : T ) : String { if ( Stringifier._STRATEGY == null ) { @@ -59,12 +50,4 @@ class Stringifier return Stringifier._STRATEGY.stringify( target ); } - - /** - * Returns the current code postion informations. - */ - public static function getPosInfos( ?posInfos : PosInfos ) : PosInfos - { - return posInfos; - } } diff --git a/src/hex/log/layout/JavaScriptConsoleLayout.hx b/src/hex/log/layout/JavaScriptConsoleLayout.hx deleted file mode 100644 index 5bc0283..0000000 --- a/src/hex/log/layout/JavaScriptConsoleLayout.hx +++ /dev/null @@ -1,57 +0,0 @@ -package hex.log.layout; - -#if js -import haxe.PosInfos; -import hex.log.ILogListener; -import hex.log.LoggerMessage; -import js.Browser; - -/** - * ... - * @author Francis Bourre - */ -@IgnoreCover -class JavaScriptConsoleLayout implements ILogListener -{ - public function new() - { - - } - - public function onLog( message : LoggerMessage ) : Void - { - var posInfos : PosInfos = message.posInfos; - var info : String = posInfos != null ? " at " + posInfos.className + "::" + posInfos.methodName + " line " + posInfos.lineNumber + " in file " + posInfos.fileName : ""; - var m : haxe.extern.Rest->Void; - - if ( message.level.value == LogLevel.DEBUG.value ) - { - m = Browser.console.debug; - } - else if ( message.level.value == LogLevel.INFO.value ) - { - m = Browser.console.info; - } - else if ( message.level.value == LogLevel.WARN.value ) - { - m = Browser.console.warn; - } - else if ( message.level.value == LogLevel.FATAL.value || message.level.value == LogLevel.ERROR.value) - { - m = Browser.console.error; - - } - else - { - m = Browser.console.log; - } - - m( message.message, "[" + message.domain.getName() + "]" + info ); - } - - public function onClear() : Void - { - Browser.console.clear(); - } -} -#end \ No newline at end of file diff --git a/src/hex/log/layout/TraceLayout.hx b/src/hex/log/layout/TraceLayout.hx deleted file mode 100644 index 5e09d2e..0000000 --- a/src/hex/log/layout/TraceLayout.hx +++ /dev/null @@ -1,34 +0,0 @@ -package hex.log.layout; - -import haxe.Log; -import haxe.PosInfos; -import hex.log.ILogListener; -import hex.log.LoggerMessage; - -/** - * ... - * @author Francis Bourre - */ -@IgnoreCover -class TraceLayout implements ILogListener -{ - public function new() - { - - } - - public function onLog( message : LoggerMessage ) : Void - { - var posInfos : PosInfos = message.posInfos; - var info : String = posInfos != null ? " at " + posInfos.className + "::" + posInfos.methodName + " line " + posInfos.lineNumber + " in file " + posInfos.fileName : ""; - - Log.trace( ">>> " + message.level + ":" + message.message + " [" + message.domain.getName() + "]" + info, posInfos ); - } - - public function onClear() : Void - { - #if (flash || js) - Log.clear(); - #end - } -} diff --git a/test/hex/HexCoreSuite.hx b/test/hex/HexCoreSuite.hx index d1d3363..1a13fd6 100644 --- a/test/hex/HexCoreSuite.hx +++ b/test/hex/HexCoreSuite.hx @@ -8,6 +8,7 @@ import hex.di.CoreDiSuite; import hex.domain.CoreDomainSuite; import hex.event.CoreEventSuite; import hex.error.CoreErrorSuite; +import hex.log.CoreLogSuite; import hex.model.CoreModelSuite; import hex.module.CoreModuleSuite; import hex.service.CoreServiceSuite; @@ -31,6 +32,7 @@ class HexCoreSuite CoreDomainSuite, CoreEventSuite, CoreErrorSuite, + CoreLogSuite, CoreModelSuite, CoreModuleSuite, CoreServiceSuite, diff --git a/test/hex/log/CoreLogSuite.hx b/test/hex/log/CoreLogSuite.hx new file mode 100644 index 0000000..cd49616 --- /dev/null +++ b/test/hex/log/CoreLogSuite.hx @@ -0,0 +1,11 @@ +package hex.log; + +/** + * ... + * @author Francis Bourre + */ +class CoreLogSuite +{ + @Suite( "Log" ) + public var list : Array> = [ StringifierTest ]; +} \ No newline at end of file diff --git a/test/hex/log/StringifierTest.hx b/test/hex/log/StringifierTest.hx new file mode 100644 index 0000000..333486b --- /dev/null +++ b/test/hex/log/StringifierTest.hx @@ -0,0 +1,38 @@ +package hex.log; + +import hex.unittest.assertion.Assert; + +/** + * ... + * @author Francis Bourre + */ +class StringifierTest +{ + @Test( "test constructor is private" ) + public function testPrivateConstructor() : Void + { + Assert.constructorIsPrivate( Stringifier ); + } + + @Test( "test accessors" ) + public function testAccessors() : Void + { + Stringifier.stringify( 'test' ); + Assert.isNotNull( Stringifier.getStringifier() ); + Assert.isInstanceOf( Stringifier.getStringifier(), BasicStringifierStrategy ); + + var stringifier = new MockStringifierStrategy(); + Stringifier.setStringifier( stringifier ); + Assert.equals( stringifier, Stringifier.getStringifier() ); + } +} + +private class MockStringifierStrategy implements IStringifierStrategy +{ + public function new() { } + + public function stringify( target : Dynamic ) : String + { + return 'test'; + } +} \ No newline at end of file From 9e078715b063eec029318c589a80de7b6cb37934 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Thu, 23 Feb 2017 08:51:43 +0100 Subject: [PATCH 10/25] Replace when it's possible Dynamic with haxe.Constraints.Function --- src/hex/domain/DomainDispatcher.hx | 4 ++-- src/hex/domain/IDomainDispatcher.hx | 4 ++-- src/hex/event/Dispatcher.hx | 4 ++-- src/hex/event/IDispatcher.hx | 4 ++-- src/hex/module/IModule.hx | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/hex/domain/DomainDispatcher.hx b/src/hex/domain/DomainDispatcher.hx index 0e0cd9e..07f48cc 100644 --- a/src/hex/domain/DomainDispatcher.hx +++ b/src/hex/domain/DomainDispatcher.hx @@ -101,12 +101,12 @@ class DomainDispatcher implements IDomainDispatcher( messageType : MessageType, scope : Dynamic, callback : T, domain : Domain ) : Bool { return this.getDomainDispatcher( domain ).addHandler( messageType, scope, callback ); } - public function removeHandler( messageType : MessageType, scope : Dynamic, callback : Dynamic, domain : Domain ) : Bool + public function removeHandler( messageType : MessageType, scope : Dynamic, callback : T, domain : Domain ) : Bool { return this.getDomainDispatcher( domain ).removeHandler( messageType, scope, callback ); } diff --git a/src/hex/domain/IDomainDispatcher.hx b/src/hex/domain/IDomainDispatcher.hx index f874384..c2c880f 100644 --- a/src/hex/domain/IDomainDispatcher.hx +++ b/src/hex/domain/IDomainDispatcher.hx @@ -32,9 +32,9 @@ interface IDomainDispatcher function removeListener( listener : ListenerType, ?domain : Domain ) : Bool; - function addHandler( messageType : MessageType, scope : Dynamic, callback : Dynamic, domain : Domain ) : Bool; + function addHandler( messageType : MessageType, scope : Dynamic, callback : T, domain : Domain ) : Bool; - function removeHandler( messageType : MessageType, scope : Dynamic, callback : Dynamic, domain : Domain ) : Bool; + function removeHandler( messageType : MessageType, scope : Dynamic, callback : T, domain : Domain ) : Bool; function dispatch( messageType : MessageType, ?domain : Domain, ?data : Array ) : Void; diff --git a/src/hex/event/Dispatcher.hx b/src/hex/event/Dispatcher.hx index 54a964f..2c5724f 100644 --- a/src/hex/event/Dispatcher.hx +++ b/src/hex/event/Dispatcher.hx @@ -80,7 +80,7 @@ class Dispatcher implements IDispatcher this._seal( false ); } - public function addHandler( messageType : MessageType, scope : Dynamic, callback : Dynamic ) : Bool + public function addHandler( messageType : MessageType, scope : Dynamic, callback : T ) : Bool { if ( !this._isSealed ) { @@ -123,7 +123,7 @@ class Dispatcher implements IDispatcher } } - public function removeHandler( messageType : MessageType, scope : Dynamic, callback : Dynamic ) : Bool + public function removeHandler( messageType : MessageType, scope : Dynamic, callback : T ) : Bool { if ( !this._isSealed ) { diff --git a/src/hex/event/IDispatcher.hx b/src/hex/event/IDispatcher.hx index ceb3ec4..01dc296 100644 --- a/src/hex/event/IDispatcher.hx +++ b/src/hex/event/IDispatcher.hx @@ -6,8 +6,8 @@ package hex.event; interface IDispatcher { function dispatch( messageType : MessageType, ?data : Array ) : Void; - function addHandler( messageType : MessageType, scope : Dynamic, callback : Dynamic ) : Bool; - function removeHandler( messageType : MessageType, scope : Dynamic, callback : Dynamic ) : Bool; + function addHandler( messageType : MessageType, scope : Dynamic, callback : T ) : Bool; + function removeHandler( messageType : MessageType, scope : Dynamic, callback : T ) : Bool; function addListener( listener : ListenerType ) : Bool; function removeListener( listener : ListenerType ) : Bool; function removeAllListeners() : Void; diff --git a/src/hex/module/IModule.hx b/src/hex/module/IModule.hx index eac2d6c..b139de3 100644 --- a/src/hex/module/IModule.hx +++ b/src/hex/module/IModule.hx @@ -21,9 +21,9 @@ interface IModule extends IContextOwner function dispatchPublicMessage( messageType : MessageType, ?data : Array ) : Void; - function addHandler( messageType : MessageType, scope : Dynamic, callback : Dynamic ) : Void; + function addHandler( messageType : MessageType, scope : Dynamic, callback : T ) : Void; - function removeHandler( messageType : MessageType, scope : Dynamic, callback : Dynamic ) : Void; + function removeHandler( messageType : MessageType, scope : Dynamic, callback : T ) : Void; function getDomain() : Domain; From 0eb77d64280992fb02c7149987e7f62b359b4dd6 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Thu, 23 Feb 2017 10:05:13 +0100 Subject: [PATCH 11/25] Domain class is final --- src/hex/domain/DefaultDomain.hx | 4 ++-- src/hex/domain/Domain.hx | 1 + src/hex/domain/DomainExpert.hx | 2 +- src/hex/domain/DomainUtil.hx | 6 +++--- src/hex/domain/NoDomain.hx | 4 ++-- src/hex/domain/TopLevelDomain.hx | 4 ++-- test/hex/domain/DefaultDomainTest.hx | 2 +- test/hex/domain/DomainUtilTest.hx | 4 ++-- test/hex/domain/NoDomainTest.hx | 2 +- test/hex/domain/TopLevelDomainTest.hx | 2 +- 10 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/hex/domain/DefaultDomain.hx b/src/hex/domain/DefaultDomain.hx index 6611307..9611035 100644 --- a/src/hex/domain/DefaultDomain.hx +++ b/src/hex/domain/DefaultDomain.hx @@ -4,7 +4,7 @@ package hex.domain; * ... * @author Francis Bourre */ -class DefaultDomain extends Domain +class DefaultDomain { - public static var DOMAIN : DefaultDomain = DomainUtil.getDomain( "DefaultDomain", DefaultDomain ); + public static var DOMAIN : Domain = DomainUtil.getDomain( "DefaultDomain" ); } diff --git a/src/hex/domain/Domain.hx b/src/hex/domain/Domain.hx index ffa5c52..d2e2eab 100644 --- a/src/hex/domain/Domain.hx +++ b/src/hex/domain/Domain.hx @@ -8,6 +8,7 @@ import hex.error.IllegalArgumentException; * ... * @author Francis Bourre */ +@:final class Domain { var _domainName : String; diff --git a/src/hex/domain/DomainExpert.hx b/src/hex/domain/DomainExpert.hx index 9e380a6..525a597 100644 --- a/src/hex/domain/DomainExpert.hx +++ b/src/hex/domain/DomainExpert.hx @@ -53,7 +53,7 @@ class DomainExpert } else { - var domain = DomainUtil.getDomain( key, Domain ); + var domain = DomainUtil.getDomain( key ); this._removedModules.set( key, false ); this._subscribedModules.set( module, domain ); return domain; diff --git a/src/hex/domain/DomainUtil.hx b/src/hex/domain/DomainUtil.hx index 239e383..a956c94 100644 --- a/src/hex/domain/DomainUtil.hx +++ b/src/hex/domain/DomainUtil.hx @@ -16,9 +16,9 @@ class DomainUtil throw new PrivateConstructorException(); } - static public function getDomain( domainName : String, type : Class ) : DomainType + static public function getDomain( domainName : String ) : Domain { - var domain : DomainType = null; + var domain = null; if ( DomainUtil._domain.exists( domainName ) ) { @@ -26,7 +26,7 @@ class DomainUtil } else { - domain = Type.createInstance( type, [ domainName ] ); + domain = Type.createInstance( Domain, [ domainName ] ); DomainUtil._domain.set( domainName, domain ); } diff --git a/src/hex/domain/NoDomain.hx b/src/hex/domain/NoDomain.hx index 4350197..c23d0c4 100644 --- a/src/hex/domain/NoDomain.hx +++ b/src/hex/domain/NoDomain.hx @@ -4,7 +4,7 @@ package hex.domain; * ... * @author Francis Bourre */ -class NoDomain extends Domain +class NoDomain { - public static var DOMAIN : NoDomain = DomainUtil.getDomain( "NoDomain", NoDomain ); + public static var DOMAIN : Domain = DomainUtil.getDomain( "NoDomain" ); } diff --git a/src/hex/domain/TopLevelDomain.hx b/src/hex/domain/TopLevelDomain.hx index 31201fc..a62aa20 100644 --- a/src/hex/domain/TopLevelDomain.hx +++ b/src/hex/domain/TopLevelDomain.hx @@ -4,7 +4,7 @@ package hex.domain; * ... * @author Francis Bourre */ -class TopLevelDomain extends Domain +class TopLevelDomain { - public static var DOMAIN : TopLevelDomain = DomainUtil.getDomain( "TopLevelDomain", TopLevelDomain ); + public static var DOMAIN : Domain = DomainUtil.getDomain( "TopLevelDomain" ); } \ No newline at end of file diff --git a/test/hex/domain/DefaultDomainTest.hx b/test/hex/domain/DefaultDomainTest.hx index 36eb420..07d0433 100644 --- a/test/hex/domain/DefaultDomainTest.hx +++ b/test/hex/domain/DefaultDomainTest.hx @@ -17,6 +17,6 @@ class DefaultDomainTest @Test( "Test if DefaultDomain.DOMAIN is an instance of DefaultDomain" ) public function testDefaultDomainStaticVariableType() : Void { - Assert.isInstanceOf( DefaultDomain.DOMAIN, DefaultDomain, "domain should be an instance of 'DefaultDomain'" ); + Assert.isInstanceOf( DefaultDomain.DOMAIN, Domain, "domain should be an instance of 'DefaultDomain'" ); } } diff --git a/test/hex/domain/DomainUtilTest.hx b/test/hex/domain/DomainUtilTest.hx index b08b090..a29a934 100644 --- a/test/hex/domain/DomainUtilTest.hx +++ b/test/hex/domain/DomainUtilTest.hx @@ -19,7 +19,7 @@ class DomainUtilTest { var domainName = Type.getClassName( Type.getClass( this ) ) + "_testDomainCreation"; - var domain = DomainUtil.getDomain( domainName, Domain ); + var domain = DomainUtil.getDomain( domainName ); Assert.isNotNull( domain, "getDomain function should create a domain if doesn't exist" ); Assert.isInstanceOf( domain, Domain, "getDomain should return a domain instance of the requested type" ); Assert.equals( domainName, domain.getName(), "domain's name should be the same that was requested" ); @@ -30,7 +30,7 @@ class DomainUtilTest { var domainName = Type.getClassName( Type.getClass( this ) ) + "_testGetDomainTwice"; - var domain = DomainUtil.getDomain( domainName, DefaultDomain ); + var domain = DomainUtil.getDomain( domainName ); var anotherDomainWithTheSameName = Domain.getDomain( domainName ); Assert.equals( domain, anotherDomainWithTheSameName, "getDomain should return the same domain" ); diff --git a/test/hex/domain/NoDomainTest.hx b/test/hex/domain/NoDomainTest.hx index d9e4d7c..e5f9315 100644 --- a/test/hex/domain/NoDomainTest.hx +++ b/test/hex/domain/NoDomainTest.hx @@ -17,6 +17,6 @@ class NoDomainTest @Test( "Test if NoDomain.DOMAIN is an instance of NoDomain" ) public function testNoDomainStaticVariableType() : Void { - Assert.isInstanceOf( NoDomain.DOMAIN, NoDomain, "domain should be an instance of 'NoDomain'" ); + Assert.isInstanceOf( NoDomain.DOMAIN, Domain, "domain should be an instance of 'NoDomain'" ); } } diff --git a/test/hex/domain/TopLevelDomainTest.hx b/test/hex/domain/TopLevelDomainTest.hx index 2105c81..c55ea4a 100644 --- a/test/hex/domain/TopLevelDomainTest.hx +++ b/test/hex/domain/TopLevelDomainTest.hx @@ -17,6 +17,6 @@ class TopLevelDomainTest @Test( "Test if TopLevelDomain.DOMAIN is an instance of TopLevelDomain" ) public function testTopLevelDomainStaticVariableType() : Void { - Assert.isInstanceOf( TopLevelDomain.DOMAIN, TopLevelDomain, "domain should be an instance of 'TopLevelDomain'" ); + Assert.isInstanceOf( TopLevelDomain.DOMAIN, Domain, "domain should be an instance of 'TopLevelDomain'" ); } } From 10789c44bcc914b5942f7f7708f628d074ad6464 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Thu, 23 Feb 2017 10:36:56 +0100 Subject: [PATCH 12/25] Domain class is abstract --- src/hex/domain/DefaultDomain.hx | 2 +- src/hex/domain/Domain.hx | 3 ++- src/hex/domain/NoDomain.hx | 2 +- src/hex/domain/TopLevelDomain.hx | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/hex/domain/DefaultDomain.hx b/src/hex/domain/DefaultDomain.hx index 9611035..62756e6 100644 --- a/src/hex/domain/DefaultDomain.hx +++ b/src/hex/domain/DefaultDomain.hx @@ -6,5 +6,5 @@ package hex.domain; */ class DefaultDomain { - public static var DOMAIN : Domain = DomainUtil.getDomain( "DefaultDomain" ); + public static var DOMAIN = DomainUtil.getDomain( "DefaultDomain" ); } diff --git a/src/hex/domain/Domain.hx b/src/hex/domain/Domain.hx index d2e2eab..4eb0cf1 100644 --- a/src/hex/domain/Domain.hx +++ b/src/hex/domain/Domain.hx @@ -14,7 +14,8 @@ class Domain var _domainName : String; static var _domainNames = new Map(); - public function new( domainName : String ) + @:allow( hex.domain ) + function new( domainName : String ) { if ( domainName == null ) { diff --git a/src/hex/domain/NoDomain.hx b/src/hex/domain/NoDomain.hx index c23d0c4..cf4bac6 100644 --- a/src/hex/domain/NoDomain.hx +++ b/src/hex/domain/NoDomain.hx @@ -6,5 +6,5 @@ package hex.domain; */ class NoDomain { - public static var DOMAIN : Domain = DomainUtil.getDomain( "NoDomain" ); + public static var DOMAIN = DomainUtil.getDomain( "NoDomain" ); } diff --git a/src/hex/domain/TopLevelDomain.hx b/src/hex/domain/TopLevelDomain.hx index a62aa20..2b66519 100644 --- a/src/hex/domain/TopLevelDomain.hx +++ b/src/hex/domain/TopLevelDomain.hx @@ -6,5 +6,5 @@ package hex.domain; */ class TopLevelDomain { - public static var DOMAIN : Domain = DomainUtil.getDomain( "TopLevelDomain" ); + public static var DOMAIN = DomainUtil.getDomain( "TopLevelDomain" ); } \ No newline at end of file From eb35e0ed26eaa60362be109e3b292dcbe59ca5af Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Thu, 23 Feb 2017 11:33:48 +0100 Subject: [PATCH 13/25] Domain constructor is fully private (no more @;allow) --- src/hex/domain/Domain.hx | 2 +- test/hex/domain/DomainTest.hx | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/hex/domain/Domain.hx b/src/hex/domain/Domain.hx index 4eb0cf1..d0b1d65 100644 --- a/src/hex/domain/Domain.hx +++ b/src/hex/domain/Domain.hx @@ -14,7 +14,7 @@ class Domain var _domainName : String; static var _domainNames = new Map(); - @:allow( hex.domain ) + //@:allow( hex.domain ) function new( domainName : String ) { if ( domainName == null ) diff --git a/test/hex/domain/DomainTest.hx b/test/hex/domain/DomainTest.hx index 8f1101b..9674ecf 100644 --- a/test/hex/domain/DomainTest.hx +++ b/test/hex/domain/DomainTest.hx @@ -14,7 +14,7 @@ class DomainTest @Test( "Test 'name' property passed to constructor" ) public function testConstructor() : Void { - var domain = new Domain( "testConstructor" ); + var domain = Type.createInstance( Domain, [ "testConstructor" ] ); Assert.equals( "testConstructor", domain.getName(), "'name' property should be the same passed to constructor" ); } @@ -29,21 +29,21 @@ class DomainTest @Test( "Test using twice the same 'name' value" ) public function testConstructorWithNameValues() : Void { - var domain = new Domain( "testConstructorWithNameValues" ); + var domain = Type.createInstance( Domain, [ "testConstructorWithNameValues" ] ); Assert.constructorCallThrows( IllegalArgumentException, Domain, ["testConstructorWithNameValues"], "" ); } @Test( "Test getName function" ) public function testGetName() : Void { - var domain = new Domain( "testGetName" ); + var domain = Type.createInstance( Domain, [ "testGetName" ] ); Assert.equals( "testGetName", domain.getName(), "'getName' method should return correct domain's name" ); } @Test( "Test getDomain function" ) public function testGetDomain() : Void { - var newDomain = new Domain( "testGetDomain" ); + var newDomain = Type.createInstance( Domain, [ "testGetDomain" ] ); var domain = Domain.getDomain( "testGetDomain" ); Assert.equals( newDomain, domain, "getDomain method should return the same instance if it already exists" ); @@ -54,7 +54,7 @@ class DomainTest @Test( "Test toString function" ) public function testToString() : Void { - var domain = new Domain( "testToString" ); + var domain = Type.createInstance( Domain, [ "testToString" ] ); var expectedString = "hex.domain.Domain with name 'testToString'"; Assert.equals( expectedString, domain.toString(), "toString method should return expected string value" ); } From 9a5907886ba7a1c0dfe7272d2dbdbf1db39fb907 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Thu, 23 Feb 2017 12:10:28 +0100 Subject: [PATCH 14/25] Stringifier moved to util package --- src/hex/collection/Locator.hx | 2 +- src/hex/domain/Domain.hx | 2 +- src/hex/error/Exception.hx | 2 +- src/hex/event/BasicEvent.hx | 2 +- src/hex/event/CompositeDispatcher.hx | 2 +- src/hex/event/Dispatcher.hx | 2 +- src/hex/log/Logger.hx | 1 + src/hex/{log => util}/BasicStringifierStrategy.hx | 2 +- src/hex/{log => util}/IStringifierStrategy.hx | 2 +- src/hex/{log => util}/Stringifier.hx | 2 +- test/hex/HexCoreSuite.hx | 2 -- test/hex/domain/DomainTest.hx | 2 +- test/hex/log/CoreLogSuite.hx | 11 ----------- test/hex/util/CoreUtilSuite.hx | 2 +- test/hex/{log => util}/StringifierTest.hx | 2 +- 15 files changed, 13 insertions(+), 25 deletions(-) rename src/hex/{log => util}/BasicStringifierStrategy.hx (96%) rename src/hex/{log => util}/IStringifierStrategy.hx (91%) rename src/hex/{log => util}/Stringifier.hx (98%) delete mode 100644 test/hex/log/CoreLogSuite.hx rename test/hex/{log => util}/StringifierTest.hx (97%) diff --git a/src/hex/collection/Locator.hx b/src/hex/collection/Locator.hx index daa1fc6..1773335 100644 --- a/src/hex/collection/Locator.hx +++ b/src/hex/collection/Locator.hx @@ -4,7 +4,7 @@ import hex.error.IllegalArgumentException; import hex.error.NoSuchElementException; import hex.event.ITrigger; import hex.event.ITriggerOwner; -import hex.log.Stringifier; +import hex.util.Stringifier; /** * ... diff --git a/src/hex/domain/Domain.hx b/src/hex/domain/Domain.hx index d0b1d65..8720916 100644 --- a/src/hex/domain/Domain.hx +++ b/src/hex/domain/Domain.hx @@ -1,6 +1,6 @@ package hex.domain; -import hex.log.Stringifier; +import hex.util.Stringifier; import hex.error.NullPointerException; import hex.error.IllegalArgumentException; diff --git a/src/hex/error/Exception.hx b/src/hex/error/Exception.hx index 5d4ac5f..492261c 100644 --- a/src/hex/error/Exception.hx +++ b/src/hex/error/Exception.hx @@ -2,7 +2,7 @@ package hex.error; import haxe.PosInfos; import hex.log.Logger; -import hex.log.Stringifier; +import hex.util.Stringifier; /** * ... diff --git a/src/hex/event/BasicEvent.hx b/src/hex/event/BasicEvent.hx index 7b35a15..a2d7437 100644 --- a/src/hex/event/BasicEvent.hx +++ b/src/hex/event/BasicEvent.hx @@ -1,6 +1,6 @@ package hex.event; -import hex.log.Stringifier; +import hex.util.Stringifier; /** * ... diff --git a/src/hex/event/CompositeDispatcher.hx b/src/hex/event/CompositeDispatcher.hx index bf4c7dd..05e7653 100644 --- a/src/hex/event/CompositeDispatcher.hx +++ b/src/hex/event/CompositeDispatcher.hx @@ -1,7 +1,7 @@ package hex.event; import hex.error.UnsupportedOperationException; -import hex.log.Stringifier; +import hex.util.Stringifier; /** * ... diff --git a/src/hex/event/Dispatcher.hx b/src/hex/event/Dispatcher.hx index 2c5724f..e3111cb 100644 --- a/src/hex/event/Dispatcher.hx +++ b/src/hex/event/Dispatcher.hx @@ -2,7 +2,7 @@ package hex.event; import hex.error.IllegalArgumentException; import hex.error.UnsupportedOperationException; -import hex.log.Stringifier; +import hex.util.Stringifier; /** * ... diff --git a/src/hex/log/Logger.hx b/src/hex/log/Logger.hx index 0ff6e55..5736591 100644 --- a/src/hex/log/Logger.hx +++ b/src/hex/log/Logger.hx @@ -4,6 +4,7 @@ import haxe.PosInfos; import hex.domain.Domain; import hex.domain.DomainDispatcher; import hex.domain.NoDomain; +import hex.util.Stringifier; /** * ... diff --git a/src/hex/log/BasicStringifierStrategy.hx b/src/hex/util/BasicStringifierStrategy.hx similarity index 96% rename from src/hex/log/BasicStringifierStrategy.hx rename to src/hex/util/BasicStringifierStrategy.hx index 8cf3945..9b9ee10 100644 --- a/src/hex/log/BasicStringifierStrategy.hx +++ b/src/hex/util/BasicStringifierStrategy.hx @@ -1,4 +1,4 @@ -package hex.log; +package hex.util; /** * ... diff --git a/src/hex/log/IStringifierStrategy.hx b/src/hex/util/IStringifierStrategy.hx similarity index 91% rename from src/hex/log/IStringifierStrategy.hx rename to src/hex/util/IStringifierStrategy.hx index 9d08c68..34f6c38 100644 --- a/src/hex/log/IStringifierStrategy.hx +++ b/src/hex/util/IStringifierStrategy.hx @@ -1,4 +1,4 @@ -package hex.log; +package hex.util; /** * ... diff --git a/src/hex/log/Stringifier.hx b/src/hex/util/Stringifier.hx similarity index 98% rename from src/hex/log/Stringifier.hx rename to src/hex/util/Stringifier.hx index 6cf79fb..f01e605 100644 --- a/src/hex/log/Stringifier.hx +++ b/src/hex/util/Stringifier.hx @@ -1,4 +1,4 @@ -package hex.log; +package hex.util; import hex.error.PrivateConstructorException; diff --git a/test/hex/HexCoreSuite.hx b/test/hex/HexCoreSuite.hx index 1a13fd6..d1d3363 100644 --- a/test/hex/HexCoreSuite.hx +++ b/test/hex/HexCoreSuite.hx @@ -8,7 +8,6 @@ import hex.di.CoreDiSuite; import hex.domain.CoreDomainSuite; import hex.event.CoreEventSuite; import hex.error.CoreErrorSuite; -import hex.log.CoreLogSuite; import hex.model.CoreModelSuite; import hex.module.CoreModuleSuite; import hex.service.CoreServiceSuite; @@ -32,7 +31,6 @@ class HexCoreSuite CoreDomainSuite, CoreEventSuite, CoreErrorSuite, - CoreLogSuite, CoreModelSuite, CoreModuleSuite, CoreServiceSuite, diff --git a/test/hex/domain/DomainTest.hx b/test/hex/domain/DomainTest.hx index 9674ecf..848ce15 100644 --- a/test/hex/domain/DomainTest.hx +++ b/test/hex/domain/DomainTest.hx @@ -1,8 +1,8 @@ package hex.domain; import hex.domain.Domain; -import hex.error.NullPointerException; import hex.error.IllegalArgumentException; +import hex.error.NullPointerException; import hex.unittest.assertion.Assert; /** diff --git a/test/hex/log/CoreLogSuite.hx b/test/hex/log/CoreLogSuite.hx deleted file mode 100644 index cd49616..0000000 --- a/test/hex/log/CoreLogSuite.hx +++ /dev/null @@ -1,11 +0,0 @@ -package hex.log; - -/** - * ... - * @author Francis Bourre - */ -class CoreLogSuite -{ - @Suite( "Log" ) - public var list : Array> = [ StringifierTest ]; -} \ No newline at end of file diff --git a/test/hex/util/CoreUtilSuite.hx b/test/hex/util/CoreUtilSuite.hx index b6df3c3..600bbf1 100644 --- a/test/hex/util/CoreUtilSuite.hx +++ b/test/hex/util/CoreUtilSuite.hx @@ -7,5 +7,5 @@ package hex.util; class CoreUtilSuite { @Suite( "Util" ) - public var list : Array> = [ ClassUtilTest ]; + public var list : Array> = [ ClassUtilTest, StringifierTest ]; } \ No newline at end of file diff --git a/test/hex/log/StringifierTest.hx b/test/hex/util/StringifierTest.hx similarity index 97% rename from test/hex/log/StringifierTest.hx rename to test/hex/util/StringifierTest.hx index 333486b..464673d 100644 --- a/test/hex/log/StringifierTest.hx +++ b/test/hex/util/StringifierTest.hx @@ -1,4 +1,4 @@ -package hex.log; +package hex.util; import hex.unittest.assertion.Assert; From 412b555022c1bc829f941f50a86969e244467a73 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Thu, 23 Feb 2017 14:04:51 +0100 Subject: [PATCH 15/25] DomainUtil was removed. Domain is doing the job now. --- src/hex/domain/DefaultDomain.hx | 2 +- src/hex/domain/Domain.hx | 108 +++++++++++++++++++++++++---- src/hex/domain/DomainExpert.hx | 3 +- src/hex/domain/DomainUtil.hx | 35 ---------- src/hex/domain/NoDomain.hx | 2 +- src/hex/domain/TopLevelDomain.hx | 2 +- test/hex/domain/CoreDomainSuite.hx | 8 ++- test/hex/domain/DomainTest.hx | 49 ++++++++++++- test/hex/domain/DomainUtilTest.hx | 38 ---------- 9 files changed, 150 insertions(+), 97 deletions(-) delete mode 100644 src/hex/domain/DomainUtil.hx delete mode 100644 test/hex/domain/DomainUtilTest.hx diff --git a/src/hex/domain/DefaultDomain.hx b/src/hex/domain/DefaultDomain.hx index 62756e6..ccfc2aa 100644 --- a/src/hex/domain/DefaultDomain.hx +++ b/src/hex/domain/DefaultDomain.hx @@ -6,5 +6,5 @@ package hex.domain; */ class DefaultDomain { - public static var DOMAIN = DomainUtil.getDomain( "DefaultDomain" ); + public static var DOMAIN = Domain.getDomain( "DefaultDomain" ); } diff --git a/src/hex/domain/Domain.hx b/src/hex/domain/Domain.hx index 8720916..7ca6c0f 100644 --- a/src/hex/domain/Domain.hx +++ b/src/hex/domain/Domain.hx @@ -1,8 +1,8 @@ package hex.domain; -import hex.util.Stringifier; -import hex.error.NullPointerException; import hex.error.IllegalArgumentException; +import hex.error.NullPointerException; +import hex.util.Stringifier; /** * ... @@ -11,46 +11,124 @@ import hex.error.IllegalArgumentException; @:final class Domain { - var _domainName : String; - static var _domainNames = new Map(); + var _name : String; + var _parent : Domain; + + static var _domains = new Map(); - //@:allow( hex.domain ) function new( domainName : String ) { if ( domainName == null ) { throw new NullPointerException( "Domain's name can't be null" ); } - else if ( Domain._domainNames.exists( domainName ) ) + else if ( Domain._domains.exists( domainName ) ) { throw new IllegalArgumentException( "Domain has already been registered with name '" + domainName + "'" ); } else { - Domain._domainNames.set( domainName, this ); - this._domainName = domainName; + Domain._domains.set( domainName, this ); + this._name = domainName; } } public function getName() : String { - return this._domainName; + return this._name; + } + + public function getParent() : Domain + { + return this._parent; } - public static function getDomain( domainName : String ) : Domain + static public function getDomain( domainName : String ) : Domain { - if ( !Domain._domainNames.exists( domainName ) ) - { - return null; - } + var domain = null; + + if ( Domain._domains.exists( domainName ) ) + { + domain = Domain._domains.get( domainName ); + } else { - return Domain._domainNames.get( domainName ); + domain = new Domain( domainName ); + Domain._domains.set( domainName, domain ); } + + Domain._reparent(); + return domain; } public function toString() : String { return Stringifier.stringify( this ) + " with name '" + this.getName() + "'"; } + + static function _reparent() : Void + { + var domains = Domain._domains; + + for ( key in domains.keys() ) + { + var domain = domains.get( key ); + if ( key != null && key != '' ) + { + var i = key.lastIndexOf( '.' ); + if ( i > 0 ) + { + key = key.substring( 0, i ); + var parent = Domain._getDomain( key ); + if ( parent == null ) + { + parent = TopLevelDomain.DOMAIN; + } + domain._parent = parent; + } + else + { + domain._parent = TopLevelDomain.DOMAIN; + } + } + } + } + + static public function _getDomain( name : String ) : Domain + { + var domains = Domain._domains; + + var domain = domains.get( name ); + if ( domain != null ) + { + return domain; + } + + var substr = name; + while ( ( substr = Domain._getSubName( substr ) ) != null ) + { + domain = domains.get( substr ); + if ( domain != null ) + { + return domain; + } + } + + return TopLevelDomain.DOMAIN; + } + + /** + * + * @param name + * @return + */ + static function _getSubName( name : String ) : String + { + if ( name == null || name == '' ) + { + return null; + } + var i = name.lastIndexOf( '.' ); + return i > 0 ? name.substring( 0, i ) : ''; + } } diff --git a/src/hex/domain/DomainExpert.hx b/src/hex/domain/DomainExpert.hx index 525a597..a038ea0 100644 --- a/src/hex/domain/DomainExpert.hx +++ b/src/hex/domain/DomainExpert.hx @@ -1,7 +1,6 @@ package hex.domain; import hex.core.HashCodeFactory; -import hex.domain.Domain; import hex.error.IllegalStateException; import hex.module.IModule; @@ -53,7 +52,7 @@ class DomainExpert } else { - var domain = DomainUtil.getDomain( key ); + var domain = Domain.getDomain( key ); this._removedModules.set( key, false ); this._subscribedModules.set( module, domain ); return domain; diff --git a/src/hex/domain/DomainUtil.hx b/src/hex/domain/DomainUtil.hx deleted file mode 100644 index a956c94..0000000 --- a/src/hex/domain/DomainUtil.hx +++ /dev/null @@ -1,35 +0,0 @@ -package hex.domain; - -import hex.error.PrivateConstructorException; - -/** - * ... - * @author Francis Bourre - */ -class DomainUtil -{ - static var _domain = new Map(); - - /** @private */ - function new() - { - throw new PrivateConstructorException(); - } - - static public function getDomain( domainName : String ) : Domain - { - var domain = null; - - if ( DomainUtil._domain.exists( domainName ) ) - { - domain = DomainUtil._domain.get( domainName ); - } - else - { - domain = Type.createInstance( Domain, [ domainName ] ); - DomainUtil._domain.set( domainName, domain ); - } - - return domain; - } -} \ No newline at end of file diff --git a/src/hex/domain/NoDomain.hx b/src/hex/domain/NoDomain.hx index cf4bac6..eaa5871 100644 --- a/src/hex/domain/NoDomain.hx +++ b/src/hex/domain/NoDomain.hx @@ -6,5 +6,5 @@ package hex.domain; */ class NoDomain { - public static var DOMAIN = DomainUtil.getDomain( "NoDomain" ); + public static var DOMAIN = Domain.getDomain( "NoDomain" ); } diff --git a/src/hex/domain/TopLevelDomain.hx b/src/hex/domain/TopLevelDomain.hx index 2b66519..acfba61 100644 --- a/src/hex/domain/TopLevelDomain.hx +++ b/src/hex/domain/TopLevelDomain.hx @@ -6,5 +6,5 @@ package hex.domain; */ class TopLevelDomain { - public static var DOMAIN = DomainUtil.getDomain( "TopLevelDomain" ); + public static var DOMAIN = Domain.getDomain( "TopLevelDomain" ); } \ No newline at end of file diff --git a/test/hex/domain/CoreDomainSuite.hx b/test/hex/domain/CoreDomainSuite.hx index 501e4a4..d8ea755 100644 --- a/test/hex/domain/CoreDomainSuite.hx +++ b/test/hex/domain/CoreDomainSuite.hx @@ -7,5 +7,11 @@ package hex.domain; class CoreDomainSuite { @Suite( "Domain" ) - public var list : Array> = [ DefaultDomainTest, DomainTest, DomainUtilTest, NoDomainTest, TopLevelDomainTest ]; + public var list : Array> = + [ + DefaultDomainTest, + DomainTest, + NoDomainTest, + TopLevelDomainTest + ]; } \ No newline at end of file diff --git a/test/hex/domain/DomainTest.hx b/test/hex/domain/DomainTest.hx index 848ce15..0f4e706 100644 --- a/test/hex/domain/DomainTest.hx +++ b/test/hex/domain/DomainTest.hx @@ -36,8 +36,28 @@ class DomainTest @Test( "Test getName function" ) public function testGetName() : Void { - var domain = Type.createInstance( Domain, [ "testGetName" ] ); - Assert.equals( "testGetName", domain.getName(), "'getName' method should return correct domain's name" ); + var domainName = Type.getClassName( Type.getClass( this ) ) + "_testGetName"; + var domain = Domain.getDomain( domainName ); + + Assert.equals( domainName, domain.getName(), "`getName` method should return correct domain's name" ); + } + + @Test( "Test `getParent` function" ) + public function testGetParent() : Void + { + var domainName = 'parent.' + Type.getClassName( Type.getClass( this ) ) + '_testGetParent'; + var domain = Domain.getDomain( domainName ); + + Assert.equals( TopLevelDomain.DOMAIN, domain.getParent(), "`getParent` method should return root parent" ); + + var childDomain = Domain.getDomain( domainName + '.child' ); + Assert.notEquals( domain, childDomain, "domains should not be the same" ); + Assert.equals( domain, childDomain.getParent(), "`getParent` method should return parent" ); + + var parentDomain = Domain.getDomain( 'parent' ); + Assert.notEquals( parentDomain, domain, "domains should not be the same" ); + Assert.notEquals( parentDomain, childDomain, "domains should not be the same" ); + Assert.equals( parentDomain, domain.getParent(), "`getParent` method should return root parent" ); } @Test( "Test getDomain function" ) @@ -48,7 +68,8 @@ class DomainTest Assert.equals( newDomain, domain, "getDomain method should return the same instance if it already exists" ); domain = Domain.getDomain( "nonExistingDomain" ); - Assert.equals( null, domain, "'getDomain' method should return null if the requested domain doesn't exist" ); + Assert.isInstanceOf( domain, Domain, "'getDomain' method should return new instance if it doesn't exist" ); + Assert.equals( "nonExistingDomain", domain.getName(), "'getDomain' method should return new instance if it doesn't exist" ); } @Test( "Test toString function" ) @@ -58,4 +79,26 @@ class DomainTest var expectedString = "hex.domain.Domain with name 'testToString'"; Assert.equals( expectedString, domain.toString(), "toString method should return expected string value" ); } + + @Test( "Test `getDomain` method" ) + public function testDomainCreation() : Void + { + var domainName = Type.getClassName( Type.getClass( this ) ) + "_testDomainCreation"; + + var domain = Domain.getDomain( domainName ); + Assert.isNotNull( domain, "`getDomain` function should create a domain if doesn't exist" ); + Assert.isInstanceOf( domain, Domain, "`getDomain` should return a domain instance of the requested type" ); + Assert.equals( domainName, domain.getName(), "domain's name should be the same that was requested" ); + } + + @Test( "Test `getDomain` twice" ) + public function testGetDomainTwice() : Void + { + var domainName = Type.getClassName( Type.getClass( this ) ) + "_testGetDomainTwice"; + + var domain = Domain.getDomain( domainName ); + var anotherDomainWithTheSameName = Domain.getDomain( domainName ); + + Assert.equals( domain, anotherDomainWithTheSameName, "getDomain should return the same domain" ); + } } diff --git a/test/hex/domain/DomainUtilTest.hx b/test/hex/domain/DomainUtilTest.hx deleted file mode 100644 index a29a934..0000000 --- a/test/hex/domain/DomainUtilTest.hx +++ /dev/null @@ -1,38 +0,0 @@ -package hex.domain; - -import hex.unittest.assertion.Assert; - -/** - * ... - * @author Tamas Kinsztler - */ -class DomainUtilTest -{ - @Test( "test constructor is private" ) - public function testPrivateConstructor() : Void - { - Assert.constructorIsPrivate( DomainUtil ); - } - - @Test( "Test 'getDomain' method" ) - public function testDomainCreation() : Void - { - var domainName = Type.getClassName( Type.getClass( this ) ) + "_testDomainCreation"; - - var domain = DomainUtil.getDomain( domainName ); - Assert.isNotNull( domain, "getDomain function should create a domain if doesn't exist" ); - Assert.isInstanceOf( domain, Domain, "getDomain should return a domain instance of the requested type" ); - Assert.equals( domainName, domain.getName(), "domain's name should be the same that was requested" ); - } - - @Test( "Test 'getDomain' twice" ) - public function testGetDomainTwice() : Void - { - var domainName = Type.getClassName( Type.getClass( this ) ) + "_testGetDomainTwice"; - - var domain = DomainUtil.getDomain( domainName ); - var anotherDomainWithTheSameName = Domain.getDomain( domainName ); - - Assert.equals( domain, anotherDomainWithTheSameName, "getDomain should return the same domain" ); - } -} From 5b37411671dcdd948a1375493deba97d86c80a9e Mon Sep 17 00:00:00 2001 From: St3veV Date: Thu, 2 Mar 2017 08:59:45 +0100 Subject: [PATCH 16/25] only reparenting domains when it's necessary --- src/hex/domain/Domain.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hex/domain/Domain.hx b/src/hex/domain/Domain.hx index 7ca6c0f..3905825 100644 --- a/src/hex/domain/Domain.hx +++ b/src/hex/domain/Domain.hx @@ -55,9 +55,9 @@ class Domain { domain = new Domain( domainName ); Domain._domains.set( domainName, domain ); + Domain._reparent(); } - Domain._reparent(); return domain; } From fcae63d58e9717601e9d65ac311693543631dfb7 Mon Sep 17 00:00:00 2001 From: St3veV Date: Thu, 2 Mar 2017 10:10:00 +0100 Subject: [PATCH 17/25] goodbye old logger and welcome dependency on hexLog + changes in build script for better testing --- .travis.yml | 6 +- build-each.hxml | 7 ++- haxelib.json | 2 +- src/hex/error/Exception.hx | 11 +++- src/hex/log/DomainLogger.hx | 63 ------------------- src/hex/log/ILogListener.hx | 16 ----- src/hex/log/ILogger.hx | 24 -------- src/hex/log/LogLevel.hx | 99 ------------------------------ src/hex/log/Logger.hx | 116 ----------------------------------- src/hex/log/LoggerMessage.hx | 29 --------- 10 files changed, 19 insertions(+), 354 deletions(-) delete mode 100644 src/hex/log/DomainLogger.hx delete mode 100644 src/hex/log/ILogListener.hx delete mode 100644 src/hex/log/ILogger.hx delete mode 100644 src/hex/log/LogLevel.hx delete mode 100644 src/hex/log/Logger.hx delete mode 100644 src/hex/log/LoggerMessage.hx diff --git a/.travis.yml b/.travis.yml index 6f4e535..c0cbdc0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,11 @@ before_install: - sudo apt-get install -qq libgtk2.0-0:i386 install: - - git clone --recursive -b $DEPENDENCIES_BRANCH https://github.com/DoclerLabs/hexUnit.git ./hexunit + - haxelib newrepo + - haxelib git hexunit https://github.com/DoclerLabs/hexUnit.git --never + - haxelib git hexlog https://github.com/DoclerLabs/hexLog.git --never + - haxelib dev hexcore . + - haxelib path hexcore - export DISPLAY=:99.0; - export AUDIODEV=null; - haxe flash/install.hxml diff --git a/build-each.hxml b/build-each.hxml index 883452f..ecd4306 100644 --- a/build-each.hxml +++ b/build-each.hxml @@ -1,5 +1,8 @@ -main MainCoreTest --cp src +-lib hexcore +-lib hexunit +-lib hexlog + -cp test --cp hexunit/src + -D debug=true \ No newline at end of file diff --git a/haxelib.json b/haxelib.json index 7d48edb..5fe5df9 100644 --- a/haxelib.json +++ b/haxelib.json @@ -10,6 +10,6 @@ "url": "https://github.com/DoclerLabs/hexCore", "dependencies": { - + "hexlog": "git:https://github.com/DoclerLabs/hexLog.git", } } \ No newline at end of file diff --git a/src/hex/error/Exception.hx b/src/hex/error/Exception.hx index 492261c..e5f8975 100644 --- a/src/hex/error/Exception.hx +++ b/src/hex/error/Exception.hx @@ -1,9 +1,12 @@ package hex.error; import haxe.PosInfos; -import hex.log.Logger; import hex.util.Stringifier; +#if (!macro && debug) +import hex.log.HexLog.*; +#end + /** * ... * @author Francis Bourre @@ -20,8 +23,10 @@ class Exception this.posInfos = posInfos; this.name = Stringifier.stringify( this ); - #if debug - Logger.error( this.toString() ); + #if (!macro && debug) + error(this.toString()); + #elseif (macro && debug) + trace(this.toString()); #end } diff --git a/src/hex/log/DomainLogger.hx b/src/hex/log/DomainLogger.hx deleted file mode 100644 index 8e215ba..0000000 --- a/src/hex/log/DomainLogger.hx +++ /dev/null @@ -1,63 +0,0 @@ -package hex.log; - -import haxe.PosInfos; -import hex.domain.Domain; -import hex.error.NullPointerException; -import hex.log.Logger; - -/** - * ... - * @author Francis Bourre - */ -@IgnoreCover -class DomainLogger implements ILogger -{ - var _domain : Domain; - var _logger : Logger; - - public function new( domain : Domain ) - { - if ( domain == null ) - { - throw new NullPointerException( "Domain should be specified for contructor call" ); - } - - this._domain = domain; - this._logger = Logger.getInstance(); - } - - public function clear() : Void - { - this._logger.clear(); - } - - public function debug( o : Dynamic, ?posInfos : PosInfos ) : Void - { - this._logger.log( o, LogLevel.DEBUG, this._domain, posInfos ); - } - - public function info( o : Dynamic, ?posInfos : PosInfos ) : Void - { - this._logger.log( o, LogLevel.INFO, this._domain, posInfos ); - } - - public function warn( o : Dynamic, ?posInfos : PosInfos ) : Void - { - this._logger.log( o, LogLevel.WARN, this._domain, posInfos ); - } - - public function error( o : Dynamic, ?posInfos : PosInfos ) : Void - { - this._logger.log( o, LogLevel.ERROR, this._domain, posInfos ); - } - - public function fatal( o : Dynamic, ?posInfos : PosInfos ) : Void - { - this._logger.log( o, LogLevel.FATAL, this._domain, posInfos ); - } - - public function getDomain() : Domain - { - return this._domain; - } -} \ No newline at end of file diff --git a/src/hex/log/ILogListener.hx b/src/hex/log/ILogListener.hx deleted file mode 100644 index 13e99cd..0000000 --- a/src/hex/log/ILogListener.hx +++ /dev/null @@ -1,16 +0,0 @@ -package hex.log; - -/** - * ... - * @author Francis Bourre - */ -interface ILogListener -{ - function onClear() : Void; - - /** - * Triggered when a Log event is dispatched by the Logging API. - * @see Logger - */ - function onLog( message : LoggerMessage ) : Void; -} \ No newline at end of file diff --git a/src/hex/log/ILogger.hx b/src/hex/log/ILogger.hx deleted file mode 100644 index f3d7f8c..0000000 --- a/src/hex/log/ILogger.hx +++ /dev/null @@ -1,24 +0,0 @@ -package hex.log; - -import haxe.PosInfos; -import hex.domain.Domain; - -/** - * @author Francis Bourre - */ -interface ILogger -{ - function clear() : Void; - - function debug( o : Dynamic, ?posInfos : PosInfos ) : Void; - - function info( o : Dynamic, ?posInfos : PosInfos ) : Void; - - function warn( o : Dynamic, ?posInfos : PosInfos ) : Void; - - function error( o : Dynamic, ?posInfos : PosInfos ) : Void; - - function fatal( o : Dynamic, ?posInfos : PosInfos ) : Void; - - function getDomain() : Domain; -} \ No newline at end of file diff --git a/src/hex/log/LogLevel.hx b/src/hex/log/LogLevel.hx deleted file mode 100644 index 005195c..0000000 --- a/src/hex/log/LogLevel.hx +++ /dev/null @@ -1,99 +0,0 @@ -package hex.log; - -/** - * ... - * @author Francis Bourre - */ -@IgnoreCover -class LogLevel -{ - static var _ALL = new LogLevel( 0 ); - static var _DEBUG = new LogLevel( 10000 ); - static var _INFO = new LogLevel( 20000 ); - static var _WARN = new LogLevel( 30000 ); - static var _ERROR = new LogLevel( 40000 ); - static var _FATAL = new LogLevel( 50000 ); - static var _OFF = new LogLevel( 60000 ); - - @:isVar public static var LEVELS( get, null ) : Array; - static function get_LEVELS() : Array - { - return [ LogLevel._ALL, LogLevel._DEBUG, LogLevel._INFO, LogLevel._WARN, LogLevel._ERROR, LogLevel._FATAL, LogLevel._OFF ]; - } - - @:isVar public static var ALL( get, null ) : LogLevel; - inline static function get_ALL() : LogLevel - { - return LogLevel._ALL; - } - - @:isVar public static var DEBUG( get, null ) : LogLevel; - inline static function get_DEBUG() : LogLevel - { - return LogLevel._DEBUG; - } - - @:isVar public static var INFO( get, null ) : LogLevel; - inline static function get_INFO() : LogLevel - { - return LogLevel._INFO; - } - - @:isVar public static var WARN( get, null ) : LogLevel; - inline static function get_WARN() : LogLevel - { - return LogLevel._WARN; - } - - @:isVar public static var ERROR( get, null ) : LogLevel; - inline static function get_ERROR() : LogLevel - { - return LogLevel._ERROR; - } - - @:isVar public static var FATAL( get, null ) : LogLevel; - inline static function get_FATAL() : LogLevel - { - return LogLevel._FATAL; - } - - @:isVar public static var OFF( get, null ) : LogLevel; - inline static function get_OFF() : LogLevel - { - return LogLevel._OFF; - } - - @:isVar public var value( get, null ) : Int; - function get_value() : Int - { - return this.value; - } - - public function new( value : Int ) - { - this.value = value; - } - - public function toString() : String - { - switch( this.value ) - { - case 0 : - return "ALL"; - case 10000 : - return "DEBUG"; - case 20000 : - return "INFO"; - case 30000 : - return "WARN"; - case 40000 : - return "ERROR"; - case 50000 : - return "FATAL"; - case 60000 : - return "OFF"; - } - - return ""; - } -} \ No newline at end of file diff --git a/src/hex/log/Logger.hx b/src/hex/log/Logger.hx deleted file mode 100644 index 5736591..0000000 --- a/src/hex/log/Logger.hx +++ /dev/null @@ -1,116 +0,0 @@ -package hex.log; - -import haxe.PosInfos; -import hex.domain.Domain; -import hex.domain.DomainDispatcher; -import hex.domain.NoDomain; -import hex.util.Stringifier; - -/** - * ... - * @author Francis Bourre - */ -@IgnoreCover -class Logger -{ - static var _Instance : Logger = null; - - var _dispatcher : DomainDispatcher; - var _level : LogLevel; - - public function new() - { - this.setLevel( LogLevel.ALL ); - this._dispatcher = new DomainDispatcher(); - } - - public static function getInstance() : Logger - { - if ( Logger._Instance == null ) - { - Logger._Instance = new Logger(); - } - - return Logger._Instance; - } - - public function setLevel( level : LogLevel ) : Void - { - this._level = level; - } - - public function getLevel() : LogLevel - { - return this._level; - } - - public function clear() : Void - { - this._dispatcher.dispatch( LoggerMessage.CLEAR ); - } - - public function log( o : Dynamic, level : LogLevel, ?domain : Domain, ?posInfos : PosInfos ) : Void - { - if ( this._level.value <= level.value ) - { - this._dispatcher.dispatch( LoggerMessage.LOG, domain, [ new LoggerMessage( o, level, domain == null ? NoDomain.DOMAIN : domain, posInfos ) ] ); - } - } - - public function addListener( listener : ILogListener, ?domain : Domain ) : Bool - { - this._dispatcher.addHandler( LoggerMessage.LOG, listener, listener.onLog, domain ); - return this._dispatcher.addHandler( LoggerMessage.CLEAR, listener, listener.onClear, domain ); - } - - public function removeListener( listener : ILogListener, ?domain : Domain ) : Bool - { - this._dispatcher.removeHandler( LoggerMessage.LOG, listener, listener.onLog, domain ); - return this._dispatcher.removeHandler( LoggerMessage.CLEAR, listener, listener.onClear, domain ); - } - - public function isRegistered( listener : ILogListener, ?domain : Domain ) : Bool - { - return this._dispatcher.isRegistered( listener, LoggerMessage.LOG, domain ); - } - - public function removeAllListeners() : Void - { - this._dispatcher.removeAllListeners(); - } - - public function toString() : String - { - return Stringifier.stringify( this ); - } - - public static function debug( o : Dynamic, ?domain : Domain, ?posInfos : PosInfos ) : Void - { - Logger.getInstance().log( o, LogLevel.DEBUG, domain, posInfos ); - } - - public static function info( o : Dynamic, ?domain : Domain, ?posInfos : PosInfos ) : Void - { - Logger.getInstance().log( o, LogLevel.INFO, domain, posInfos ); - } - - public static function warn( o : Dynamic, ?domain : Domain, ?posInfos : PosInfos ) : Void - { - Logger.getInstance().log( o, LogLevel.WARN, domain, posInfos ); - } - - public static function error( o : Dynamic, ?domain : Domain, ?posInfos : PosInfos ) : Void - { - Logger.getInstance().log( o, LogLevel.ERROR, domain, posInfos ); - } - - public static function fatal( o : Dynamic, ?domain : Domain, ?posInfos : PosInfos ) : Void - { - Logger.getInstance().log( o, LogLevel.FATAL, domain, posInfos ); - } - - public static function clear_all( ?domain : Domain ) : Void - { - Logger.getInstance().clear(); - } -} diff --git a/src/hex/log/LoggerMessage.hx b/src/hex/log/LoggerMessage.hx deleted file mode 100644 index 40c3366..0000000 --- a/src/hex/log/LoggerMessage.hx +++ /dev/null @@ -1,29 +0,0 @@ -package hex.log; - -import haxe.PosInfos; -import hex.domain.Domain; -import hex.event.MessageType; - -/** - * ... - * @author Francis Bourre - */ -@IgnoreCover -class LoggerMessage -{ - inline public static var LOG = new MessageType( "onLog" ); - inline public static var CLEAR = new MessageType( "onClear" ); - - public var message : Dynamic; - public var level : LogLevel; - public var domain : Domain; - public var posInfos : PosInfos; - - public function new( message : Dynamic, level : LogLevel, ?domain : Domain, ?posInfos : PosInfos ) - { - this.message = message; - this.level = level; - this.domain = domain; - this.posInfos = posInfos; - } -} \ No newline at end of file From 89877b07c5dd9181cda95dd554d3705541603e83 Mon Sep 17 00:00:00 2001 From: St3veV Date: Thu, 2 Mar 2017 10:17:14 +0100 Subject: [PATCH 18/25] adding dependencies branch to the git url --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c0cbdc0..eccdc32 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,8 +33,8 @@ before_install: install: - haxelib newrepo - - haxelib git hexunit https://github.com/DoclerLabs/hexUnit.git --never - - haxelib git hexlog https://github.com/DoclerLabs/hexLog.git --never + - haxelib git hexunit https://github.com/DoclerLabs/hexUnit.git#$DEPENDENCIES_BRANCH --never + - haxelib git hexlog https://github.com/DoclerLabs/hexLog.git#$DEPENDENCIES_BRANCH --never - haxelib dev hexcore . - haxelib path hexcore - export DISPLAY=:99.0; From ccfc2cd8dc6cc317fe5b3efdf66ef0a0d1871c77 Mon Sep 17 00:00:00 2001 From: St3veV Date: Thu, 2 Mar 2017 10:21:47 +0100 Subject: [PATCH 19/25] fix haxelib command syntax --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index eccdc32..bf4bb60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,8 +33,8 @@ before_install: install: - haxelib newrepo - - haxelib git hexunit https://github.com/DoclerLabs/hexUnit.git#$DEPENDENCIES_BRANCH --never - - haxelib git hexlog https://github.com/DoclerLabs/hexLog.git#$DEPENDENCIES_BRANCH --never + - haxelib git hexunit https://github.com/DoclerLabs/hexUnit.git $DEPENDENCIES_BRANCH --never + - haxelib git hexlog https://github.com/DoclerLabs/hexLog.git $DEPENDENCIES_BRANCH --never - haxelib dev hexcore . - haxelib path hexcore - export DISPLAY=:99.0; From a4705446c40fe12699cd14a30c7e5bbf95820daf Mon Sep 17 00:00:00 2001 From: St3veV Date: Thu, 2 Mar 2017 14:09:29 +0100 Subject: [PATCH 20/25] gitignore + fix in haxelib.json --- .gitignore | 2 ++ haxelib.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7429fd2..5b4e7c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ hexCore.iml +bin +.haxelib \ No newline at end of file diff --git a/haxelib.json b/haxelib.json index 5fe5df9..b8781d4 100644 --- a/haxelib.json +++ b/haxelib.json @@ -10,6 +10,6 @@ "url": "https://github.com/DoclerLabs/hexCore", "dependencies": { - "hexlog": "git:https://github.com/DoclerLabs/hexLog.git", + "hexlog": "git:https://github.com/DoclerLabs/hexLog.git" } } \ No newline at end of file From 8d18590891978975f7ae8e86573898656cc30d9e Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Fri, 3 Mar 2017 09:18:20 +0100 Subject: [PATCH 21/25] AsyncHandler replaced by AsyncCallback AsyncHandler instances needed to be stored to be triggered later. Its use was tricky in some situations. AsyncCallback solves that and uses abstract to trigger result and errors with the same method (like parameters overloading) --- src/hex/control/AsyncHandler.hx | 47 ---- src/hex/control/AsyncHandlerUtil.hx | 115 ---------- src/hex/control/Callback.hx | 26 +++ src/hex/control/async/AsyncCallback.hx | 233 ++++++++++++++++++++ src/hex/control/async/AsyncResult.hx | 25 +++ src/hex/control/async/Handler.hx | 7 + src/hex/control/async/IAsyncCallback.hx | 13 ++ src/hex/control/async/Nothing.hx | 9 + test/hex/control/AsyncCallbackTest.hx | 259 +++++++++++++++++++++++ test/hex/control/AsyncHandlerTest.hx | 98 --------- test/hex/control/AsyncHandlerUtilTest.hx | 132 ------------ test/hex/control/CoreControlSuite.hx | 6 +- 12 files changed, 573 insertions(+), 397 deletions(-) delete mode 100644 src/hex/control/AsyncHandler.hx delete mode 100644 src/hex/control/AsyncHandlerUtil.hx create mode 100644 src/hex/control/Callback.hx create mode 100644 src/hex/control/async/AsyncCallback.hx create mode 100644 src/hex/control/async/AsyncResult.hx create mode 100644 src/hex/control/async/Handler.hx create mode 100644 src/hex/control/async/IAsyncCallback.hx create mode 100644 src/hex/control/async/Nothing.hx create mode 100644 test/hex/control/AsyncCallbackTest.hx delete mode 100644 test/hex/control/AsyncHandlerTest.hx delete mode 100644 test/hex/control/AsyncHandlerUtilTest.hx diff --git a/src/hex/control/AsyncHandler.hx b/src/hex/control/AsyncHandler.hx deleted file mode 100644 index 31d673a..0000000 --- a/src/hex/control/AsyncHandler.hx +++ /dev/null @@ -1,47 +0,0 @@ -package hex.control; - -import hex.error.IllegalStateException; - -/** - * ... - * @author Francis Bourre - */ -class AsyncHandler implements ICompletable -{ - var _completeResponder : ArrayVoid>; - var _failResponder : ArrayVoid>; - - public function new() - { - this._completeResponder = []; - this._failResponder = []; - } - - public function onComplete( callback : ResultType->Void ) : ICompletable - { - this._completeResponder.push( callback ); - return this; - } - - public function onFail( callback : String->Void ) : ICompletable - { - this._failResponder.push( callback ); - return this; - } - - public function complete( result : ResultType ) : Void - { - for ( responder in this._completeResponder ) - { - responder( result ); - } - } - - public function fail( errorMessage : String ) : Void - { - for ( responder in this._failResponder ) - { - responder( errorMessage ); - } - } -} diff --git a/src/hex/control/AsyncHandlerUtil.hx b/src/hex/control/AsyncHandlerUtil.hx deleted file mode 100644 index 022d483..0000000 --- a/src/hex/control/AsyncHandlerUtil.hx +++ /dev/null @@ -1,115 +0,0 @@ -package hex.control; - -import haxe.ds.StringMap; -import haxe.macro.Context; -import haxe.macro.Expr; -import hex.error.PrivateConstructorException; - -/** - * ... - * @author Francis Bourre - */ -class AsyncHandlerUtil -{ - /** @private */ - function new() - { - throw new PrivateConstructorException(); - } - - static function arrowDecompose( f: Expr ) : { left: Expr, right: Expr } - { - var l: Expr = null; - var r: Expr = null; - - switch( f.expr ) - { - case EBinop( OpArrow, e1, e2 ): - { - l = e1; - r = e2; - } - - default: r = f; - } - - return { left: l, right: r }; - } - - static function _getLeftName( e : Expr ) - { - return AsyncHandlerUtil._getLeftNames( e )[ 0 ]; - } - - static function _getLeftNames( L : Expr, min : Int = 1 ) - { - var names : Array = - if ( L != null ) - { - switch( L.expr ) - { - case EConst( CIdent( s ) ): [ s ]; - - case EArrayDecl( els ): - els.map( function( e ) - return switch( e.expr ) - { - case EConst( CIdent( s ) ): s; - default: '_'; - }); - - case _: []; - } - } - else []; - - var t = ''; - while ( names.length < min ) names.push( t += '_' ); - return names; - } - - static function _getUniqueLocalVarNames( count, locals ) : Array - { - var r = new Array(); - var tmap = new StringMap(); - - while ( r.length < count ) - { - var t = '__tmp_' + Std.random( 0xffffff ); - if ( !locals.exists( t ) && !tmap.exists( t ) ) - { - r.push( t ); - tmap.set( t, 1 ); - } - } - return r; - } - - macro public static function on( h : ExprOf>, f : Expr ) : ExprOf> - { - var ad = AsyncHandlerUtil.arrowDecompose( f ); - var leftName = AsyncHandlerUtil._getLeftName( ad.left ); - var fExp = ad.right; - - var locals = AsyncHandlerUtil._getUniqueLocalVarNames( 1, Context.getLocalTVars() ); - var fName = locals.pop(); - - var mm = macro { function $fName( $leftName ) { return $fExp; } }; - return macro - { - $h.onComplete( $mm ); - } - } - - macro public static function triggers( h : ExprOf>, newHandler : ExprOf> ) : ExprOf> - { - var arg = AsyncHandlerUtil._getUniqueLocalVarNames( 1, Context.getLocalTVars() ).pop(); - - return macro - { - var $arg = ( $newHandler ); - $h.onComplete( $i{arg}.complete ); - $i{arg}; - } - } -} \ No newline at end of file diff --git a/src/hex/control/Callback.hx b/src/hex/control/Callback.hx new file mode 100644 index 0000000..f6641be --- /dev/null +++ b/src/hex/control/Callback.hx @@ -0,0 +1,26 @@ +package hex.control; + +/** + * ... + * @author back2dos + */ +abstract Callback( T->Void ) from ( T->Void ) +{ + inline function new(f) + this = f; + + @:from static function fromNiladic( f : Void->Void ) : Callback //inlining this seems to cause recursive implicit casts + return new Callback( function ( r ) f() ); + + public inline function invoke( data : T ) : Void //TODO: consider swallowing null here + ( this )( data ); + + @:to inline function toFunction() + return this; + + @:from static function fromMany( callbacks : Array> ) : Callback + return + function ( v : A ) + for ( callback in callbacks ) + callback.invoke( v ); +} \ No newline at end of file diff --git a/src/hex/control/async/AsyncCallback.hx b/src/hex/control/async/AsyncCallback.hx new file mode 100644 index 0000000..71501ce --- /dev/null +++ b/src/hex/control/async/AsyncCallback.hx @@ -0,0 +1,233 @@ +package hex.control.async; + +import haxe.ds.StringMap; +import haxe.macro.Context; +import haxe.macro.Expr; +import hex.error.Exception; +import hex.error.IllegalStateException; +import hex.error.PrivateConstructorException; + +/** + * ... + * @author Francis Bourre + */ +class AsyncCallback implements IAsyncCallback +{ + static var _map : Map, Bool> = new Map(); + + var _completeResponder : Array>; + var _failResponder : ArrayVoid>; + var _result : AsyncResult; + + public function new() + { + this._completeResponder = []; + this._failResponder = []; + this._result = Result.WAITING; + + AsyncCallback._map.set( this, true ); + } + + public static function get( callback : Callback> ) : AsyncCallback + { + var handler = new AsyncCallback(); + callback.invoke( handler._complete ); + return handler; + } + + macro public function whenComplete( ethis : Expr, clazz : Expr ) : ExprOf> + { + return AsyncCallbackUtil.whenComplete( ethis, clazz ); + } + + public function onComplete( onComplete : Callback ) : AsyncCallback + { + switch( this._result ) + { + case Result.WAITING: + this._completeResponder.push( onComplete ); + + case Result.DONE( result ): + onComplete.invoke( result ); + + case _: + } + + return this; + } + + public function onFail( onFail : Exception->Void ) : AsyncCallback + { + switch( this._result ) + { + case Result.WAITING: + this._failResponder.push( onFail ); + + case Result.FAILED( error ): + onFail( error ); + + case _: + } + + return this; + } + + function _complete( result : AsyncResult ) : Void + { + switch( result ) + { + case Result.DONE( result ): + this._doComplete( result ); + + case Result.FAILED( error ): + this._doFail( error ); + + case _: + } + } + + function _doComplete( result : ResultType ) : Void + { + if ( AsyncCallback._map.exists( this ) ) + { + this._result = result; + for ( responder in this._completeResponder ) + { + responder.invoke( result ); + } + + this._dispose(); + } + else + { + throw new IllegalStateException( 'AsyncCallback is disposed' ); + } + } + + function _doFail( error : Exception ) : Void + { + if ( AsyncCallback._map.exists( this ) ) + { + this._result = error; + for ( responder in this._failResponder ) + { + responder( error ); + } + + this._dispose(); + } + else + { + throw new IllegalStateException( 'AsyncCallback is disposed' ); + } + } + + function _dispose() : Void + { + AsyncCallback._map.remove( this ); + this._completeResponder = null; + this._failResponder = null; + } +} + +enum Result +{ + WAITING; + DONE( result : T ); + FAILED( e : Exception ); +} + +private class AsyncCallbackUtil +{ + /** @private */ + function new() + { + throw new PrivateConstructorException(); + } + + #if macro + static function arrowDecompose( f: Expr ) : { left: Expr, right: Expr } + { + var l: Expr = null; + var r: Expr = null; + + switch( f.expr ) + { + case EBinop( OpArrow, e1, e2 ): + { + l = e1; + r = e2; + } + + default: r = f; + } + + return { left: l, right: r }; + } + + static function _getLeftName( e : Expr ) + { + return AsyncCallbackUtil._getLeftNames( e )[ 0 ]; + } + + static function _getLeftNames( L : Expr, min : Int = 1 ) + { + var names : Array = + if ( L != null ) + { + switch( L.expr ) + { + case EConst( CIdent( s ) ): [ s ]; + + case EArrayDecl( els ): + els.map( function( e ) + return switch( e.expr ) + { + case EConst( CIdent( s ) ): s; + default: '_'; + }); + + case _: []; + } + } + else []; + + var t = ''; + while ( names.length < min ) names.push( t += '_' ); + return names; + } + + static function _getUniqueLocalVarNames( count, locals ) : Array + { + var r = new Array(); + var tmap = new StringMap(); + + while ( r.length < count ) + { + var t = '__tmp_' + Std.random( 0xffffff ); + if ( !locals.exists( t ) && !tmap.exists( t ) ) + { + r.push( t ); + tmap.set( t, 1 ); + } + } + return r; + } + + public static function whenComplete( h : ExprOf>, f : Expr ) : ExprOf> + { + var ad = AsyncCallbackUtil.arrowDecompose( f ); + var leftName = AsyncCallbackUtil._getLeftName( ad.left ); + var fExp = ad.right; + + var locals = AsyncCallbackUtil._getUniqueLocalVarNames( 1, Context.getLocalTVars() ); + var fName = locals.pop(); + + var mm = macro { function $fName( $leftName ) { return $fExp; } }; + return macro + { + $h.onComplete( $mm ); + } + } + #end +} \ No newline at end of file diff --git a/src/hex/control/async/AsyncResult.hx b/src/hex/control/async/AsyncResult.hx new file mode 100644 index 0000000..b3fc4c8 --- /dev/null +++ b/src/hex/control/async/AsyncResult.hx @@ -0,0 +1,25 @@ +package hex.control.async; + +import hex.control.async.AsyncCallback; + +/** + * ... + * @author Francis Bourre + */ +abstract AsyncResult( Result ) from ( Result ) +{ + inline function new( r ) + { + this = r; + } + + @:from public static inline function completed( result : ResultType ) : AsyncResult + { + return new AsyncResult( Result.DONE( result ) ); + } + + @:from public static inline function failed( error : hex.error.Exception ) : AsyncResult + { + return new AsyncResult( Result.FAILED( error) ); + } +} \ No newline at end of file diff --git a/src/hex/control/async/Handler.hx b/src/hex/control/async/Handler.hx new file mode 100644 index 0000000..cef2f87 --- /dev/null +++ b/src/hex/control/async/Handler.hx @@ -0,0 +1,7 @@ +package hex.control.async; + +/** + * @author Francis Bourre + */ + +typedef Handler = AsyncResult->Void; \ No newline at end of file diff --git a/src/hex/control/async/IAsyncCallback.hx b/src/hex/control/async/IAsyncCallback.hx new file mode 100644 index 0000000..31b4758 --- /dev/null +++ b/src/hex/control/async/IAsyncCallback.hx @@ -0,0 +1,13 @@ +package hex.control.async; + +import hex.error.Exception; + +/** + * @author Francis Bourre + */ + +interface IAsyncCallback +{ + function onComplete( onComplete : Callback ) : IAsyncCallback; + function onFail( onFail : Exception->Void ) : IAsyncCallback; +} \ No newline at end of file diff --git a/src/hex/control/async/Nothing.hx b/src/hex/control/async/Nothing.hx new file mode 100644 index 0000000..f8511be --- /dev/null +++ b/src/hex/control/async/Nothing.hx @@ -0,0 +1,9 @@ +package hex.control.async; + +/** + * @author Francis Bourre + */ +enum Nothing +{ + Nothing; +} \ No newline at end of file diff --git a/test/hex/control/AsyncCallbackTest.hx b/test/hex/control/AsyncCallbackTest.hx new file mode 100644 index 0000000..91b810f --- /dev/null +++ b/test/hex/control/AsyncCallbackTest.hx @@ -0,0 +1,259 @@ +package hex.control; + +import hex.control.async.AsyncCallback; +import hex.control.async.Handler; +import hex.control.async.IAsyncCallback; +import hex.control.async.Nothing; +import hex.error.Exception; +import hex.error.IllegalArgumentException; +import hex.error.IllegalStateException; +import hex.unittest.assertion.Assert; + +using hex.util.ArrayUtil; + +/** + * ... + * @author Francis Bourre + */ +class AsyncCallbackTest +{ + @Test( 'Test with argument result' ) + public function testWithArgumentResult() : Void + { + var result : String; + var error : Exception; + + //test completion + _loadString( false ).onComplete( function(r) {result = r;} ).onFail( function(e) {error = e;} ); + + Assert.equals( 'test', result ); + Assert.isNull( error ); + + //test failure + result = null; + error = null; + _loadString( true ).onComplete( function(r) { result = r; } ).onFail( function(e) { error = e; } ); + + Assert.isInstanceOf( error, Exception ); + Assert.equals( 'message', error.message ); + Assert.isNull( result ); + } + + @Test( 'Test without argument result' ) + public function testWithoutArgumentResult() : Void + { + var result : String; + var error : Exception; + + //test completion + _load( false ).onComplete( function() {result = 'test';} ).onFail( function(e) {error = e;} ); + + Assert.equals( 'test', result ); + Assert.isNull( error ); + + //test failure + result = null; + error = null; + _load( true ).onComplete( function() { result = 'test'; } ).onFail( function(e) { error = e; } ); + + Assert.isInstanceOf( error, Exception ); + Assert.equals( 'message', error.message ); + Assert.isNull( result ); + } + + @Test( 'Test completion twice' ) + public function testCompletionTwice() : Void + { + var error : IllegalStateException = null; + + try + { + AsyncCallback.get + ( + function ( handler : Handler ) + { + handler( Nothing ); + handler( Nothing ); + } + ); + } + catch ( e : IllegalStateException ) + { + error = e; + } + + Assert.isInstanceOf( error, IllegalStateException ); + } + + @Test( 'Test failure twice' ) + public function testFailureTwice() : Void + { + var error : IllegalStateException = null; + + try + { + AsyncCallback.get + ( + function ( handler : Handler ) + { + handler( new Exception( 'message' ) ); + handler( new Exception( 'message' ) ); + } + ); + } + catch ( e : IllegalStateException ) + { + error = e; + } + + Assert.isInstanceOf( error, IllegalStateException ); + } + + @Test( 'Test completion and failure at the same time' ) + public function testCompletionAndFailureAtTheSameTime() : Void + { + var error : IllegalStateException = null; + + try + { + AsyncCallback.get + ( + function ( handler : Handler ) + { + handler( Nothing ); + handler( new Exception( 'message' ) ); + } + ); + } + catch ( e : IllegalStateException ) + { + error = e; + } + + Assert.isInstanceOf( error, IllegalStateException ); + } + + @Test( "test simple lambda chaining" ) + public function testSimpleLambdaChaining() + { + var r0 = 0; + var r1 = 0; + + var async = AsyncCallback.get + ( + function ( handler : Handler ) + { + handler( 4 ); + } + ); + + async + .whenComplete( i => r0 = 3 + i ) + .whenComplete( j => r1 = r0 * 2 ); + + Assert.equals( 7, r0, "result0 should be 3 + 4" ); + Assert.equals( 14, r1, "result1 should be 7 * 2" ); + } + + @Test( "test try catch" ) + public function testTryCatch() + { + var error : Exception = null; + var r0 = 0.0; + + + var async = AsyncCallback.get + ( + function ( handler : Handler ) + { + try + { + var a = []; + handler( a[2] ); + } + catch ( e : Dynamic ) + { + handler( new IllegalArgumentException( 'message' ) ); + } + } + ); + + async + .whenComplete( i => r0 = 3 + i ) + .onFail( function(e) { error = e; } ); + + Assert.isInstanceOf( error, Exception ); + Assert.equals( 'message', error.message ); + Assert.equals( 0.0, r0 ); + } + + @Test( "test chaining with ArrayUtil" ) + public function testChainingWithArrayUtil() + { + var collection = [ for ( i in 0...10 ) { id: i, name: "user_" + i, isMember: i % 2 == 0 } ]; + + var async = AsyncCallback.get + ( + function ( handler : Handler> ) + { + handler( collection ); + } + ); + + async + .whenComplete( a => a.forEach( e => e.name += "Test" ) ) + .whenComplete( a => collection = a.filters( e => e.isMember ) ) + .whenComplete( a => a.forEach( e => if ( e.id > 5 ) collection.remove( e ) ) ); + + Assert.deepEquals( + [ + { id:0, name: "user_0Test", isMember: true }, + { id:2, name: "user_2Test", isMember: true }, + { id:4, name: "user_4Test", isMember: true } + ] + , collection, "collection content should be the same" ); + } + + static function _load( failure : Bool ) : IAsyncCallback + { + return AsyncCallback.get + ( + function ( handler : Handler ) + { + if ( !failure ) + { + handler( Nothing ); + } + else + { + handler( new Exception( 'message' ) ); + } + } + ); + } + + static function _loadString( failure : Bool ) : IAsyncCallback + { + return AsyncCallback.get + ( + function ( handler : Handler ) + { + if ( !failure ) + { + handler( 'test' ); + } + else + { + handler( new Exception( 'message' ) ); + } + } + ); + } +} + +typedef User = +{ + var id : Int; + var name : String; + var isMember : Bool; +} \ No newline at end of file diff --git a/test/hex/control/AsyncHandlerTest.hx b/test/hex/control/AsyncHandlerTest.hx deleted file mode 100644 index 9acdf12..0000000 --- a/test/hex/control/AsyncHandlerTest.hx +++ /dev/null @@ -1,98 +0,0 @@ -package hex.control; - -import hex.error.IllegalStateException; -import hex.unittest.assertion.Assert; - -/** - * ... - * @author Francis Bourre - */ -class AsyncHandlerTest -{ - var result0 : String; - var result1 : String; - var error0 : String; - var error1 : String; - - @Before - function _init() : Void - { - result0 = ""; - result1 = ""; - error0 = ""; - error1 = ""; - } - - @Test( "test callbacks" ) - public function testCallbacks() - { - var responder = new AsyncHandler(); - - responder - .onComplete( function( s : String) { result0 = s; } ) - .onComplete( function( s : String) { result1 = s; } ) - .onFail( function( e : String) { error0 = e; } ) - .onFail( function( e : String) { error1 = e; } ); - - responder.complete( "hello" ); - - Assert.equals( "hello", result0, "result0 should be passed" ); - Assert.equals( "hello", result1, "result1 should be passed" ); - Assert.equals( "", error0, "error0 should not be setted" ); - Assert.equals( "", error1, "error1 should not be setted" ); - - this._init(); - responder.complete( "hello2" ); - - Assert.equals( "hello2", result0, "result0 should be passed" ); - Assert.equals( "hello2", result1, "result1 should be passed" ); - Assert.equals( "", error0, "error0 should not be setted" ); - Assert.equals( "", error1, "error1 should not be setted" ); - - this._init(); - responder.fail( "error" ); - - Assert.equals( "", result0, "result0 should not be setted" ); - Assert.equals( "", result1, "result1 should not be setted" ); - Assert.equals( "error", error0, "error0 should be passed" ); - Assert.equals( "error", error1, "error1 should be passed" ); - - this._init(); - responder.fail( "error2" ); - - Assert.equals( "", result0, "result0 should not be setted" ); - Assert.equals( "", result1, "result1 should not be setted" ); - Assert.equals( "error2", error0, "error0 should be passed" ); - Assert.equals( "error2", error1, "error1 should be passed" ); - - this._init(); - responder.complete( "hello" ); - - Assert.equals( "hello", result0, "result0 should be passed" ); - Assert.equals( "hello", result1, "result1 should be passed" ); - Assert.equals( "", error0, "error0 should not be setted" ); - Assert.equals( "", error1, "error1 should not be setted" ); - } - - @Test( "test callbacks" ) - public function testCallbackChaining() - { - var responder = new AsyncHandler(); - var anotheResponder = new AsyncHandler(); - - var intResult = 0; - - responder - .onComplete( function( i : Int ) { anotheResponder.onComplete( function( s : String ) { result0 = ">" + s; } ); anotheResponder.complete( ">" + i ); } ) - .onComplete( function( i : Int ) { intResult = i; } ) - .onFail( function( e : String) { error0 = e; } ) - .onFail( function( e : String) { error1 = e; } ); - - responder.complete( 3 ); - - Assert.equals( ">>3", result0, "result0 should be passed" ); - Assert.equals( 3, intResult, "result1 should be passed" ); - Assert.equals( "", error0, "error0 should not be setted" ); - Assert.equals( "", error1, "error1 should not be setted" ); - } -} \ No newline at end of file diff --git a/test/hex/control/AsyncHandlerUtilTest.hx b/test/hex/control/AsyncHandlerUtilTest.hx deleted file mode 100644 index 8cc4c57..0000000 --- a/test/hex/control/AsyncHandlerUtilTest.hx +++ /dev/null @@ -1,132 +0,0 @@ -package hex.control; - -#if (!neko || haxe_ver >= "3.3") -import haxe.Timer; -import hex.unittest.assertion.Assert; -import hex.unittest.runner.MethodRunner; - -using hex.util.ArrayUtil; -using hex.control.AsyncHandlerUtil; - -/** - * ... - * @author Francis Bourre - */ -class AsyncHandlerUtilTest -{ - var result : Int; - - @Test( "test constructor is private" ) - public function testPrivateConstructor() : Void - { - Assert.constructorIsPrivate( AsyncHandlerUtil ); - } - - @Test( "test simple lambda" ) - public function testSimpleLambda() - { - var result = 0; - - var handler = new AsyncHandler(); - handler.on( i => result = i + 3 ); - handler.complete( 4 ); - - Assert.equals( 7, result, "result should be sum of arg and 3" ); - } - - @Test( "test simple lambda chaining" ) - public function testSimpleLambdaChaining() - { - var result0 = 0; - var result1 = 0; - - var handler = new AsyncHandler(); - - handler - .on( i => result0 = i + 3 ) - .on( j => result1 = result0 * 2 ); - - handler.complete( 4 ); - - Assert.equals( 7, result0, "result0 should be 3 + 4" ); - Assert.equals( 14, result1, "result1 should be 7 * 2" ); - } - - @Async( "test lambda chaining" ) - public function testChainingLambdas() - { - this.result = 0; - - var handler = new AsyncHandler(); - - handler - .on( i => this.result = i + 3 ) - .on( j => this.result *= 2 ) - .triggers ( new AsyncHandler() - .on( l => this.result *= 20 ) - .on( l => this.result -= 1 ) - ) - .triggers ( new TimeoutIntHandler() ) - .on( l => this.result -= 3 - ) - .onComplete( MethodRunner.asyncHandler( this._onChainingEnd ) ); - - - handler.complete( 4 ); - } - - private function _onChainingEnd( i : Int ) : Void - { - Assert.equals( 276, this.result, "result should be ((4 + 3) *20) -1 -3" ); - } - - @Test( "test chaining with ArrayUtil" ) - public function testChainingWithArrayUtil() - { - var collection = [ for ( i in 0...10 ) { id: i, name: "user_"+i, isMember: i%2==0 } ]; - - var handler = new AsyncHandler>(); - - handler - .on( a => a.forEach( e => e.name += "Test" ) ) - .on( a => collection = a.filters( e => e.isMember ) ) - .on( a => a.forEach( e => if ( e.id > 5 ) collection.remove( e ) ) ); - - - handler.complete( collection ); - - Assert.deepEquals( - [ - { id:0, name: "user_0Test", isMember: true }, - { id:2, name: "user_2Test", isMember: true }, - { id:4, name: "user_4Test", isMember: true } - ] - , collection, "collection content should be the same" ); - } -} - -private class TimeoutIntHandler extends AsyncHandler -{ - public function new() - { - super(); - } - - override public function complete( i : Int ) : Void - { - Timer.delay( this._do.bind( i ), 100 ); - } - - private function _do( i : Int ) : Void - { - super.complete( i ); - } -} - -typedef User = -{ - var id : Int; - var name : String; - var isMember : Bool; -} -#end diff --git a/test/hex/control/CoreControlSuite.hx b/test/hex/control/CoreControlSuite.hx index b4ac619..814fee3 100644 --- a/test/hex/control/CoreControlSuite.hx +++ b/test/hex/control/CoreControlSuite.hx @@ -9,9 +9,5 @@ import hex.control.payload.CorePayloadSuite; class CoreControlSuite { @Suite( "Control" ) - #if !neko - public var list : Array> = [ AsyncHandlerTest, AsyncHandlerUtilTest, AsyncResponderTest, CorePayloadSuite ]; - #else - public var list : Array> = [ AsyncHandlerTest, AsyncResponderTest, CorePayloadSuite ]; - #end + public var list : Array> = [ AsyncCallbackTest, AsyncResponderTest, CorePayloadSuite ]; } \ No newline at end of file From 91c569fb75739514af9c7faa43b1710f2d41c6e2 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Fri, 3 Mar 2017 09:35:13 +0100 Subject: [PATCH 22/25] Dispatcher.dispatch sealing dispatch method is sealed during the whole stack execution and dispatching requests are stacked to be executed later. --- src/hex/event/Dispatcher.hx | 103 +++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 48 deletions(-) diff --git a/src/hex/event/Dispatcher.hx b/src/hex/event/Dispatcher.hx index e3111cb..e072c97 100644 --- a/src/hex/event/Dispatcher.hx +++ b/src/hex/event/Dispatcher.hx @@ -23,61 +23,68 @@ class Dispatcher implements IDispatcher public function dispatch( messageType : MessageType, ?data : Array ) : Void { - this._seal( true ); - - var parameters : Array = null; - - var iterator = this._listeners.keys(); - while ( iterator.hasNext() ) - { - var listener : ListenerType = iterator.next(); - var m : Map = this._listeners.get( listener ); + if ( !this._isSealed ) + { + this._seal( true ); - if ( Lambda.count( m ) > 0 ) - { - if ( m.exists( messageType ) ) + var parameters : Array = null; + + var iterator = this._listeners.keys(); + while ( iterator.hasNext() ) + { + var listener : ListenerType = iterator.next(); + var m : Map = this._listeners.get( listener ); + + if ( Lambda.count( m ) > 0 ) { - var handler : CallbackHandler = m.get( messageType ); - handler.call( data ); + if ( m.exists( messageType ) ) + { + var handler : CallbackHandler = m.get( messageType ); + handler.call( data ); + } } - } - else - { - var messageName : String = messageType; - var callback = Reflect.field( listener, messageName ); - if ( callback != null && messageName != 'handleMessage' ) - { - Reflect.callMethod ( listener, callback, data ); - } - else - { - callback = Reflect.field( listener, 'handleMessage' ); - - if ( callback != null ) + else + { + var messageName : String = messageType; + var callback = Reflect.field( listener, messageName ); + if ( callback != null && messageName != 'handleMessage' ) { - if ( parameters == null ) + Reflect.callMethod ( listener, callback, data ); + } + else + { + callback = Reflect.field( listener, 'handleMessage' ); + + if ( callback != null ) { - parameters = [messageType]; - if ( data != null ) + if ( parameters == null ) { - parameters = parameters.concat( data ); - } - } - - Reflect.callMethod ( listener, callback, parameters ); - - } else - { - var msg : String = Stringifier.stringify( this ) + ".dispatch failed. " + - " You must implement '" + messageType + "' or 'handleMessage' method in '" + - Stringifier.stringify( listener ) + "' instance."; - throw( new UnsupportedOperationException( msg ) ); + parameters = [messageType]; + if ( data != null ) + { + parameters = parameters.concat( data ); + } + } + + Reflect.callMethod ( listener, callback, parameters ); + + } else + { + var msg : String = Stringifier.stringify( this ) + ".dispatch failed. " + + " You must implement '" + messageType + "' or 'handleMessage' method in '" + + Stringifier.stringify( listener ) + "' instance."; + throw( new UnsupportedOperationException( msg ) ); + } } - } - } - } - - this._seal( false ); + } + } + + this._seal( false ); + } + else + { + this._cachedMethodCalls.push( this.dispatch.bind( messageType, data ) ); + } } public function addHandler( messageType : MessageType, scope : Dynamic, callback : T ) : Bool From 410eef243920c0356f9348ec3d753c825d671d31 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Fri, 3 Mar 2017 11:08:36 +0100 Subject: [PATCH 23/25] AsyncCallbackTest enhancement Better exception matching when onFail is triggered --- test/hex/control/AsyncCallbackTest.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/hex/control/AsyncCallbackTest.hx b/test/hex/control/AsyncCallbackTest.hx index 91b810f..ade49c1 100644 --- a/test/hex/control/AsyncCallbackTest.hx +++ b/test/hex/control/AsyncCallbackTest.hx @@ -182,7 +182,7 @@ class AsyncCallbackTest .whenComplete( i => r0 = 3 + i ) .onFail( function(e) { error = e; } ); - Assert.isInstanceOf( error, Exception ); + Assert.isInstanceOf( error, IllegalArgumentException ); Assert.equals( 'message', error.message ); Assert.equals( 0.0, r0 ); } From 82d27ec33d13ca5c5db12983633d1def5140738d Mon Sep 17 00:00:00 2001 From: St3veV Date: Fri, 3 Mar 2017 15:14:45 +0100 Subject: [PATCH 24/25] updating travis build to use dev dependencies --- .travis.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index bf4bb60..0d2883d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,8 +33,12 @@ before_install: install: - haxelib newrepo - - haxelib git hexunit https://github.com/DoclerLabs/hexUnit.git $DEPENDENCIES_BRANCH --never - - haxelib git hexlog https://github.com/DoclerLabs/hexLog.git $DEPENDENCIES_BRANCH --never +#hexLog + - git clone --recursive -b $DEPENDENCIES_BRANCH https://github.com/DoclerLabs/hexLog.git ./hexlog + - haxelib dev hexlog ./hexlog +#hexUnit + - git clone --recursive -b $DEPENDENCIES_BRANCH https://github.com/DoclerLabs/hexUnit.git ./hexunit + - haxelib dev hexunit ./hexunit - haxelib dev hexcore . - haxelib path hexcore - export DISPLAY=:99.0; From 6ddc43010e2a31f3ff5ebdf3b0891d0bc95af128 Mon Sep 17 00:00:00 2001 From: Laurent Deketelaere Date: Mon, 6 Mar 2017 18:17:50 +0100 Subject: [PATCH 25/25] Set git as a version number + clean dependencies --- haxelib.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/haxelib.json b/haxelib.json index b8781d4..6e84b50 100644 --- a/haxelib.json +++ b/haxelib.json @@ -6,7 +6,7 @@ "description": "Independent core elements for building OOP projects and frameworks", "contributors": ["doclerlabs"], "releasenote": "First release. Still alpha testing", - "version": "0.1.0", + "version": "git", "url": "https://github.com/DoclerLabs/hexCore", "dependencies": {