|
3 | 3 | convertAndExpectToEqualBlocks, |
4 | 4 | convertAndExpectToEqualRubyStatement, |
5 | 5 | rubyToExpected, |
| 6 | + expectedInfo, |
6 | 7 | expectNoArgsMethod |
7 | 8 | } from '../../../helpers/expect-to-equal-blocks'; |
8 | 9 |
|
@@ -359,6 +360,63 @@ describe('RubyToBlocksConverter/Sensing', () => { |
359 | 360 | }); |
360 | 361 | }); |
361 | 362 |
|
| 363 | + describe('sensing_askandwait', () => { |
| 364 | + test('normal', () => { |
| 365 | + code = 'ask("What\'s your name?")'; |
| 366 | + expected = [ |
| 367 | + { |
| 368 | + opcode: 'sensing_askandwait', |
| 369 | + inputs: [ |
| 370 | + { |
| 371 | + name: 'QUESTION', |
| 372 | + block: expectedInfo.makeText('What\'s your name?') |
| 373 | + } |
| 374 | + ] |
| 375 | + } |
| 376 | + ]; |
| 377 | + convertAndExpectToEqualBlocks(converter, target, code, expected); |
| 378 | + |
| 379 | + code = 'ask(x)'; |
| 380 | + expected = [ |
| 381 | + { |
| 382 | + opcode: 'sensing_askandwait', |
| 383 | + inputs: [ |
| 384 | + { |
| 385 | + name: 'QUESTION', |
| 386 | + block: rubyToExpected(converter, target, 'x')[0], |
| 387 | + shadow: expectedInfo.makeText('What\'s your name?') |
| 388 | + } |
| 389 | + ] |
| 390 | + } |
| 391 | + ]; |
| 392 | + convertAndExpectToEqualBlocks(converter, target, code, expected); |
| 393 | + }); |
| 394 | + |
| 395 | + test('statement', () => { |
| 396 | + code = ` |
| 397 | + bounce_if_on_edge |
| 398 | + ask("What's your name?") |
| 399 | + bounce_if_on_edge |
| 400 | + `; |
| 401 | + expected = [ |
| 402 | + rubyToExpected(converter, target, 'bounce_if_on_edge')[0] |
| 403 | + ]; |
| 404 | + expected[0].next = rubyToExpected(converter, target, 'ask("What\'s your name?")')[0]; |
| 405 | + expected[0].next.next = rubyToExpected(converter, target, 'bounce_if_on_edge')[0]; |
| 406 | + convertAndExpectToEqualBlocks(converter, target, code, expected); |
| 407 | + }); |
| 408 | + |
| 409 | + test('invalid', () => { |
| 410 | + [ |
| 411 | + 'ask()', |
| 412 | + 'ask(1)', |
| 413 | + 'ask("What\'s your name?", 1)' |
| 414 | + ].forEach(c => { |
| 415 | + convertAndExpectToEqualRubyStatement(converter, target, c, c); |
| 416 | + }); |
| 417 | + }); |
| 418 | + }); |
| 419 | + |
362 | 420 | expectNoArgsMethod('sensing_answer', 'answer', 'value'); |
363 | 421 | expectNoArgsMethod('sensing_mousedown', 'Mouse.down?', 'value_boolean'); |
364 | 422 | expectNoArgsMethod('sensing_mousex', 'Mouse.x', 'value'); |
|
0 commit comments