@@ -907,7 +907,6 @@ describe('RubyToBlocksConverter/Control', () => {
907907 }
908908 ] ;
909909 convertAndExpectToEqualBlocks ( converter , target , code , expected ) ;
910-
911910 } ) ;
912911
913912 test ( 'invalid' , ( ) => {
@@ -919,4 +918,63 @@ describe('RubyToBlocksConverter/Control', () => {
919918 } ) ;
920919 } ) ;
921920 } ) ;
921+
922+ describe ( 'control_start_as_clone' , ( ) => {
923+ test ( 'normal' , ( ) => {
924+ code = `
925+ self.when(:start_as_a_clone) do
926+ end
927+ ` ;
928+ expected = [
929+ {
930+ opcode : 'control_start_as_clone'
931+ }
932+ ] ;
933+ convertAndExpectToEqualBlocks ( converter , target , code , expected ) ;
934+
935+ code = `
936+ self.when(:start_as_a_clone) do
937+ move(10)
938+ end
939+ ` ;
940+ expected = [
941+ {
942+ opcode : 'control_start_as_clone' ,
943+ next : rubyToExpected ( converter , target , 'move(10)' ) [ 0 ]
944+ }
945+ ] ;
946+ convertAndExpectToEqualBlocks ( converter , target , code , expected ) ;
947+
948+ code = `
949+ self.when(:start_as_a_clone) do
950+ move(10)
951+ bounce_if_on_edge
952+ end
953+ ` ;
954+ expected = [
955+ {
956+ opcode : 'control_start_as_clone' ,
957+ next : rubyToExpected ( converter , target , 'move(10); bounce_if_on_edge' ) [ 0 ]
958+ }
959+ ] ;
960+ convertAndExpectToEqualBlocks ( converter , target , code , expected ) ;
961+ } ) ;
962+
963+ test ( 'invalid' , ( ) => {
964+ [
965+ 'self.when(:start_as_a_clone)' ,
966+ 'self.when(:start_as_a_clone, 1)'
967+ ] . forEach ( s => {
968+ convertAndExpectToEqualRubyStatement ( converter , target , s , s ) ;
969+ } ) ;
970+
971+ [
972+ '12.when(:start_as_a_clone) {}'
973+ ] . forEach ( s => {
974+ expect ( converter . targetCodeToBlocks ( target , s ) ) . toBeTruthy ( ) ;
975+ const blockId = Object . keys ( converter . blocks ) . filter ( id => converter . blocks [ id ] . topLevel ) [ 0 ] ;
976+ expect ( converter . blocks [ blockId ] . opcode ) . toEqual ( 'ruby_statement_with_block' ) ;
977+ } ) ;
978+ } ) ;
979+ } ) ;
922980} ) ;
0 commit comments