@@ -283,44 +283,109 @@ describe('RubyToBlocksConverter/Control', () => {
283283 } ) ;
284284 } ) ;
285285
286- test ( 'control_forever' , ( ) => {
287- code = 'loop { bounce_if_on_edge; wait }' ;
288- expected = [
289- {
290- opcode : 'control_forever' ,
291- branches : [
292- {
293- opcode : 'motion_ifonedgebounce'
294- }
295- ]
296- }
297- ] ;
298- convertAndExpectToEqualBlocks ( converter , target , code , expected ) ;
286+ describe ( 'control_forever' , ( ) => {
287+ test ( 'loop' , ( ) => {
288+ code = 'loop { wait }' ;
289+ expected = [
290+ {
291+ opcode : 'control_forever' ,
292+ branches : [ ]
293+ }
294+ ] ;
295+ convertAndExpectToEqualBlocks ( converter , target , code , expected ) ;
299296
300- code = 'loop { bounce_if_on_edge; move(10); wait }' ;
301- expected = [
302- {
303- opcode : 'control_forever' ,
304- branches : [
305- rubyToExpected ( converter , target , 'bounce_if_on_edge; move(10)' ) [ 0 ]
306- ]
307- }
308- ] ;
309- convertAndExpectToEqualBlocks ( converter , target , code , expected ) ;
297+ code = 'loop { bounce_if_on_edge; wait }' ;
298+ expected = [
299+ {
300+ opcode : 'control_forever' ,
301+ branches : [
302+ {
303+ opcode : 'motion_ifonedgebounce'
304+ }
305+ ]
306+ }
307+ ] ;
308+ convertAndExpectToEqualBlocks ( converter , target , code , expected ) ;
310309
311- [
312- 'loop()' ,
313- 'loop(1)'
314- ] . forEach ( s => {
315- convertAndExpectToEqualRubyStatement ( converter , target , s , s ) ;
310+ code = 'loop { bounce_if_on_edge; move(10); wait }' ;
311+ expected = [
312+ {
313+ opcode : 'control_forever' ,
314+ branches : [
315+ rubyToExpected ( converter , target , 'bounce_if_on_edge; move(10)' ) [ 0 ]
316+ ]
317+ }
318+ ] ;
319+ convertAndExpectToEqualBlocks ( converter , target , code , expected ) ;
316320 } ) ;
317321
318- [
319- 'loop { bounce_if_on_edge }'
320- ] . forEach ( s => {
321- expect ( converter . targetCodeToBlocks ( target , s ) ) . toBeTruthy ( ) ;
322- const blockId = Object . keys ( converter . blocks ) . filter ( id => converter . blocks [ id ] . topLevel ) [ 0 ] ;
323- expect ( converter . blocks [ blockId ] . opcode ) . toEqual ( 'ruby_statement_with_block' ) ;
322+ test ( 'forever' , ( ) => {
323+ code = 'forever { }' ;
324+ expected = [
325+ {
326+ opcode : 'control_forever' ,
327+ branches : [ ]
328+ }
329+ ] ;
330+ convertAndExpectToEqualBlocks ( converter , target , code , expected ) ;
331+
332+ code = 'forever { bounce_if_on_edge }' ;
333+ expected = [
334+ {
335+ opcode : 'control_forever' ,
336+ branches : [
337+ {
338+ opcode : 'motion_ifonedgebounce'
339+ }
340+ ]
341+ }
342+ ] ;
343+ convertAndExpectToEqualBlocks ( converter , target , code , expected ) ;
344+
345+ code = 'forever { bounce_if_on_edge; move(10) }' ;
346+ expected = [
347+ {
348+ opcode : 'control_forever' ,
349+ branches : [
350+ rubyToExpected ( converter , target , 'bounce_if_on_edge; move(10)' ) [ 0 ]
351+ ]
352+ }
353+ ] ;
354+ convertAndExpectToEqualBlocks ( converter , target , code , expected ) ;
355+
356+ code = 'forever { wait }' ;
357+ expected = [
358+ {
359+ opcode : 'control_forever' ,
360+ branches : [
361+ rubyToExpected ( converter , target , 'wait' ) [ 0 ]
362+ ]
363+ }
364+ ] ;
365+ convertAndExpectToEqualBlocks ( converter , target , code , expected ) ;
366+ } ) ;
367+
368+ test ( 'invalid' , ( ) => {
369+ [
370+ 'loop()' ,
371+ 'loop(1)' ,
372+ 'forever()' ,
373+ 'forever(1)'
374+ ] . forEach ( s => {
375+ convertAndExpectToEqualRubyStatement ( converter , target , s , s ) ;
376+ } ) ;
377+
378+ [
379+ 'loop { bounce_if_on_edge }' ,
380+ 'loop { |a| bounce_if_on_edge; wait }' ,
381+ 'loop(1) { bounce_if_on_edge; wait }' ,
382+ 'forever(1) { bounce_if_on_edge }' ,
383+ 'forever(1) { |a| bounce_if_on_edge }'
384+ ] . forEach ( s => {
385+ expect ( converter . targetCodeToBlocks ( target , s ) ) . toBeTruthy ( ) ;
386+ const blockId = Object . keys ( converter . blocks ) . filter ( id => converter . blocks [ id ] . topLevel ) [ 0 ] ;
387+ expect ( converter . blocks [ blockId ] . opcode ) . toEqual ( 'ruby_statement_with_block' ) ;
388+ } ) ;
324389 } ) ;
325390 } ) ;
326391
0 commit comments