@@ -737,4 +737,82 @@ describe('helpers', function() {
737737 shouldCompileTo ( '{{#if bar}}{{else goodbyes as |value|}}{{value}}{{/if}}{{value}}' , [ hash , helpers ] , '1foo' ) ;
738738 } ) ;
739739 } ) ;
740+
741+ describe ( 'splat operators' , function ( ) {
742+
743+ it ( 'basic splat test' , function ( ) {
744+ var string = '{{hello **splat }}' ;
745+ var hash = { splat : { firstName : 'Guybrush' , lastName : 'Threepwood' } } ;
746+ var helpers = {
747+ hello : function ( options ) {
748+ var hash = options . hash ;
749+ return 'Hi, my name is ' + hash . firstName + ' ' + hash . lastName ;
750+ }
751+ } ;
752+
753+ shouldCompileTo ( string , [ hash , helpers ] , 'Hi, my name is Guybrush Threepwood' ) ;
754+ } ) ;
755+
756+ it ( 'fails with multiple splats' , function ( ) {
757+ var string = '{{foo **bar **baz}}' ;
758+ shouldThrow ( function ( ) {
759+ CompilerContext . compile ( string ) ;
760+ } , Error ) ;
761+
762+ } ) ;
763+
764+ it ( 'splat shadowing' , function ( ) {
765+ var string = '{{helper **splat occupation="pirate" }}' ;
766+ var hash = { splat : { occupation : 'cannonball' } } ;
767+ var helpers = {
768+ helper : function ( options ) {
769+ var hash = options . hash ;
770+ return 'I want to be a ' + hash . occupation + '!' ;
771+ }
772+ } ;
773+
774+ shouldCompileTo ( string , [ hash , helpers ] , 'I want to be a pirate!' ) ;
775+ } ) ;
776+
777+ it ( 'splat test' , function ( ) {
778+ var template = CompilerContext . compile ( '{{helper **foo.splat character=character }}' ) ;
779+
780+ var helpers = {
781+ helper : function ( options ) {
782+ return options . hash . character + ' and the ' + options . hash . numberOfHeads + ' monkey on ' + options . hash . island + ' Island' ;
783+ }
784+ } ;
785+
786+ var context = { foo : { splat : { numberOfHeads : '3 headed' , island : 'Dinky' } } , character : 'Guybrush' } ;
787+
788+ var result = template ( context , { helpers : helpers } ) ;
789+ equals ( result , 'Guybrush and the 3 headed monkey on Dinky Island' , 'Splat test' ) ;
790+ } ) ;
791+
792+ it ( 'splat with function' , function ( ) {
793+ var template = CompilerContext . compile ( '{{helper **foo character=character }}' ) ;
794+
795+ var helpers = {
796+ helper : function ( options ) {
797+ var hash = options . hash ;
798+ return hash . character + ' and the ' + hash . numberOfHeads + ' monkey on ' + hash . format ( hash . island ) + ' Island' ;
799+ }
800+ } ;
801+
802+ var context = {
803+ foo : {
804+ numberOfHeads : '3 headed' ,
805+ island : 'Dinky' ,
806+ format : function ( str ) {
807+ return str . toUpperCase ( ) ;
808+ }
809+ } ,
810+ character : 'Guybrush'
811+ } ;
812+
813+ var result = template ( context , { helpers : helpers } ) ;
814+ equals ( result , 'Guybrush and the 3 headed monkey on DINKY Island' , 'Splat function test' ) ;
815+ } ) ;
816+
817+ } ) ;
740818} ) ;
0 commit comments