From ac923787e8fc0d8477a0b0ce6a6f29836f9f7e7d Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Wed, 28 Jun 2017 10:28:44 +0200 Subject: [PATCH 1/8] Two modules listening each other in Flow --- src/hex/compiler/parser/flow/ObjectParser.hx | 30 +++++++++++++++++-- .../flow/twoModulesListeningEachOther.flow | 22 ++++++++++++++ .../compiler/parser/flow/FlowCompilerTest.hx | 8 ++--- .../parser/flow/MockCustomStaticFlowParser.hx | 2 +- .../parser/flow/StaticFlowCompilerTest.hx | 1 - 5 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 test/context/flow/twoModulesListeningEachOther.flow diff --git a/src/hex/compiler/parser/flow/ObjectParser.hx b/src/hex/compiler/parser/flow/ObjectParser.hx index 0481462..196b154 100644 --- a/src/hex/compiler/parser/flow/ObjectParser.hx +++ b/src/hex/compiler/parser/flow/ObjectParser.hx @@ -63,6 +63,30 @@ class ObjectParser extends AbstractExprParser } ); this._builder.build( OBJECT( constructorVO ) ); + /*case macro $keyword( $a { args } ): + trace( new haxe.macro.Printer().printExpr( e ) ); + trace( keyword ); + trace( args );*/ + + case macro when( $a { when } ).then( $a { then } ): + + var callback = ExpressionUtil.compressField( then[0] ); + var ident = callback.split('.').shift(); + var vo = new hex.ioc.vo.DomainListenerVO( ident, ExpressionUtil.getIdent( when[0] ) ); + + if ( when.length == 2 ) + { + var arg = new hex.ioc.vo.DomainListenerVOArguments(); + arg.staticRef = ExpressionUtil.compressField( when[1] ); + var cb = callback.split('.'); + if ( cb.length > 1 ) arg.method = cb[ 1 ]; + vo.arguments = [ arg ]; + arg.filePosition = e.pos; + } + + vo.filePosition = e.pos; + this._builder.build( DOMAIN_LISTENER( vo ) ); + case _: switch( e.expr ) @@ -84,6 +108,8 @@ class ObjectParser extends AbstractExprParser } //logger.debug(e); } + + function _getConstructorVO( ident : String, value : Expr ) : ConstructorVO { @@ -166,9 +192,9 @@ class ObjectParser extends AbstractExprParser } case ECall( _.expr => EConst(CIdent(keyword)), params ): - if ( this.parser.methodParser.exists( keyword ) ) + if ( this.parser.buildMethodParser.exists( keyword ) ) { - return this.parser.methodParser.get( keyword )( this.parser, new ConstructorVO( ident ), params, value ); + return this.parser.buildMethodParser.get( keyword )( this.parser, new ConstructorVO( ident ), params, value ); } else { diff --git a/test/context/flow/twoModulesListeningEachOther.flow b/test/context/flow/twoModulesListeningEachOther.flow new file mode 100644 index 0000000..d24701e --- /dev/null +++ b/test/context/flow/twoModulesListeningEachOther.flow @@ -0,0 +1,22 @@ +/* + + + + + + + + + + + +*/ + +@context( name = 'applicationContext' ) +{ + chat = new hex.ioc.parser.xml.mock.MockChatModule(); + translation = new hex.ioc.parser.xml.mock.MockTranslationModule(); + + when( chat, hex.ioc.parser.xml.mock.MockChatModule.TEXT_INPUT ).then( translation.onSomethingToTranslate ); + when( translation ).then( chat ); +} \ No newline at end of file diff --git a/test/hex/compiler/parser/flow/FlowCompilerTest.hx b/test/hex/compiler/parser/flow/FlowCompilerTest.hx index ed96549..740cbf9 100644 --- a/test/hex/compiler/parser/flow/FlowCompilerTest.hx +++ b/test/hex/compiler/parser/flow/FlowCompilerTest.hx @@ -554,7 +554,7 @@ class FlowCompilerTest Assert.notEquals( intInstance, stringInstance ); } - /*@Test( "test building two modules listening each other" ) + @Test( "test building two modules listening each other" ) public function testBuildingTwoModulesListeningEachOther() : Void { this._applicationAssembler = FlowCompiler.compile( "context/flow/twoModulesListeningEachOther.flow" ); @@ -568,7 +568,7 @@ class FlowCompilerTest chat.dispatchDomainEvent( MockChatModule.TEXT_INPUT, [ "Bonjour" ] ); Assert.equals( "Hello", chat.translatedMessage, "" ); - }*/ + } /*@Ignore( "test building two modules listening each other with adapter" ) public function testBuildingTwoModulesListeningEachOtherWithAdapter() : Void @@ -949,7 +949,7 @@ class FlowCompilerTest Assert.equals( 20, r.height ); } - /*@Test( "test add custom parser" ) + @Test( "test add custom parser" ) public function testAddCustomParser() : Void { MockCustomStaticFlowParser.prepareCompiler(); @@ -959,7 +959,7 @@ class FlowCompilerTest Assert.equals( 11, this._getCoreFactory().locate( "i" ) ); Assert.equals( 11, this._getCoreFactory().locate( "p" ).x ); Assert.equals( 13, this._getCoreFactory().locate( "p" ).y ); - }*/ + } @Test( "test alias primitive" ) public function testAliasPrimitive() : Void diff --git a/test/hex/compiler/parser/flow/MockCustomStaticFlowParser.hx b/test/hex/compiler/parser/flow/MockCustomStaticFlowParser.hx index df9c105..fb99b64 100644 --- a/test/hex/compiler/parser/flow/MockCustomStaticFlowParser.hx +++ b/test/hex/compiler/parser/flow/MockCustomStaticFlowParser.hx @@ -12,7 +12,7 @@ class MockCustomStaticFlowParser /** @private */ function new() throw new hex.error.PrivateConstructorException(); macro public static function prepareCompiler() : haxe.macro.Expr.ExprOf { - FlowExpressionParser.parser.methodParser.set( 'add', hex.compiletime.flow.parser.custom.AddParser.parse ); + FlowExpressionParser.parser.buildMethodParser.set( 'add', hex.compiletime.flow.parser.custom.AddParser.parse ); CompileTimeSettings.factoryMap.set( 'haxe.macro.Expr', hex.compiletime.factory.CodeFactory.build ); return macro true; } diff --git a/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx b/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx index d8e3e6f..a0f275e 100644 --- a/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx +++ b/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx @@ -1,6 +1,5 @@ package hex.compiler.parser.flow; - import hex.compiler.parser.flow.StaticFlowCompiler; import hex.core.IApplicationAssembler; import hex.di.Injector; From 2f28482bdbbc447911d17411dc69f61ce8acfa3a Mon Sep 17 00:00:00 2001 From: Laurent Deketelaere Date: Wed, 28 Jun 2017 10:33:12 +0200 Subject: [PATCH 2/8] - _readFile method on every compilers are public - rename _readXmlFile to _readFile --- src/hex/compiler/parser/flow/FlowCompiler.hx | 10 +++++----- src/hex/compiler/parser/flow/StaticFlowCompiler.hx | 12 ++++++------ src/hex/compiler/parser/xml/StaticXmlCompiler.hx | 12 ++++++------ src/hex/compiler/parser/xml/XmlCompiler.hx | 14 +++++++------- src/hex/ioc/parser/xml/XmlReader.hx | 14 +++++++------- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/hex/compiler/parser/flow/FlowCompiler.hx b/src/hex/compiler/parser/flow/FlowCompiler.hx index 77c40e0..6e79020 100644 --- a/src/hex/compiler/parser/flow/FlowCompiler.hx +++ b/src/hex/compiler/parser/flow/FlowCompiler.hx @@ -24,11 +24,11 @@ import hex.preprocess.flow.MacroConditionalVariablesProcessor; class FlowCompiler { #if macro - static function _readFile( fileName : String, - ?applicationContextName : String, - ?preprocessingVariables : Expr, - ?conditionalVariables : Expr, - ?applicationAssemblerExpression : Expr ) : ExprOf + public static function _readFile( fileName : String, + ?applicationContextName : String, + ?preprocessingVariables : Expr, + ?conditionalVariables : Expr, + ?applicationAssemblerExpression : Expr ) : ExprOf { LogManager.context = new MacroLoggerContext(); diff --git a/src/hex/compiler/parser/flow/StaticFlowCompiler.hx b/src/hex/compiler/parser/flow/StaticFlowCompiler.hx index 5e54378..f2e3bd4 100644 --- a/src/hex/compiler/parser/flow/StaticFlowCompiler.hx +++ b/src/hex/compiler/parser/flow/StaticFlowCompiler.hx @@ -37,12 +37,12 @@ using hex.util.LambdaUtil; class StaticFlowCompiler { #if macro - static public function _readFile( fileName : String, - ?applicationContextName : String, - ?preprocessingVariables : Expr, - ?conditionalVariables : Expr, - ?applicationAssemblerExpression : Expr, - isExtending : Bool = false ) : Expr + public static function _readFile( fileName : String, + ?applicationContextName : String, + ?preprocessingVariables : Expr, + ?conditionalVariables : Expr, + ?applicationAssemblerExpression : Expr, + isExtending : Bool = false ) : Expr { LogManager.context = new MacroLoggerContext(); diff --git a/src/hex/compiler/parser/xml/StaticXmlCompiler.hx b/src/hex/compiler/parser/xml/StaticXmlCompiler.hx index 2d3da3c..3aa3daa 100644 --- a/src/hex/compiler/parser/xml/StaticXmlCompiler.hx +++ b/src/hex/compiler/parser/xml/StaticXmlCompiler.hx @@ -31,12 +31,12 @@ import hex.util.MacroUtil; class StaticXmlCompiler { #if macro - static public function _readFile( fileName : String, - ?applicationContextName : String, - ?preprocessingVariables : Expr, - ?conditionalVariables : Expr, - ?applicationAssemblerExpression : Expr, - isExtending : Bool = false ) : Expr + public static function _readFile( fileName : String, + ?applicationContextName : String, + ?preprocessingVariables : Expr, + ?conditionalVariables : Expr, + ?applicationAssemblerExpression : Expr, + isExtending : Bool = false ) : Expr { LogManager.context = new MacroLoggerContext(); diff --git a/src/hex/compiler/parser/xml/XmlCompiler.hx b/src/hex/compiler/parser/xml/XmlCompiler.hx index 14dd99d..ac63f9a 100644 --- a/src/hex/compiler/parser/xml/XmlCompiler.hx +++ b/src/hex/compiler/parser/xml/XmlCompiler.hx @@ -26,11 +26,11 @@ using StringTools; class XmlCompiler { #if macro - static function _readXmlFile( fileName : String, - ?applicationContextName : String, - ?preprocessingVariables : Expr, - ?conditionalVariables : Expr, - ?applicationAssemblerExpression : Expr ) : ExprOf + public static function _readFile( fileName : String, + ?applicationContextName : String, + ?preprocessingVariables : Expr, + ?conditionalVariables : Expr, + ?applicationAssemblerExpression : Expr ) : ExprOf { LogManager.context = new MacroLoggerContext(); @@ -57,7 +57,7 @@ class XmlCompiler ?preprocessingVariables : Expr, ?conditionalVariables : Expr ) : ExprOf { - return XmlCompiler._readXmlFile( fileName, applicationContextName, preprocessingVariables, conditionalVariables ); + return XmlCompiler._readFile( fileName, applicationContextName, preprocessingVariables, conditionalVariables ); } macro public static function compileWithAssembler( assemblerExpr : Expr, @@ -66,6 +66,6 @@ class XmlCompiler ?preprocessingVariables : Expr, ?conditionalVariables : Expr ) : ExprOf { - return XmlCompiler._readXmlFile( fileName, applicationContextName, preprocessingVariables, conditionalVariables, assemblerExpr ); + return XmlCompiler._readFile( fileName, applicationContextName, preprocessingVariables, conditionalVariables, assemblerExpr ); } } diff --git a/src/hex/ioc/parser/xml/XmlReader.hx b/src/hex/ioc/parser/xml/XmlReader.hx index 4a7feb3..53262a0 100644 --- a/src/hex/ioc/parser/xml/XmlReader.hx +++ b/src/hex/ioc/parser/xml/XmlReader.hx @@ -210,10 +210,10 @@ class XmlReader } } - static function _readXmlFile( fileName : String, - ?applicationContextName : String, - ?preprocessingVariables : Expr, - ?conditionalVariables : Expr ) : ExprOf + public static function _readFile( fileName : String, + ?applicationContextName : String, + ?preprocessingVariables : Expr, + ?conditionalVariables : Expr ) : ExprOf { var conditionalVariablesMap = MacroConditionalVariablesProcessor.parse( conditionalVariables ); var conditionalVariablesChecker = new ConditionalVariablesChecker( conditionalVariablesMap ); @@ -249,7 +249,7 @@ class XmlReader ?preprocessingVariables : Expr, ?conditionalVariables : Expr ) : ExprOf { - return XmlReader._readXmlFile( fileName, applicationContextName, preprocessingVariables, conditionalVariables ); + return XmlReader._readFile( fileName, applicationContextName, preprocessingVariables, conditionalVariables ); } macro public static function getXml( fileName : String, @@ -258,7 +258,7 @@ class XmlReader ?conditionalVariables : Expr ) : ExprOf { var tp = MacroUtil.getPack( Type.getClassName( Xml ) ); - var data = XmlReader._readXmlFile( fileName, applicationContextName, preprocessingVariables, conditionalVariables ); + var data = XmlReader._readFile( fileName, applicationContextName, preprocessingVariables, conditionalVariables ); return macro @:pos( Context.currentPos() ){ $p { tp }.parse( $data ); } } @@ -270,7 +270,7 @@ class XmlReader var xmlPack = MacroUtil.getPack( Type.getClassName( Xml ) ); var applicationAssemblerTypePath = MacroUtil.getTypePath( "hex.runtime.ApplicationAssembler" ); var applicationXMLParserTypePath = MacroUtil.getTypePath( Type.getClassName( ApplicationXMLParser ) ); - var data = XmlReader._readXmlFile( fileName, applicationContextName, preprocessingVariables, conditionalVariables ); + var data = XmlReader._readFile( fileName, applicationContextName, preprocessingVariables, conditionalVariables ); return macro @:pos( Context.currentPos() ) { From c3cc4a9f7f450d6f0c5a5153ef77a50ef6f6dbf9 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Wed, 28 Jun 2017 11:31:49 +0200 Subject: [PATCH 3/8] Event API for FlowCompiler --- src/hex/compiler/parser/flow/ObjectParser.hx | 40 ++++++++++++------- .../flow/twoModulesListeningEachOther.flow | 14 ------- ...oModulesListeningEachOtherWithAdapter.flow | 11 +++++ ...eningEachOtherWithAdapterAndInjection.flow | 10 +++++ .../compiler/parser/flow/FlowCompilerTest.hx | 14 +++---- 5 files changed, 53 insertions(+), 36 deletions(-) create mode 100644 test/context/flow/twoModulesListeningEachOtherWithAdapter.flow create mode 100644 test/context/flow/twoModulesListeningEachOtherWithAdapterAndInjection.flow diff --git a/src/hex/compiler/parser/flow/ObjectParser.hx b/src/hex/compiler/parser/flow/ObjectParser.hx index 196b154..f007496 100644 --- a/src/hex/compiler/parser/flow/ObjectParser.hx +++ b/src/hex/compiler/parser/flow/ObjectParser.hx @@ -69,21 +69,13 @@ class ObjectParser extends AbstractExprParser trace( args );*/ case macro when( $a { when } ).then( $a { then } ): + + var vo = _getDomainListenerVO( when, then ); + vo.filePosition = e.pos; + this._builder.build( DOMAIN_LISTENER( vo ) ); - var callback = ExpressionUtil.compressField( then[0] ); - var ident = callback.split('.').shift(); - var vo = new hex.ioc.vo.DomainListenerVO( ident, ExpressionUtil.getIdent( when[0] ) ); - - if ( when.length == 2 ) - { - var arg = new hex.ioc.vo.DomainListenerVOArguments(); - arg.staticRef = ExpressionUtil.compressField( when[1] ); - var cb = callback.split('.'); - if ( cb.length > 1 ) arg.method = cb[ 1 ]; - vo.arguments = [ arg ]; - arg.filePosition = e.pos; - } - + case macro when( $a { when } ).adapt( $a { adapt } ).then( $a { then } ): + var vo = _getDomainListenerVO( when, then, adapt ); vo.filePosition = e.pos; this._builder.build( DOMAIN_LISTENER( vo ) ); @@ -109,7 +101,25 @@ class ObjectParser extends AbstractExprParser //logger.debug(e); } - + function _getDomainListenerVO( when, then, ?adapt ) : hex.ioc.vo.DomainListenerVO + { + var callback = ExpressionUtil.compressField( then[0] ); + var ident = callback.split('.').shift(); + var vo = new hex.ioc.vo.DomainListenerVO( ident, ExpressionUtil.getIdent( when[0] ) ); + + if ( when.length == 2 ) + { + var arg = new hex.ioc.vo.DomainListenerVOArguments(); + arg.staticRef = ExpressionUtil.compressField( when[1] ); + var cb = callback.split('.'); + if ( cb.length > 1 ) arg.method = cb[ 1 ]; + if ( adapt != null ) arg.strategy = ExpressionUtil.compressField( adapt[ 0 ] ); + vo.arguments = [ arg ]; + arg.filePosition = when[1].pos; + } + + return vo; + } function _getConstructorVO( ident : String, value : Expr ) : ConstructorVO { diff --git a/test/context/flow/twoModulesListeningEachOther.flow b/test/context/flow/twoModulesListeningEachOther.flow index d24701e..e45d637 100644 --- a/test/context/flow/twoModulesListeningEachOther.flow +++ b/test/context/flow/twoModulesListeningEachOther.flow @@ -1,17 +1,3 @@ -/* - - - - - - - - - - - -*/ - @context( name = 'applicationContext' ) { chat = new hex.ioc.parser.xml.mock.MockChatModule(); diff --git a/test/context/flow/twoModulesListeningEachOtherWithAdapter.flow b/test/context/flow/twoModulesListeningEachOtherWithAdapter.flow new file mode 100644 index 0000000..830e4a4 --- /dev/null +++ b/test/context/flow/twoModulesListeningEachOtherWithAdapter.flow @@ -0,0 +1,11 @@ +@context( name = 'applicationContext' ) +{ + chat = new hex.ioc.parser.xml.mock.MockChatModule(); + translation = new hex.ioc.parser.xml.mock.MockTranslationModule(); + + when( chat, hex.ioc.parser.xml.mock.MockChatModule.TEXT_INPUT ) + .adapt( hex.ioc.parser.xml.mock.MockChatAdapterStrategy ) + .then( translation.onTranslateWithTime ); + + when( translation ).then( chat ); +} \ No newline at end of file diff --git a/test/context/flow/twoModulesListeningEachOtherWithAdapterAndInjection.flow b/test/context/flow/twoModulesListeningEachOtherWithAdapterAndInjection.flow new file mode 100644 index 0000000..58c9eaf --- /dev/null +++ b/test/context/flow/twoModulesListeningEachOtherWithAdapterAndInjection.flow @@ -0,0 +1,10 @@ +@context( name = 'applicationContext' ) +{ + chat = new hex.ioc.parser.xml.mock.MockChatModule(); + receiver = new hex.ioc.parser.xml.mock.MockReceiverModule(); + @map_type( 'hex.ioc.parser.xml.mock.IMockMessageParserModule' ) parser = new hex.ioc.parser.xml.mock.MockMessageParserModule(); + + when( chat, hex.ioc.parser.xml.mock.MockChatModule.TEXT_INPUT ) + .adapt( hex.ioc.parser.xml.mock.MockChatEventAdapterStrategyWithInjection ) + .then( receiver.onMessage ); +} \ No newline at end of file diff --git a/test/hex/compiler/parser/flow/FlowCompilerTest.hx b/test/hex/compiler/parser/flow/FlowCompilerTest.hx index 740cbf9..0985f63 100644 --- a/test/hex/compiler/parser/flow/FlowCompilerTest.hx +++ b/test/hex/compiler/parser/flow/FlowCompilerTest.hx @@ -570,10 +570,10 @@ class FlowCompilerTest Assert.equals( "Hello", chat.translatedMessage, "" ); } - /*@Ignore( "test building two modules listening each other with adapter" ) + @Test( "test building two modules listening each other with adapter" ) public function testBuildingTwoModulesListeningEachOtherWithAdapter() : Void { - this._applicationAssembler = XmlCompiler.readXmlFile( "context/twoModulesListeningEachOtherWithAdapter.xml" ); + this._applicationAssembler = FlowCompiler.compile( "context/flow/twoModulesListeningEachOtherWithAdapter.flow" ); var chat : MockChatModule = this._getCoreFactory().locate( "chat" ); Assert.isNotNull( chat, "" ); @@ -587,25 +587,25 @@ class FlowCompilerTest Assert.isInstanceOf( chat.date, Date, "" ); } - @Ignore( "test building two modules listening each other with adapter and injection" ) + @Test( "test building two modules listening each other with adapter and injection" ) public function testBuildingTwoModulesListeningEachOtherWithAdapterAndInjection() : Void { - this._applicationAssembler = XmlCompiler.readXmlFile( "context/twoModulesListeningEachOtherWithAdapterAndInjection.xml" ); + this._applicationAssembler = FlowCompiler.compile( "context/flow/twoModulesListeningEachOtherWithAdapterAndInjection.flow" ); var chat : MockChatModule = this._getCoreFactory().locate( "chat" ); Assert.isNotNull( chat, "" ); - var receiver : MockReceiverModule = this._getCoreFactory().locate( "receiver" ); + var receiver : hex.ioc.parser.xml.mock.MockReceiverModule = this._getCoreFactory().locate( "receiver" ); Assert.isNotNull( receiver, "" ); - var parser : MockMessageParserModule = this._getCoreFactory().locate( "parser" ); + var parser : hex.ioc.parser.xml.mock.MockMessageParserModule = this._getCoreFactory().locate( "parser" ); Assert.isNotNull( parser, "" ); chat.dispatchDomainEvent( MockChatModule.TEXT_INPUT, [ "Bonjour" ] ); Assert.equals( "BONJOUR", receiver.message, "" ); } - @Ignore( "test domain dispatch after module initialisation" ) + /*@Ignore( "test domain dispatch after module initialisation" ) public function testDomainDispatchAfterModuleInitialisation() : Void { this._applicationAssembler = XmlCompiler.readXmlFile( "context/domainDispatchAfterModuleInitialisation.xml" ); From 0206122e21774215fd6ed94bceac5dc9ff1f8631 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Wed, 28 Jun 2017 14:32:11 +0200 Subject: [PATCH 4/8] StaticFlowCompiler handles event system like StaticXmlCompiler --- src/hex/compiler/parser/flow/ObjectParser.hx | 27 ++- test/context/flow/eventProxy.flow | 19 +++ test/context/flow/eventTrigger.flow | 13 ++ test/context/flow/moduleListeningService.flow | 8 + .../moduleListeningServiceWithMapType.flow | 10 ++ ...erviceWithStrategyAndContextInjection.flow | 17 ++ ...ServiceWithStrategyAndModuleInjection.flow | 9 + .../parser/flow/StaticFlowCompilerTest.hx | 161 ++++++++++++++++++ 8 files changed, 261 insertions(+), 3 deletions(-) create mode 100644 test/context/flow/eventProxy.flow create mode 100644 test/context/flow/eventTrigger.flow create mode 100644 test/context/flow/moduleListeningService.flow create mode 100644 test/context/flow/moduleListeningServiceWithMapType.flow create mode 100644 test/context/flow/moduleListeningServiceWithStrategyAndContextInjection.flow create mode 100644 test/context/flow/moduleListeningServiceWithStrategyAndModuleInjection.flow diff --git a/src/hex/compiler/parser/flow/ObjectParser.hx b/src/hex/compiler/parser/flow/ObjectParser.hx index f007496..97126d8 100644 --- a/src/hex/compiler/parser/flow/ObjectParser.hx +++ b/src/hex/compiler/parser/flow/ObjectParser.hx @@ -69,7 +69,6 @@ class ObjectParser extends AbstractExprParser trace( args );*/ case macro when( $a { when } ).then( $a { then } ): - var vo = _getDomainListenerVO( when, then ); vo.filePosition = e.pos; this._builder.build( DOMAIN_LISTENER( vo ) ); @@ -79,6 +78,11 @@ class ObjectParser extends AbstractExprParser vo.filePosition = e.pos; this._builder.build( DOMAIN_LISTENER( vo ) ); + case macro when( $a { when } ).execute( $a { adapt } ): + var vo = _getDomainListenerVO( when, null, adapt ); + vo.filePosition = e.pos; + this._builder.build( DOMAIN_LISTENER( vo ) ); + case _: switch( e.expr ) @@ -103,7 +107,20 @@ class ObjectParser extends AbstractExprParser function _getDomainListenerVO( when, then, ?adapt ) : hex.ioc.vo.DomainListenerVO { - var callback = ExpressionUtil.compressField( then[0] ); + var callback; + + if ( then == null ) + { + callback = 'uniquefuckingID'; + var cvo = new ConstructorVO( callback, ContextTypeList.OBJECT ); + cvo.filePosition = Context.currentPos(); + this._builder.build( OBJECT( cvo ) ); + } + else + { + callback = ExpressionUtil.compressField( then[0] ); + } + var ident = callback.split('.').shift(); var vo = new hex.ioc.vo.DomainListenerVO( ident, ExpressionUtil.getIdent( when[0] ) ); @@ -113,7 +130,11 @@ class ObjectParser extends AbstractExprParser arg.staticRef = ExpressionUtil.compressField( when[1] ); var cb = callback.split('.'); if ( cb.length > 1 ) arg.method = cb[ 1 ]; - if ( adapt != null ) arg.strategy = ExpressionUtil.compressField( adapt[ 0 ] ); + if ( adapt != null ) + { + arg.strategy = ExpressionUtil.compressField( adapt[ 0 ] ); + if ( adapt.length == 2 ) arg.injectedInModule = ExpressionUtil.getBool( adapt[1] ); + } vo.arguments = [ arg ]; arg.filePosition = when[1].pos; } diff --git a/test/context/flow/eventProxy.flow b/test/context/flow/eventProxy.flow new file mode 100644 index 0000000..59661ec --- /dev/null +++ b/test/context/flow/eventProxy.flow @@ -0,0 +1,19 @@ +@context( name = 'applicationContext' ) +{ + chat = new hex.ioc.parser.xml.mock.MockChatModule(); + receiver = new hex.ioc.parser.xml.mock.MockReceiverModule(); + + @map_type( 'hex.ioc.parser.xml.mock.IMockMessageParserModule' ) + parser = new hex.ioc.parser.xml.mock.MockMessageParserModule(); + + //Don't do that + eventProxy = new hex.event.EventProxy( receiver, receiver.onMessage ); + when( chat, hex.ioc.parser.xml.mock.MockChatModule.TEXT_INPUT ) + .adapt( hex.ioc.parser.xml.mock.MockChatEventAdapterStrategyMacro ) + .then( eventProxy ); + + //Do that Instead + /*when( chat, hex.ioc.parser.xml.mock.MockChatModule.TEXT_INPUT ) + .adapt( hex.ioc.parser.xml.mock.MockChatEventAdapterStrategyMacro ) + .then( receiver.onMessage );*/ +} \ No newline at end of file diff --git a/test/context/flow/eventTrigger.flow b/test/context/flow/eventTrigger.flow new file mode 100644 index 0000000..fec3e4a --- /dev/null +++ b/test/context/flow/eventTrigger.flow @@ -0,0 +1,13 @@ +@context( name = 'applicationContext' ) +{ + chat = new hex.ioc.parser.xml.mock.MockChatModule(); + + @map_type( 'hex.ioc.parser.xml.mock.MockReceiverModule' ) + receiver = new hex.ioc.parser.xml.mock.MockReceiverModule(); + + @map_type( 'hex.ioc.parser.xml.mock.IMockMessageParserModule' ) + parser = new hex.ioc.parser.xml.mock.MockMessageParserModule(); + + when( chat, hex.ioc.parser.xml.mock.MockChatModule.TEXT_INPUT ) + .execute( hex.ioc.parser.xml.mock.MockChatAdapterStrategyMacro ); +} \ No newline at end of file diff --git a/test/context/flow/moduleListeningService.flow b/test/context/flow/moduleListeningService.flow new file mode 100644 index 0000000..c2d3e7c --- /dev/null +++ b/test/context/flow/moduleListeningService.flow @@ -0,0 +1,8 @@ +@context( name = 'applicationContext' ) +{ + myService = new hex.ioc.parser.xml.mock.MockStubStatefulService(); + myModule = new hex.ioc.parser.xml.mock.MockModuleWithServiceCallback(); + + when( myService, hex.ioc.parser.xml.mock.MockStubStatefulService.BOOLEAN_VO_UPDATE ) + .then( myModule.onBooleanServiceCallback ); +} \ No newline at end of file diff --git a/test/context/flow/moduleListeningServiceWithMapType.flow b/test/context/flow/moduleListeningServiceWithMapType.flow new file mode 100644 index 0000000..06b98cd --- /dev/null +++ b/test/context/flow/moduleListeningServiceWithMapType.flow @@ -0,0 +1,10 @@ +@context( name = 'applicationContext' ) +{ + @map_type( 'hex.ioc.parser.xml.mock.IMockStubStatefulService' ) + myService = new hex.ioc.parser.xml.mock.MockStubStatefulService(); + + myModule = new hex.ioc.parser.xml.mock.MockModuleWithServiceCallback(); + + when( myService, hex.ioc.parser.xml.mock.MockStubStatefulService.BOOLEAN_VO_UPDATE ) + .then( myModule.onBooleanServiceCallback ); +} \ No newline at end of file diff --git a/test/context/flow/moduleListeningServiceWithStrategyAndContextInjection.flow b/test/context/flow/moduleListeningServiceWithStrategyAndContextInjection.flow new file mode 100644 index 0000000..96a4147 --- /dev/null +++ b/test/context/flow/moduleListeningServiceWithStrategyAndContextInjection.flow @@ -0,0 +1,17 @@ +@context( name = 'applicationContext' ) +{ + @map_type( 'hex.ioc.parser.xml.mock.IMockDividerHelper' ) + mockDividerHelper = new hex.ioc.parser.xml.mock.MockDividerHelper(); + + myService = new hex.ioc.parser.xml.mock.MockStubStatefulService(); + myModuleA = new hex.ioc.parser.xml.mock.MockModuleWithServiceCallback(); + myModuleB = new hex.ioc.parser.xml.mock.AnotherMockModuleWithServiceCallback(); + + when( myService, hex.ioc.parser.xml.mock.MockStubStatefulService.INT_VO_UPDATE ) + .adapt( hex.ioc.parser.xml.mock.MockIntDividerEventAdapterStrategy, true ) + .then( myModuleA.onFloatServiceCallback ); + + when( myService, hex.ioc.parser.xml.mock.MockStubStatefulService.INT_VO_UPDATE ) + .adapt( hex.ioc.parser.xml.mock.MockIntDividerEventAdapterStrategy, false ) + .then( myModuleB.onFloatServiceCallback ); +} \ No newline at end of file diff --git a/test/context/flow/moduleListeningServiceWithStrategyAndModuleInjection.flow b/test/context/flow/moduleListeningServiceWithStrategyAndModuleInjection.flow new file mode 100644 index 0000000..7c949b5 --- /dev/null +++ b/test/context/flow/moduleListeningServiceWithStrategyAndModuleInjection.flow @@ -0,0 +1,9 @@ +@context( name = 'applicationContext' ) +{ + myService = new hex.ioc.parser.xml.mock.MockStubStatefulService(); + myModule = new hex.ioc.parser.xml.mock.MockModuleWithServiceCallback(); + + when( myService, hex.ioc.parser.xml.mock.MockStubStatefulService.INT_VO_UPDATE ) + .adapt( hex.ioc.parser.xml.mock.MockIntDividerEventAdapterStrategy, true ) + .then( myModule.onFloatServiceCallback ); +} \ No newline at end of file diff --git a/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx b/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx index a0f275e..01393db 100644 --- a/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx +++ b/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx @@ -1,5 +1,6 @@ package hex.compiler.parser.flow; +import haxe.Timer; import hex.compiler.parser.flow.StaticFlowCompiler; import hex.core.IApplicationAssembler; import hex.di.Injector; @@ -9,6 +10,12 @@ import hex.domain.ApplicationDomainDispatcher; import hex.domain.Domain; import hex.error.NoSuchElementException; import hex.ioc.assembler.ApplicationContext; +import hex.ioc.parser.xml.mock.IMockStubStatefulService; +import hex.ioc.parser.xml.mock.MockBooleanVO; +import hex.ioc.parser.xml.mock.MockChatModule; +import hex.ioc.parser.xml.mock.MockIntVO; +import hex.ioc.parser.xml.mock.MockReceiverModule; +import hex.ioc.parser.xml.mock.MockTranslationModule; import hex.mock.AnotherMockClass; import hex.mock.ArrayOfDependenciesOwner; import hex.mock.IAnotherMockInterface; @@ -29,6 +36,7 @@ import hex.runtime.ApplicationAssembler; import hex.structures.Point; import hex.structures.Size; import hex.unittest.assertion.Assert; +import hex.unittest.runner.MethodRunner; /** * ... @@ -601,6 +609,49 @@ class StaticFlowCompilerTest Assert.notEquals( intInstance, stringInstance ); } + @Test( "test building two modules listening each other" ) + public function testBuildingTwoModulesListeningEachOther() : Void + { + var code = StaticFlowCompiler.compile( this._applicationAssembler, "context/flow/twoModulesListeningEachOther.flow", "StaticFlowCompiler_testBuildingTwoModulesListeningEachOther" ); + code.execute(); + + Assert.isNotNull( code.locator.chat ); + Assert.isNull( code.locator.chat.translatedMessage ); + Assert.isNotNull( code.locator.translation ); + + code.locator.chat.dispatchDomainEvent( MockChatModule.TEXT_INPUT, [ "Bonjour" ] ); + Assert.equals( "Hello", code.locator.chat.translatedMessage ); + } + + @Test( "test building two modules listening each other with adapter" ) + public function testBuildingTwoModulesListeningEachOtherWithAdapter() : Void + { + var code = StaticFlowCompiler.compile( this._applicationAssembler, "context/flow/twoModulesListeningEachOtherWithAdapter.flow", "StaticFlowCompiler_testBuildingTwoModulesListeningEachOtherWithAdapter" ); + code.execute(); + + Assert.isNotNull( code.locator.chat ); + Assert.isNull( code.locator.chat.translatedMessage ); + Assert.isNotNull( code.locator.translation ); + + code.locator.chat.dispatchDomainEvent( MockChatModule.TEXT_INPUT, [ "Bonjour" ] ); + Assert.equals( "Hello", code.locator.chat.translatedMessage, "" ); + Assert.isInstanceOf( code.locator.chat.date, Date, "" ); + } + + @Test( "test building two modules listening each other with adapter and injection" ) + public function testBuildingTwoModulesListeningEachOtherWithAdapterAndInjection() : Void + { + var code = StaticFlowCompiler.compile( this._applicationAssembler, "context/flow/twoModulesListeningEachOtherWithAdapterAndInjection.flow", "StaticFlowCompiler_testBuildingTwoModulesListeningEachOtherWithAdapterAndInjection" ); + code.execute(); + + Assert.isNotNull( code.locator.chat ); + Assert.isNotNull( code.locator.receiver ); + Assert.isNotNull( code.locator.parser ); + + code.locator.chat.dispatchDomainEvent( MockChatModule.TEXT_INPUT, [ "Bonjour" ] ); + Assert.equals( "BONJOUR", code.locator.receiver.message ); + } + @Test( "test building class reference" ) public function testBuildingClassReference() : Void { @@ -708,6 +759,116 @@ class StaticFlowCompilerTest Assert.equals( 'property', code.locator.oDynamic.p ); } + // + @Test( "test module listening service" ) + public function testModuleListeningService() : Void + { + var code = StaticFlowCompiler.compile( this._applicationAssembler, "context/flow/moduleListeningService.flow", "StaticFlowCompiler_testModuleListeningService" ); + code.execute(); + + Assert.isNotNull( code.locator.myService ); + Assert.isNotNull( code.locator.myModule ); + + var booleanVO = new MockBooleanVO( true ); + code.locator.myService.setBooleanVO( booleanVO ); + Assert.isTrue( code.locator.myModule.getBooleanValue() ); + } + + @Test( "test module listening service with map-type" ) + public function testModuleListeningServiceWithMapType() : Void + { + var code = StaticFlowCompiler.compile( this._applicationAssembler, "context/flow/moduleListeningServiceWithMapType.flow", "StaticFlowCompiler_testModuleListeningServiceWithMapType" ); + code.execute(); + + Assert.isNotNull( code.locator.myService ); + Assert.isNotNull( code.locator.myModule ); + + var booleanVO = new MockBooleanVO( true ); + code.locator.myService.setBooleanVO( booleanVO ); + Assert.isTrue( code.locator.myModule.getBooleanValue() ); + + Assert.equals( code.locator.myService, code.applicationContext.getInjector().getInstance( IMockStubStatefulService, "myService" ) ); + } + + @Test( "test module listening service with strategy and module injection" ) + public function testModuleListeningServiceWithStrategyAndModuleInjection() : Void + { + var code = StaticFlowCompiler.compile( this._applicationAssembler, "context/flow/moduleListeningServiceWithStrategyAndModuleInjection.flow", "StaticFlowCompiler_testModuleListeningServiceWithStrategyAndModuleInjection" ); + code.execute(); + + Assert.isNotNull( code.locator.myService ); + Assert.isNotNull( code.locator.myModule ); + + var intVO = new MockIntVO( 7 ); + code.locator.myService.setIntVO( intVO ); + Assert.equals( 3.5, code.locator.myModule.getFloatValue() ); + } + + @Test( "test module listening service with strategy and context injection" ) + public function testModuleListeningServiceWithStrategyAndContextInjection() : Void + { + var code = StaticFlowCompiler.compile( this._applicationAssembler, "context/flow/moduleListeningServiceWithStrategyAndContextInjection.flow", "StaticFlowCompiler_testModuleListeningServiceWithStrategyAndContextInjection" ); + code.execute(); + + Assert.isNotNull( code.locator.mockDividerHelper ); + Assert.isNotNull( code.locator.myService ); + Assert.isNotNull( code.locator.myModuleA ); + Assert.isNotNull( code.locator.myModuleB ); + + code.locator.myService.setIntVO( new MockIntVO( 7 ) ); + Assert.equals( 3.5, ( code.locator.myModuleA.getFloatValue() ), "" ); + + code.locator.myService.setIntVO( new MockIntVO( 9 ) ); + Assert.equals( 4.5, ( code.locator.myModuleB.getFloatValue() ), "" ); + } + + @Async( "test EventTrigger" ) + public function testEventTrigger() : Void + { + var code = StaticFlowCompiler.compile( this._applicationAssembler, "context/flow/eventTrigger.flow", "StaticFlowCompiler_testEventTrigger" ); + code.execute(); + + Assert.isNotNull( code.locator.chat ); + Assert.isNotNull( code.locator.receiver ); + Assert.isNotNull( code.locator.parser ); + + Timer.delay( MethodRunner.asyncHandler( this._onCompleteHandlerEventTrigger ), 500 ); + code.locator.chat.dispatchDomainEvent( MockChatModule.TEXT_INPUT, [ "bonjour" ] ); + } + + function _onCompleteHandlerEventTrigger() : Void + { + var receiver : MockReceiverModule = this._locate( "StaticFlowCompiler_testEventTrigger", "receiver" ); + Assert.equals( "BONJOUR:HTTP://GOOGLE.COM", receiver.message, "" ); + } + + @Async( "test EventProxy" ) + public function testEventProxy() : Void + { + var code = StaticFlowCompiler.compile( this._applicationAssembler, "context/flow/eventProxy.flow", "StaticFlowCompiler_testEventProxy" ); + code.execute(); + + //Assert.isNotNull( code.locator.eventProxy ); + Assert.isNotNull( code.locator.chat ); + Assert.isNotNull( code.locator.receiver ); + //Assert.isNotNull( code.locator.eventProxy ); + Assert.isNotNull( code.locator.parser ); + + Timer.delay( MethodRunner.asyncHandler( this._onCompleteHandlerEventProxy ), 500 ); + code.locator.chat.dispatchDomainEvent( MockChatModule.TEXT_INPUT, [ "bonjour" ] ); + } + + function _onCompleteHandlerEventProxy() : Void + { + var receiver : MockReceiverModule = this._locate( "StaticFlowCompiler_testEventProxy", "receiver" ); + Assert.equals( "BONJOUR:HTTP://GOOGLE.COM", receiver.message, "" ); + } + + function _locate( contextName : String, key : String ) : Dynamic + { + return this._applicationAssembler.getApplicationContext( contextName, ApplicationContext ).getCoreFactory().locate( key ); + } + @Test( "test file preprocessor with flow file" ) public function testFilePreprocessorWithFlowFile() : Void { From 8e072b76cfc77448bf095769d29101017eb5f536 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Wed, 28 Jun 2017 14:57:50 +0200 Subject: [PATCH 5/8] StaticFlowCompiler tests with annotation provider --- test/context/flow/macroWithAnnotation.flow | 8 ++ .../flow/testMockObjectWithAnnotation.flow | 4 + .../parser/flow/StaticFlowCompilerTest.hx | 113 ++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 test/context/flow/macroWithAnnotation.flow create mode 100644 test/context/flow/testMockObjectWithAnnotation.flow diff --git a/test/context/flow/macroWithAnnotation.flow b/test/context/flow/macroWithAnnotation.flow new file mode 100644 index 0000000..bdee2ca --- /dev/null +++ b/test/context/flow/macroWithAnnotation.flow @@ -0,0 +1,8 @@ +/* + + + + + + +*/ \ No newline at end of file diff --git a/test/context/flow/testMockObjectWithAnnotation.flow b/test/context/flow/testMockObjectWithAnnotation.flow new file mode 100644 index 0000000..c7ad720 --- /dev/null +++ b/test/context/flow/testMockObjectWithAnnotation.flow @@ -0,0 +1,4 @@ +@context( name = 'applicationContext' ) +{ + mockObjectWithAnnotation = new hex.metadata.MockObjectWithAnnotation(); +} \ No newline at end of file diff --git a/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx b/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx index 01393db..574f6af 100644 --- a/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx +++ b/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx @@ -16,6 +16,7 @@ import hex.ioc.parser.xml.mock.MockChatModule; import hex.ioc.parser.xml.mock.MockIntVO; import hex.ioc.parser.xml.mock.MockReceiverModule; import hex.ioc.parser.xml.mock.MockTranslationModule; +import hex.metadata.IAnnotationProvider; import hex.mock.AnotherMockClass; import hex.mock.ArrayOfDependenciesOwner; import hex.mock.IAnotherMockInterface; @@ -869,6 +870,118 @@ class StaticFlowCompilerTest return this._applicationAssembler.getApplicationContext( contextName, ApplicationContext ).getCoreFactory().locate( key ); } + function getColorByName( name : String ) : Int + { + return name == "white" ? 0xFFFFFF : 0; + } + + function getText( name : String ) : String + { + return name == "welcome" ? "Bienvenue" : null; + } + + function getAnotherText( name : String ) : String + { + return "anotherText"; + } + + // + @Test( "Test MockObject with annotation" ) + public function testMockObjectWithAnnotation() : Void + { + var code = StaticFlowCompiler.compile( this._applicationAssembler, "context/flow/testMockObjectWithAnnotation.flow", "StaticFlowCompiler_testMockObjectWithAnnotation" ); + var annotationProvider : IAnnotationProvider = code.applicationContext.getInjector().getInstance( IAnnotationProvider ); + + annotationProvider.registerMetaData( "color", this.getColorByName ); + annotationProvider.registerMetaData( "language", this.getText ); + + code.execute(); + + Assert.equals( 0xffffff, code.locator.mockObjectWithAnnotation.colorTest, "color should be the same" ); + Assert.equals( "Bienvenue", code.locator.mockObjectWithAnnotation.languageTest, "text should be the same" ); + Assert.isNull( code.locator.mockObjectWithAnnotation.propWithoutMetaData, "property should be null" ); + } + + @Test( "Test AnnotationProvider with inheritance" ) + public function testAnnotationProviderWithInheritance() : Void + { + var assembler = new ApplicationAssembler(); + this._applicationAssembler = assembler; + + var code = StaticFlowCompiler.compile( assembler, "context/flow/testMockObjectWithAnnotation.flow", "StaticFlowCompiler_testAnnotationProviderWithInheritance" ); + code.execute(); + + var annotationProvider : IAnnotationProvider = code.applicationContext.getInjector().getInstance( IAnnotationProvider ); + annotationProvider.registerMetaData( "color", this.getColorByName ); + annotationProvider.registerMetaData( "language", this.getText ); + + var code2 = StaticFlowCompiler.extend( code, "context/flow/testAnnotationProviderWithInheritance.flow" ); + code2.execute(); + + var mockObjectWithMetaData = code2.locator.mockObjectWithAnnotation; + + Assert.equals( 0xffffff, mockObjectWithMetaData.colorTest, "color should be the same" ); + Assert.equals( "Bienvenue", mockObjectWithMetaData.languageTest, "text should be the same" ); + Assert.isNull( mockObjectWithMetaData.propWithoutMetaData, "property should be null" ); + + // + var provider = code2.locator.module.getAnnotationProvider(); + code2.locator.module.buildComponents(); + + Assert.equals( 0xffffff, code2.locator.module.mockObjectWithMetaData.colorTest, "color should be the same" ); + Assert.equals( "Bienvenue", code2.locator.module.mockObjectWithMetaData.languageTest, "text should be the same" ); + Assert.isNull( code2.locator.module.anotherMockObjectWithMetaData.languageTest, "property should be null when class is not implementing IAnnotationParsable" ); + + provider.registerMetaData( "language", this.getAnotherText ); + code2.locator.module.buildComponents(); + + Assert.equals( 0xffffff, code2.locator.module.mockObjectWithMetaData.colorTest, "color should be the same" ); + Assert.equals( "anotherText", code2.locator.module.mockObjectWithMetaData.languageTest, "text should be the same" ); + Assert.isNull( code2.locator.module.anotherMockObjectWithMetaData.languageTest, "property should be null when class is not implementing IAnnotationParsable" ); + } + + /*@Test( "Test Macro with annotation" ) + public function testMacroWithAnnotation() : Void + { + MockMacroWithAnnotation.lastResult = null; + MockCommandWithAnnotation.lastResult = null; + MockAsyncCommandWithAnnotation.lastResult = null; + + var applicationAssembler = new ApplicationAssembler(); + var applicationContext = applicationAssembler.getApplicationContext( "StaticFlowCompiler_testMacroWithAnnotation", ApplicationContext ); + var injector = applicationContext.getInjector(); + + var annotationProvider = AnnotationProvider.getAnnotationProvider( applicationContext.getDomain() ); + annotationProvider.registerMetaData( "Value", this._getValue ); + + var code = StaticFlowCompiler.compile( this._applicationAssembler, "context/flow/macroWithAnnotation.flow", "StaticFlowCompiler_testMacroWithAnnotation" ); + code.execute(); + + var annotationProvider : IAnnotationProvider = this._applicationAssembler.getApplicationContext( "StaticFlowCompiler_testMacroWithAnnotation", ApplicationContext ).getInjector().getInstance( IAnnotationProvider ); + + Assert.equals( "value", MockMacroWithAnnotation.lastResult, "text should be the same" ); + Assert.equals( "value", MockCommandWithAnnotation.lastResult, "text should be the same" ); + Assert.equals( "value", MockAsyncCommandWithAnnotation.lastResult, "text should be the same" ); + } + + function _getValue( key : String ) return "value"; + + @Test( "test trigger injection" ) + public function testTriggerInjection() : Void + { + var code = StaticFlowCompiler.compile( this._applicationAssembler, "context/flow/triggerInjection.flow", "StaticFlowCompiler_testTriggerInjection" ); + code.execute(); + + Assert.isInstanceOf( code.locator.model, MockWeatherModel ); + + code.locator.model.temperature.trigger( 13 ); + code.locator.model.weather.trigger( 'sunny' ); + + Assert.equals( 13, code.locator.module.temperature ); + Assert.equals( 'sunny', code.locator.module.weather ); + }*/ + + // @Test( "test file preprocessor with flow file" ) public function testFilePreprocessorWithFlowFile() : Void { From b24b24ced9083495761851756e731b9390f2c966 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Wed, 28 Jun 2017 15:04:35 +0200 Subject: [PATCH 6/8] missing files --- ...testAnnotationProviderWithInheritance.flow | 4 ++++ test/context/flow/triggerInjection.flow | 23 +++++++++++++++++++ .../parser/xml/StaticXmlCompilerTest.hx | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/context/flow/testAnnotationProviderWithInheritance.flow create mode 100644 test/context/flow/triggerInjection.flow diff --git a/test/context/flow/testAnnotationProviderWithInheritance.flow b/test/context/flow/testAnnotationProviderWithInheritance.flow new file mode 100644 index 0000000..d2d0222 --- /dev/null +++ b/test/context/flow/testAnnotationProviderWithInheritance.flow @@ -0,0 +1,4 @@ +@context( name = 'applicationContext' ) +{ + module = new hex.ioc.parser.xml.mock.MockModuleWithAnnotationProviding(); +} \ No newline at end of file diff --git a/test/context/flow/triggerInjection.flow b/test/context/flow/triggerInjection.flow new file mode 100644 index 0000000..d906887 --- /dev/null +++ b/test/context/flow/triggerInjection.flow @@ -0,0 +1,23 @@ +/* + + + + + + + + + + + + + + + + + + + + + +*/ diff --git a/test/hex/compiler/parser/xml/StaticXmlCompilerTest.hx b/test/hex/compiler/parser/xml/StaticXmlCompilerTest.hx index 4a22656..5cefd41 100644 --- a/test/hex/compiler/parser/xml/StaticXmlCompilerTest.hx +++ b/test/hex/compiler/parser/xml/StaticXmlCompilerTest.hx @@ -1214,7 +1214,7 @@ class StaticXmlCompilerTest Assert.equals( 40, code.locator.anotherSize.height ); } - @Test( "test module listening service" ) + @Test( "test module listening service with 2 passes" ) public function testModuleListeningServiceWith2Passes() : Void { var code1 = StaticXmlCompiler.compile( this._applicationAssembler, "context/xml/serviceToBeListened.xml", "StaticXmlCompiler_testModuleListeningServiceWith2Passes" ); From 0c2ca6d1a62328f198332e33233b96a6e6ceb5af Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Wed, 28 Jun 2017 15:28:58 +0200 Subject: [PATCH 7/8] more tests for StaticFlowCompiler --- test/context/flow/moduleListener.flow | 7 ++++++ test/context/flow/serviceToBeListened.flow | 4 ++++ .../parser/flow/StaticFlowCompilerTest.hx | 23 ++++++++++++++++--- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 test/context/flow/moduleListener.flow create mode 100644 test/context/flow/serviceToBeListened.flow diff --git a/test/context/flow/moduleListener.flow b/test/context/flow/moduleListener.flow new file mode 100644 index 0000000..1760d96 --- /dev/null +++ b/test/context/flow/moduleListener.flow @@ -0,0 +1,7 @@ +@context( name = 'applicationContext' ) +{ + myModule = new hex.ioc.parser.xml.mock.MockModuleWithServiceCallback(); + + when( myService, hex.ioc.parser.xml.mock.MockStubStatefulService.BOOLEAN_VO_UPDATE ) + .then( myModule.onBooleanServiceCallback ); +} \ No newline at end of file diff --git a/test/context/flow/serviceToBeListened.flow b/test/context/flow/serviceToBeListened.flow new file mode 100644 index 0000000..2e1ebcd --- /dev/null +++ b/test/context/flow/serviceToBeListened.flow @@ -0,0 +1,4 @@ +@context( name = 'applicationContext' ) +{ + myService = new hex.ioc.parser.xml.mock.MockStubStatefulService(); +} \ No newline at end of file diff --git a/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx b/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx index 574f6af..649f6c3 100644 --- a/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx +++ b/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx @@ -15,7 +15,6 @@ import hex.ioc.parser.xml.mock.MockBooleanVO; import hex.ioc.parser.xml.mock.MockChatModule; import hex.ioc.parser.xml.mock.MockIntVO; import hex.ioc.parser.xml.mock.MockReceiverModule; -import hex.ioc.parser.xml.mock.MockTranslationModule; import hex.metadata.IAnnotationProvider; import hex.mock.AnotherMockClass; import hex.mock.ArrayOfDependenciesOwner; @@ -849,10 +848,10 @@ class StaticFlowCompilerTest var code = StaticFlowCompiler.compile( this._applicationAssembler, "context/flow/eventProxy.flow", "StaticFlowCompiler_testEventProxy" ); code.execute(); - //Assert.isNotNull( code.locator.eventProxy ); + Assert.isNotNull( code.locator.eventProxy ); Assert.isNotNull( code.locator.chat ); Assert.isNotNull( code.locator.receiver ); - //Assert.isNotNull( code.locator.eventProxy ); + Assert.isNotNull( code.locator.eventProxy ); Assert.isNotNull( code.locator.parser ); Timer.delay( MethodRunner.asyncHandler( this._onCompleteHandlerEventProxy ), 500 ); @@ -1318,4 +1317,22 @@ class StaticFlowCompilerTest code.execute(); Assert.equals( 'hello world', code.locator.childContext.text ); } + + // + @Test( "test module listening service with 2 passes" ) + public function testModuleListeningServiceWith2Passes() : Void + { + var code1 = StaticFlowCompiler.compile( this._applicationAssembler, "context/flow/serviceToBeListened.flow", "StaticFlowCompiler_testModuleListeningServiceWith2Passes" ); + code1.execute(); + + var code = StaticFlowCompiler.extend( code1, "context/flow/moduleListener.flow" ); + code.execute(); + + Assert.isNotNull( code.locator.myService ); + Assert.isNotNull( code.locator.myModule ); + + var booleanVO = new MockBooleanVO( true ); + code.locator.myService.setBooleanVO( booleanVO ); + Assert.isTrue( code.locator.myModule.getBooleanValue() ); + } } \ No newline at end of file From 3d4edab770ec20ca1efd8a09645508cff1a36ffb Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Wed, 28 Jun 2017 15:41:08 +0200 Subject: [PATCH 8/8] More tests with StaticFlowCompiler --- .../flow/domainDispatchAfterModuleInitialisation.flow | 8 ++++++++ .../compiler/parser/flow/StaticFlowCompilerTest.hx | 11 +++++++++++ 2 files changed, 19 insertions(+) create mode 100644 test/context/flow/domainDispatchAfterModuleInitialisation.flow diff --git a/test/context/flow/domainDispatchAfterModuleInitialisation.flow b/test/context/flow/domainDispatchAfterModuleInitialisation.flow new file mode 100644 index 0000000..dd8ed6d --- /dev/null +++ b/test/context/flow/domainDispatchAfterModuleInitialisation.flow @@ -0,0 +1,8 @@ +@context( name = 'applicationContext' ) +{ + sender = new hex.ioc.parser.xml.mock.MockSenderModule(); + receiver = new hex.ioc.parser.xml.mock.MockReceiverModule(); + + when( sender, hex.ioc.parser.xml.mock.MockChatModule.TEXT_INPUT ) + .then( receiver.onMessage ); +} \ No newline at end of file diff --git a/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx b/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx index 649f6c3..a2e199b 100644 --- a/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx +++ b/test/hex/compiler/parser/flow/StaticFlowCompilerTest.hx @@ -822,6 +822,17 @@ class StaticFlowCompilerTest Assert.equals( 4.5, ( code.locator.myModuleB.getFloatValue() ), "" ); } + @Test( "test domain dispatch after module initialisation" ) + public function testDomainDispatchAfterModuleInitialisation() : Void + { + var code = StaticFlowCompiler.compile( this._applicationAssembler, "context/flow/domainDispatchAfterModuleInitialisation.flow", "StaticFlowCompiler_testDomainDispatchAfterModuleInitialisation" ); + code.execute(); + + Assert.isNotNull( code.locator.sender ); + Assert.isNotNull( code.locator.receiver ); + Assert.equals( "hello receiver", code.locator.receiver.message ); + } + @Async( "test EventTrigger" ) public function testEventTrigger() : Void {