@@ -93,6 +93,18 @@ describe('RubyToBlocksConverter/Sensing', () => {
9393 convertAndExpectToEqualRubyStatement ( converter , target , c , c ) ;
9494 } ) ;
9595 } ) ;
96+
97+ test ( 'error' , ( ) => {
98+ code = `
99+ forever do
100+ touching?("_edge_")
101+ end
102+ ` ;
103+ const res = converter . targetCodeToBlocks ( target , code ) ;
104+ expect ( converter . errors ) . toHaveLength ( 1 ) ;
105+ expect ( converter . errors [ 0 ] . row ) . toEqual ( 2 ) ;
106+ expect ( res ) . toBeFalsy ( ) ;
107+ } ) ;
96108 } ) ;
97109
98110 describe ( 'sensing_touchingcolor' , ( ) => {
@@ -173,6 +185,18 @@ describe('RubyToBlocksConverter/Sensing', () => {
173185 convertAndExpectToEqualRubyStatement ( converter , target , c , c ) ;
174186 } ) ;
175187 } ) ;
188+
189+ test ( 'error' , ( ) => {
190+ code = `
191+ forever do
192+ touching_color?("#43066f")
193+ end
194+ ` ;
195+ const res = converter . targetCodeToBlocks ( target , code ) ;
196+ expect ( converter . errors ) . toHaveLength ( 1 ) ;
197+ expect ( converter . errors [ 0 ] . row ) . toEqual ( 2 ) ;
198+ expect ( res ) . toBeFalsy ( ) ;
199+ } ) ;
176200 } ) ;
177201
178202 describe ( 'sensing_coloristouchingcolor' , ( ) => {
@@ -283,6 +307,18 @@ describe('RubyToBlocksConverter/Sensing', () => {
283307 convertAndExpectToEqualRubyStatement ( converter , target , c , c ) ;
284308 } ) ;
285309 } ) ;
310+
311+ test ( 'error' , ( ) => {
312+ code = `
313+ forever do
314+ color_is_touching_color?("#aad315", "#fca3bf")
315+ end
316+ ` ;
317+ const res = converter . targetCodeToBlocks ( target , code ) ;
318+ expect ( converter . errors ) . toHaveLength ( 1 ) ;
319+ expect ( converter . errors [ 0 ] . row ) . toEqual ( 2 ) ;
320+ expect ( res ) . toBeFalsy ( ) ;
321+ } ) ;
286322 } ) ;
287323
288324 describe ( 'sensing_distanceto' , ( ) => {
@@ -358,6 +394,18 @@ describe('RubyToBlocksConverter/Sensing', () => {
358394 convertAndExpectToEqualRubyStatement ( converter , target , c , c ) ;
359395 } ) ;
360396 } ) ;
397+
398+ test ( 'error' , ( ) => {
399+ code = `
400+ forever do
401+ distance("_mouse_")
402+ end
403+ ` ;
404+ const res = converter . targetCodeToBlocks ( target , code ) ;
405+ expect ( converter . errors ) . toHaveLength ( 1 ) ;
406+ expect ( converter . errors [ 0 ] . row ) . toEqual ( 2 ) ;
407+ expect ( res ) . toBeFalsy ( ) ;
408+ } ) ;
361409 } ) ;
362410
363411 describe ( 'sensing_askandwait' , ( ) => {
@@ -418,6 +466,96 @@ describe('RubyToBlocksConverter/Sensing', () => {
418466 } ) ;
419467
420468 expectNoArgsMethod ( 'sensing_answer' , 'answer' , 'value' ) ;
469+
470+ describe ( 'sensing_keypressed' , ( ) => {
471+ test ( 'normal' , ( ) => {
472+ code = 'Keyboard.pressed?("space")' ;
473+ expected = [
474+ {
475+ opcode : 'sensing_keypressed' ,
476+ inputs : [
477+ {
478+ name : 'KEY_OPTION' ,
479+ block : {
480+ opcode : 'sensing_keyoptions' ,
481+ fields : [
482+ {
483+ name : 'KEY_OPTION' ,
484+ value : 'space'
485+ }
486+ ] ,
487+ shadow : true
488+ }
489+ }
490+ ]
491+ }
492+ ] ;
493+ convertAndExpectToEqualBlocks ( converter , target , code , expected ) ;
494+
495+ code = 'Keyboard.pressed?(x)' ;
496+ expected = [
497+ {
498+ opcode : 'sensing_keypressed' ,
499+ inputs : [
500+ {
501+ name : 'KEY_OPTION' ,
502+ block : rubyToExpected ( converter , target , 'x' ) [ 0 ] ,
503+ shadow : {
504+ opcode : 'sensing_keyoptions' ,
505+ fields : [
506+ {
507+ name : 'KEY_OPTION' ,
508+ value : 'space'
509+ }
510+ ] ,
511+ shadow : true
512+ }
513+ }
514+ ]
515+ }
516+ ] ;
517+ convertAndExpectToEqualBlocks ( converter , target , code , expected ) ;
518+ } ) ;
519+
520+ test ( 'value_boolean' , ( ) => {
521+ code = `
522+ bounce_if_on_edge
523+ Keyboard.pressed?("space")
524+ bounce_if_on_edge
525+ ` ;
526+ expected = [
527+ rubyToExpected ( converter , target , 'bounce_if_on_edge' ) [ 0 ] ,
528+ rubyToExpected ( converter , target , 'Keyboard.pressed?("space")' ) [ 0 ] ,
529+ rubyToExpected ( converter , target , 'bounce_if_on_edge' ) [ 0 ]
530+ ] ;
531+ convertAndExpectToEqualBlocks ( converter , target , code , expected ) ;
532+ } ) ;
533+
534+ test ( 'invalid' , ( ) => {
535+ [
536+ 'Keyboard.pressed?' ,
537+ 'Keyboard.pressed?()' ,
538+ 'Keyboard.pressed?(1)' ,
539+ 'Keyboard.pressed?("invalid")' ,
540+ 'Keyboard.pressed?("space", 1)'
541+ ] . forEach ( c => {
542+ convertAndExpectToEqualRubyStatement ( converter , target , c , c ) ;
543+ } ) ;
544+ } ) ;
545+
546+ test ( 'error' , ( ) => {
547+ code = `
548+ forever do
549+ Keyboard.pressed?("space")
550+ end
551+ ` ;
552+ const res = converter . targetCodeToBlocks ( target , code ) ;
553+ expect ( converter . errors ) . toHaveLength ( 1 ) ;
554+ expect ( converter . errors [ 0 ] . row ) . toEqual ( 2 ) ;
555+ expect ( res ) . toBeFalsy ( ) ;
556+ } ) ;
557+ } ) ;
558+
421559 expectNoArgsMethod ( 'sensing_mousedown' , 'Mouse.down?' , 'value_boolean' ) ;
422560 expectNoArgsMethod ( 'sensing_mousex' , 'Mouse.x' , 'value' ) ;
423561 expectNoArgsMethod ( 'sensing_mousey' , 'Mouse.y' , 'value' ) ;
0 commit comments