@@ -52,6 +52,7 @@ def createScratch3Block(context, opcode):
52
52
block ["parent" ] = None
53
53
block ["next" ] = None
54
54
block = Scratch3Block (block , name )
55
+ context .spriteblocks [name ] = block
55
56
56
57
return block
57
58
@@ -69,7 +70,6 @@ def create_dummy_formula_block(context):
69
70
70
71
71
72
def createDummyProject ():
72
-
73
73
pass
74
74
75
75
def createDummySprite ():
@@ -317,6 +317,204 @@ def test_visitVolume(self):
317
317
converted_block = visitBlock (context )
318
318
assert converted_block [0 ] == "volume"
319
319
320
+ def test_visitTouchingObject (self ):
321
+ context = create_block_context ("sensing_touchingobject" )
322
+ testblock = context .block
323
+ menublock = createScratch3Block (context , "sensing_touchingobjectmenu" )
324
+ menublock .fields ["TOUCHINGOBJECTMENU" ] = ['_mouse_' ]
325
+ testblock .inputs ["TOUCHINGOBJECTMENU" ] = [1 , menublock .name ]
326
+
327
+ converted_block = visitBlock (context )
328
+
329
+ assert converted_block [0 ] == "touching:"
330
+ assert converted_block [1 ] == "_mouse_"
331
+
332
+
333
+ # def test_visitTouchingObjectMenu(self):
334
+ # context = create_block_context("sensing_touchingobjectmenu")
335
+ # testblock = context.block
336
+ # assert False
337
+
338
+ def test_visitAskandwait (self ):
339
+ context = create_block_context ("sensing_askandwait" )
340
+ testblock = context .block
341
+ addInputOfType (testblock , "QUESTION" , TYPE_STRING )
342
+
343
+ converted_block = visitBlock (context )
344
+
345
+ assert converted_block [0 ] == "doAsk"
346
+ assert converted_block [1 ] == "teststring"
347
+
348
+ def test_visitSetdragmode (self ):
349
+ context = create_block_context ("sensing_setdragmode" )
350
+ testblock = context .block
351
+ testblock .fields ["DRAG_MODE" ] = ["mode" ]
352
+
353
+ converted_block = visitBlock (context )
354
+ assert converted_block [0 ] == "dragMode"
355
+ assert converted_block [1 ] == "mode"
356
+
357
+ def test_visitResettimer (self ):
358
+ context = create_block_context ("sensing_resettimer" )
359
+ testblock = context .block
360
+
361
+ converted_block = visitBlock (context )
362
+
363
+ assert converted_block [0 ] == "timerReset"
364
+
365
+ def test_visitLoudness (self ):
366
+ context = create_block_context ("sensing_loudness" )
367
+ testblock = context .block
368
+ converted_block = visitBlock (context )
369
+
370
+ assert converted_block [0 ] == "soundLevel"
371
+
372
+ def test_visitDistanceto (self ):
373
+ context = create_block_context ("sensing_distanceto" )
374
+ testblock = context .block
375
+
376
+ menublock = createScratch3Block (context , "sensing_distancetomenu" )
377
+ menublock .fields ["DISTANCETOMENU" ] = ['testsprite' ]
378
+ testblock .inputs ["DISTANCETOMENU" ] = [1 , menublock .name ]
379
+
380
+ converted_block = visitBlock (context )
381
+
382
+ assert converted_block [0 ] == "distanceTo:"
383
+ assert converted_block [1 ] == "testsprite"
384
+
385
+ # def test_visitDistancetomenu(self):
386
+ # context = create_block_context("sensing_distancetomenu")
387
+ # testblock = context.block
388
+ # assert False
389
+
390
+ def test_visitColoristouchingcolor (self ):
391
+ context = create_block_context ("sensing_coloristouchingcolor" )
392
+ testblock = context .block
393
+
394
+ addInputOfType (testblock , "COLOR" , TYPE_STRING )
395
+ addInputOfType (testblock , "COLOR2" , TYPE_STRING )
396
+
397
+ converted_block = visitBlock (context )
398
+
399
+ assert converted_block [0 ] == "touchingColor:"
400
+ assert converted_block [1 ] == "teststring"
401
+ assert converted_block [2 ] == "teststring"
402
+
403
+ def test_visitOf (self ):
404
+ context = create_block_context ("sensing_of" )
405
+ testblock = context .block
406
+ addInputOfType (testblock , "OBJECT" , TYPE_STRING )
407
+ testblock .fields ["PROPERTY" ] = ['direction' ]
408
+
409
+ converted_block = visitBlock (context )
410
+
411
+ assert converted_block [0 ] == "getAttribute:of:"
412
+ assert converted_block [1 ] == "direction"
413
+ assert converted_block [2 ] == "teststring"
414
+
415
+ def test_visitCurrent (self ):
416
+ context = create_block_context ("sensing_current" )
417
+ testblock = context .block
418
+
419
+ menublock = createScratch3Block (context , "sensing_currentmenu" )
420
+ menublock .fields ["CURRENTMENU" ] = ['year' ]
421
+ testblock .inputs ["CURRENTMENU" ] = [1 , menublock .name ]
422
+
423
+ converted_block = visitBlock (context )
424
+
425
+ assert converted_block [0 ] == "timeAndDate"
426
+ assert converted_block [1 ] == "year"
427
+
428
+ # def test_visitCurrent_menu(self):
429
+ # context = create_block_context("sensing_currentmenu")
430
+ # testblock = context.block
431
+ # assert False
432
+
433
+ def test_visitAnswer (self ):
434
+ context = create_block_context ("sensing_answer" )
435
+ testblock = context .block
436
+
437
+ converted_block = visitBlock (context )
438
+
439
+ assert converted_block [0 ] == "answer"
440
+
441
+ def test_visitDayssince2000 (self ):
442
+ context = create_block_context ("sensing_dayssince2000" )
443
+ testblock = context .block
444
+
445
+ converted_block = visitBlock (context )
446
+
447
+ assert converted_block [0 ] == "timestamp"
448
+
449
+ def test_visitKeypressed (self ):
450
+ context = create_block_context ("sensing_keypressed" )
451
+ testblock = context .block
452
+ menublock = createScratch3Block (context , "sensing_keyoptions" )
453
+ menublock .fields ["KEY_OPTION" ] = ['a' ]
454
+ testblock .inputs ["KEY_OPTION" ] = [1 , menublock .name ]
455
+
456
+ converted_block = visitBlock (context )
457
+ assert converted_block [0 ] == "keyPressed:"
458
+ assert converted_block [1 ] == "a"
459
+
460
+ # def test_visitKey_options(self):
461
+ # context = create_block_context("sensing_key_options")
462
+ # testblock = context.block
463
+ # assert False
464
+
465
+ def test_visitMousex (self ):
466
+ context = create_block_context ("sensing_mousex" )
467
+ testblock = context .block
468
+
469
+ converted_block = visitBlock (context )
470
+
471
+ assert converted_block [0 ] == "mouseX"
472
+
473
+ def test_visitMousedown (self ):
474
+ context = create_block_context ("sensing_mousedown" )
475
+ testblock = context .block
476
+
477
+ converted_block = visitBlock (context )
478
+ assert converted_block [0 ] == "mousePressed"
479
+
480
+ def test_visitMousey (self ):
481
+ context = create_block_context ("sensing_mousey" )
482
+ testblock = context .block
483
+
484
+ converted_block = visitBlock (context )
485
+
486
+ assert converted_block [0 ] == "mouseY"
487
+
488
+ def test_visitTimer (self ):
489
+ context = create_block_context ("sensing_timer" )
490
+ testblock = context .block
491
+
492
+ converted_block = visitBlock (context )
493
+
494
+ assert converted_block [0 ] == "timer"
495
+
496
+ def test_visitTouchingcolor (self ):
497
+ context = create_block_context ("sensing_touchingcolor" )
498
+ testblock = context .block
499
+ addInputOfType (testblock , "COLOR" , TYPE_STRING )
500
+
501
+ converted_block = visitBlock (context )
502
+
503
+ assert converted_block [0 ] == "touchingColor:"
504
+ assert converted_block [1 ] == "teststring"
505
+
506
+ def test_visitUsername (self ):
507
+ context = create_block_context ("sensing_username" )
508
+ testblock = context .block
509
+
510
+ converted_block = visitBlock (context )
511
+
512
+ assert converted_block [0 ] == "getUserName"
513
+
514
+ # def test_visitOf_object_menu(self):
515
+ # context = create_block_context("sensing_of_object_menu")
516
+ # testblock = context.block
517
+ # assert False
320
518
321
519
if __name__ == "__main__" :
322
520
unittest .main ()
0 commit comments