@@ -116,6 +116,27 @@ describe('Control Flow', () => {
116116 expect ( stack [ 2 ] . right ) . toBeUndefined ( )
117117 expect ( stack [ 2 ] . left ) . toBeUndefined ( )
118118 } )
119+ test ( 'while-command-command-end' , ( ) => {
120+ let input = [
121+ createCommand ( ControlFlowCommandNames . while ) ,
122+ createCommand ( 'command' ) ,
123+ createCommand ( 'command' ) ,
124+ createCommand ( ControlFlowCommandNames . end ) ,
125+ ]
126+ let stack = createCommandNodesFromCommandStack ( input )
127+ expect ( stack [ 0 ] . next ) . toBeUndefined ( )
128+ expect ( stack [ 0 ] . right ) . toEqual ( stack [ 1 ] )
129+ expect ( stack [ 0 ] . left ) . toEqual ( stack [ 3 ] )
130+ expect ( stack [ 1 ] . next ) . toEqual ( stack [ 2 ] )
131+ expect ( stack [ 1 ] . right ) . toBeUndefined ( )
132+ expect ( stack [ 1 ] . left ) . toBeUndefined ( )
133+ expect ( stack [ 2 ] . next ) . toEqual ( stack [ 0 ] )
134+ expect ( stack [ 2 ] . right ) . toBeUndefined ( )
135+ expect ( stack [ 2 ] . left ) . toBeUndefined ( )
136+ expect ( stack [ 3 ] . next ) . toBeUndefined ( )
137+ expect ( stack [ 3 ] . right ) . toBeUndefined ( )
138+ expect ( stack [ 3 ] . left ) . toBeUndefined ( )
139+ } )
119140 test ( 'while-if-end-end' , ( ) => {
120141 let input = [
121142 createCommand ( ControlFlowCommandNames . while ) , // 0
@@ -141,26 +162,34 @@ describe('Control Flow', () => {
141162 expect ( stack [ 4 ] . right ) . toBeUndefined ( )
142163 expect ( stack [ 4 ] . left ) . toBeUndefined ( )
143164 } )
144- test ( 'while-command -command-end' , ( ) => {
165+ test ( 'while-if-end -command-end' , ( ) => {
145166 let input = [
146- createCommand ( ControlFlowCommandNames . while ) ,
147- createCommand ( 'command' ) ,
148- createCommand ( 'command' ) ,
149- createCommand ( ControlFlowCommandNames . end ) ,
167+ createCommand ( ControlFlowCommandNames . while ) , // 0
168+ createCommand ( ControlFlowCommandNames . if ) , // 1
169+ createCommand ( 'command' ) , // 2
170+ createCommand ( ControlFlowCommandNames . end ) , // 3
171+ createCommand ( 'command' ) , // 4
172+ createCommand ( ControlFlowCommandNames . end ) , // 5
150173 ]
151174 let stack = createCommandNodesFromCommandStack ( input )
152175 expect ( stack [ 0 ] . next ) . toBeUndefined ( )
153176 expect ( stack [ 0 ] . right ) . toEqual ( stack [ 1 ] )
154- expect ( stack [ 0 ] . left ) . toEqual ( stack [ 3 ] )
155- expect ( stack [ 1 ] . next ) . toEqual ( stack [ 2 ] )
156- expect ( stack [ 1 ] . right ) . toBeUndefined ( )
157- expect ( stack [ 1 ] . left ) . toBeUndefined ( )
158- expect ( stack [ 2 ] . next ) . toEqual ( stack [ 0 ] )
177+ expect ( stack [ 0 ] . left ) . toEqual ( stack [ 5 ] )
178+ expect ( stack [ 1 ] . next ) . toBeUndefined ( )
179+ expect ( stack [ 1 ] . right ) . toEqual ( stack [ 2 ] )
180+ expect ( stack [ 1 ] . left ) . toEqual ( stack [ 3 ] )
181+ expect ( stack [ 2 ] . next ) . toEqual ( stack [ 3 ] )
159182 expect ( stack [ 2 ] . right ) . toBeUndefined ( )
160183 expect ( stack [ 2 ] . left ) . toBeUndefined ( )
161- expect ( stack [ 3 ] . next ) . toBeUndefined ( )
184+ expect ( stack [ 3 ] . next ) . toEqual ( stack [ 4 ] )
162185 expect ( stack [ 3 ] . right ) . toBeUndefined ( )
163186 expect ( stack [ 3 ] . left ) . toBeUndefined ( )
187+ expect ( stack [ 4 ] . next ) . toEqual ( stack [ 0 ] )
188+ expect ( stack [ 4 ] . right ) . toBeUndefined ( )
189+ expect ( stack [ 4 ] . left ) . toBeUndefined ( )
190+ expect ( stack [ 5 ] . next ) . toBeUndefined ( )
191+ expect ( stack [ 5 ] . right ) . toBeUndefined ( )
192+ expect ( stack [ 5 ] . left ) . toBeUndefined ( )
164193 } )
165194 test ( 'if-command-while-command-end-end' , ( ) => {
166195 let input = [
0 commit comments