@@ -54,22 +54,48 @@ it('forwards input stream to target index specified in input', () => {
5454 controller . handle ( commands ) ;
5555
5656 inputStream . write ( '1:something' ) ;
57+ inputStream . write ( '1:multi\nline\n' ) ;
5758
5859 expect ( commands [ 0 ] . stdin ?. write ) . not . toHaveBeenCalled ( ) ;
59- expect ( commands [ 1 ] . stdin ?. write ) . toHaveBeenCalledTimes ( 1 ) ;
60+ expect ( commands [ 1 ] . stdin ?. write ) . toHaveBeenCalledTimes ( 2 ) ;
6061 expect ( commands [ 1 ] . stdin ?. write ) . toHaveBeenCalledWith ( 'something' ) ;
62+ expect ( commands [ 1 ] . stdin ?. write ) . toHaveBeenCalledWith ( 'multi\nline\n' ) ;
6163} ) ;
6264
6365it ( 'forwards input stream to target index specified in input when input contains colon' , ( ) => {
6466 controller . handle ( commands ) ;
6567
66- inputStream . emit ( 'data' , Buffer . from ( '1::something' ) ) ;
6768 inputStream . emit ( 'data' , Buffer . from ( '1:some:thing' ) ) ;
69+ inputStream . emit ( 'data' , Buffer . from ( '1: :something' ) ) ;
70+ inputStream . emit ( 'data' , Buffer . from ( '1::something' ) ) ;
6871
6972 expect ( commands [ 0 ] . stdin ?. write ) . not . toHaveBeenCalled ( ) ;
70- expect ( commands [ 1 ] . stdin ?. write ) . toHaveBeenCalledTimes ( 2 ) ;
71- expect ( commands [ 1 ] . stdin ?. write ) . toHaveBeenCalledWith ( ':something' ) ;
73+ expect ( commands [ 1 ] . stdin ?. write ) . toHaveBeenCalledTimes ( 3 ) ;
7274 expect ( commands [ 1 ] . stdin ?. write ) . toHaveBeenCalledWith ( 'some:thing' ) ;
75+ expect ( commands [ 1 ] . stdin ?. write ) . toHaveBeenCalledWith ( ' :something' ) ;
76+ expect ( commands [ 1 ] . stdin ?. write ) . toHaveBeenCalledWith ( ':something' ) ;
77+ } ) ;
78+
79+ it ( 'does not forward input stream when input contains colon in a different format' , ( ) => {
80+ controller . handle ( commands ) ;
81+
82+ inputStream . emit ( 'data' , Buffer . from ( 'Ruby0::Const::Syntax' ) ) ;
83+ inputStream . emit ( 'data' , Buffer . from ( '1:Ruby1::Const::Syntax' ) ) ;
84+ inputStream . emit ( 'data' , Buffer . from ( 'ruby_symbol_arg :my_symbol' ) ) ;
85+ inputStream . emit ( 'data' , Buffer . from ( 'ruby_symbol_arg(:my_symbol)' ) ) ;
86+ inputStream . emit ( 'data' , Buffer . from ( '{ruby_key: :my_val}' ) ) ;
87+ inputStream . emit ( 'data' , Buffer . from ( '{:ruby_key=>:my_val}' ) ) ;
88+ inputStream . emit ( 'data' , Buffer . from ( 'js_obj = {key: "my_val"}' ) ) ;
89+
90+ expect ( commands [ 1 ] . stdin ?. write ) . toHaveBeenCalledTimes ( 1 ) ;
91+ expect ( commands [ 1 ] . stdin ?. write ) . toHaveBeenCalledWith ( 'Ruby1::Const::Syntax' ) ;
92+ expect ( commands [ 0 ] . stdin ?. write ) . toHaveBeenCalledTimes ( 6 ) ;
93+ expect ( commands [ 0 ] . stdin ?. write ) . toHaveBeenCalledWith ( 'Ruby0::Const::Syntax' ) ;
94+ expect ( commands [ 0 ] . stdin ?. write ) . toHaveBeenCalledWith ( 'ruby_symbol_arg :my_symbol' ) ;
95+ expect ( commands [ 0 ] . stdin ?. write ) . toHaveBeenCalledWith ( 'ruby_symbol_arg(:my_symbol)' ) ;
96+ expect ( commands [ 0 ] . stdin ?. write ) . toHaveBeenCalledWith ( '{ruby_key: :my_val}' ) ;
97+ expect ( commands [ 0 ] . stdin ?. write ) . toHaveBeenCalledWith ( '{:ruby_key=>:my_val}' ) ;
98+ expect ( commands [ 0 ] . stdin ?. write ) . toHaveBeenCalledWith ( 'js_obj = {key: "my_val"}' ) ;
7399} ) ;
74100
75101it ( 'forwards input stream to target name specified in input' , ( ) => {
@@ -90,20 +116,19 @@ it('logs error if command has no stdin open', () => {
90116
91117 expect ( commands [ 1 ] . stdin ?. write ) . not . toHaveBeenCalled ( ) ;
92118 expect ( logger . logGlobalEvent ) . toHaveBeenCalledWith (
93- 'Unable to find command 0 , or it has no stdin open\n'
119+ 'Unable to find command "0" , or it has no stdin open\n'
94120 ) ;
95121} ) ;
96122
97- it ( 'logs error if command is not found' , ( ) => {
123+ it ( 'fallback to default input stream if command is not found' , ( ) => {
98124 controller . handle ( commands ) ;
99125
100126 inputStream . write ( 'foobar:something' ) ;
101127
102- expect ( commands [ 0 ] . stdin ?. write ) . not . toHaveBeenCalled ( ) ;
128+ expect ( commands [ 0 ] . stdin ?. write ) . toHaveBeenCalledTimes ( 1 ) ;
129+ expect ( commands [ 0 ] . stdin ?. write ) . toHaveBeenCalledWith ( 'foobar:something' ) ;
103130 expect ( commands [ 1 ] . stdin ?. write ) . not . toHaveBeenCalled ( ) ;
104- expect ( logger . logGlobalEvent ) . toHaveBeenCalledWith (
105- 'Unable to find command foobar, or it has no stdin open\n'
106- ) ;
131+ expect ( logger . logGlobalEvent ) . not . toHaveBeenCalled ( ) ;
107132} ) ;
108133
109134it ( 'pauses input stream when finished' , ( ) => {
0 commit comments