smalruby-editor 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of smalruby-editor might be problematic. Click here for more details.

Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/blocks/hardware.js.coffee.erb +40 -3
  3. data/app/assets/stylesheets/toolbox.css.scss.erb +1 -6
  4. data/app/controllers/source_codes_controller.rb +5 -1
  5. data/app/models/concerns/ruby_to_block.rb +17 -360
  6. data/app/models/concerns/ruby_to_block/block.rb +97 -0
  7. data/app/models/concerns/ruby_to_block/block/base.rb +251 -0
  8. data/app/models/concerns/ruby_to_block/block/character.rb +42 -0
  9. data/app/models/concerns/ruby_to_block/block/character_event.rb +27 -0
  10. data/app/models/concerns/ruby_to_block/block/character_method_call.rb +29 -0
  11. data/app/models/concerns/ruby_to_block/block/character_new.rb +7 -0
  12. data/app/models/concerns/ruby_to_block/block/character_operation.rb +80 -0
  13. data/app/models/concerns/ruby_to_block/block/control_if.rb +45 -0
  14. data/app/models/concerns/ruby_to_block/block/control_loop.rb +19 -0
  15. data/app/models/concerns/ruby_to_block/block/control_sleep.rb +18 -0
  16. data/app/models/concerns/ruby_to_block/block/do.rb +24 -0
  17. data/app/models/concerns/ruby_to_block/block/else.rb +12 -0
  18. data/app/models/concerns/ruby_to_block/block/end.rb +26 -0
  19. data/app/models/concerns/ruby_to_block/block/events_on_click.rb +14 -0
  20. data/app/models/concerns/ruby_to_block/block/events_on_key_push_or_down.rb +17 -0
  21. data/app/models/concerns/ruby_to_block/block/events_on_start.rb +14 -0
  22. data/app/models/concerns/ruby_to_block/block/hardware_init_hardware.rb +14 -0
  23. data/app/models/concerns/ruby_to_block/block/hardware_led_off.rb +16 -0
  24. data/app/models/concerns/ruby_to_block/block/hardware_led_on.rb +16 -0
  25. data/app/models/concerns/ruby_to_block/block/hardware_on_sensor_change.rb +17 -0
  26. data/app/models/concerns/ruby_to_block/block/hardware_rgb_led_off.rb +18 -0
  27. data/app/models/concerns/ruby_to_block/block/hardware_rgb_led_on.rb +23 -0
  28. data/app/models/concerns/ruby_to_block/block/hardware_sensor_value.rb +23 -0
  29. data/app/models/concerns/ruby_to_block/block/hardware_two_wheel_drive_car.rb +26 -0
  30. data/app/models/concerns/ruby_to_block/block/looks_hide.rb +8 -0
  31. data/app/models/concerns/ruby_to_block/block/looks_say.rb +20 -0
  32. data/app/models/concerns/ruby_to_block/block/looks_show.rb +8 -0
  33. data/app/models/concerns/ruby_to_block/block/looks_vanish.rb +8 -0
  34. data/app/models/concerns/ruby_to_block/block/math_number.rb +14 -0
  35. data/app/models/concerns/ruby_to_block/block/motion_change_x_by.rb +20 -0
  36. data/app/models/concerns/ruby_to_block/block/motion_change_y_by.rb +20 -0
  37. data/app/models/concerns/ruby_to_block/block/motion_move.rb +15 -0
  38. data/app/models/concerns/ruby_to_block/block/motion_point_towards_character.rb +24 -0
  39. data/app/models/concerns/ruby_to_block/block/motion_point_towards_mouse.rb +9 -0
  40. data/app/models/concerns/ruby_to_block/block/motion_reach_wall.rb +24 -0
  41. data/app/models/concerns/ruby_to_block/block/motion_rotate_left.rb +20 -0
  42. data/app/models/concerns/ruby_to_block/block/motion_rotate_right.rb +20 -0
  43. data/app/models/concerns/ruby_to_block/block/motion_self_angle.rb +23 -0
  44. data/app/models/concerns/ruby_to_block/block/motion_self_x.rb +23 -0
  45. data/app/models/concerns/ruby_to_block/block/motion_self_y.rb +23 -0
  46. data/app/models/concerns/ruby_to_block/block/motion_set_angle.rb +15 -0
  47. data/app/models/concerns/ruby_to_block/block/motion_set_x.rb +38 -0
  48. data/app/models/concerns/ruby_to_block/block/motion_set_y.rb +15 -0
  49. data/app/models/concerns/ruby_to_block/block/motion_turn.rb +8 -0
  50. data/app/models/concerns/ruby_to_block/block/motion_turn_if_reach_wall.rb +8 -0
  51. data/app/models/concerns/ruby_to_block/block/null.rb +17 -0
  52. data/app/models/concerns/ruby_to_block/block/operators_compare.rb +36 -0
  53. data/app/models/concerns/ruby_to_block/block/operators_false.rb +8 -0
  54. data/app/models/concerns/ruby_to_block/block/operators_true.rb +8 -0
  55. data/app/models/concerns/ruby_to_block/block/require_smalruby.rb +7 -0
  56. data/app/models/concerns/ruby_to_block/block/ruby_comment.rb +16 -0
  57. data/app/models/concerns/ruby_to_block/block/ruby_expression.rb +14 -0
  58. data/app/models/concerns/ruby_to_block/block/ruby_statement.rb +23 -0
  59. data/app/models/concerns/ruby_to_block/block/sensing_hit.rb +23 -0
  60. data/app/models/concerns/ruby_to_block/block/sound_play.rb +15 -0
  61. data/app/models/concerns/ruby_to_block/block/sound_preset_sounds.rb +31 -0
  62. data/app/models/concerns/ruby_to_block/block/text.rb +15 -0
  63. data/app/models/concerns/ruby_to_block/block/value.rb +12 -0
  64. data/app/models/concerns/ruby_to_block/context.rb +97 -0
  65. data/app/models/concerns/ruby_to_block/formatter.rb +26 -0
  66. data/app/models/source_code.rb +3 -1
  67. data/app/views/editor/_toolbox.html.haml +16 -0
  68. data/lib/smalruby_editor/version.rb +3 -3
  69. data/smalruby-editor.gemspec +1 -1
  70. data/spec/acceptance/block_mode/blocks/hardware/two_wheel_drive_car.feature +69 -0
  71. data/spec/acceptance/ruby_mode/translate.feature +1 -1
  72. data/spec/controllers/source_codes_controller_spec.rb +14 -11
  73. data/spec/models/concerns/ruby_to_block/block/character_method_call_spec.rb +175 -0
  74. data/spec/models/concerns/ruby_to_block/block/control_if_spec.rb +75 -0
  75. data/spec/models/concerns/ruby_to_block/block/control_loop_spec.rb +68 -0
  76. data/spec/models/concerns/ruby_to_block/block/events_on_start_spec.rb +120 -0
  77. data/spec/models/concerns/ruby_to_block/block/hardware_spec.rb +120 -0
  78. data/spec/models/concerns/ruby_to_block/block/looks_say_spec.rb +79 -0
  79. data/spec/models/concerns/ruby_to_block/block/looks_spec.rb +74 -0
  80. data/spec/models/concerns/ruby_to_block/block/motion_move_spec.rb +63 -0
  81. data/spec/models/concerns/ruby_to_block/block/motion_reach_wall_spec.rb +67 -0
  82. data/spec/models/concerns/ruby_to_block/block/motion_spec.rb +392 -0
  83. data/spec/models/concerns/ruby_to_block/block/motion_turn_spec.rb +54 -0
  84. data/spec/models/concerns/ruby_to_block/block/require_smalruby_spec.rb +39 -0
  85. data/spec/models/concerns/ruby_to_block/block/ruby_comment_spec.rb +55 -0
  86. data/spec/models/concerns/ruby_to_block/block/ruby_statement_spec.rb +113 -0
  87. data/spec/models/concerns/ruby_to_block/block/shared/block_examples.rb +44 -0
  88. data/spec/models/concerns/ruby_to_block/block/sound_spec.rb +46 -0
  89. data/spec/models/concerns/ruby_to_block/block_spec.rb +49 -0
  90. data/spec/models/concerns/ruby_to_block_spec.rb +421 -217
  91. data/spec/support/ruby_to_block.rb +10 -0
  92. metadata +108 -10
@@ -0,0 +1,120 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require_relative 'shared/block_examples'
4
+
5
+ # rubocop:disable EmptyLines, LineLength
6
+
7
+ describe RubyToBlock::Block, 'ハードウェアジャンル', to_blocks: true do
8
+ parts = <<-EOS
9
+ require "smalruby"
10
+
11
+ init_hardware
12
+ car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
13
+
14
+ car1.on(:start) do
15
+ led("D4").on
16
+ rgb_led_cathode("D9").on(color: [255, 0, 0])
17
+ two_wheel_drive_car("D2").forward
18
+ end
19
+ car1.led("D4").off
20
+ car1.rgb_led_cathode("D9").off
21
+ car1.two_wheel_drive_car("D2").backward
22
+
23
+ car1.on(:sensor_change, "A0") do
24
+ if sensor("A0").value < 200
25
+ two_wheel_drive_car("D2").turn_left
26
+ two_wheel_drive_car("D2").turn_right
27
+ two_wheel_drive_car("D2").stop
28
+ end
29
+ end
30
+ EOS
31
+ describe compact_source_code(parts) do
32
+ _parts = parts
33
+ let(:data) { _parts }
34
+
35
+ it '結果が正しいこと' do
36
+ should eq_block_xml(<<-XML)
37
+ <character name="car1" x="0" y="0" angle="0" costumes="car1.png" />
38
+ <block type="hardware_init_hardware" />
39
+ <block type="character_new">
40
+ <field name="NAME">car1</field>
41
+ <statement name="DO">
42
+ <block type="events_on_start">
43
+ <statement name="DO">
44
+ <block type="hardware_led_on">
45
+ <field name="PIN">D4</field>
46
+ <next>
47
+ <block type="hardware_rgb_led_on">
48
+ <field name="AC">cathode</field>
49
+ <field name="PIN">D9</field>
50
+ <field name="COLOUR">#ff0000</field>
51
+ <next>
52
+ <block type="hardware_two_wheel_drive_car_forward">
53
+ <field name="PIN">D2</field>
54
+ </block>
55
+ </next>
56
+ </block>
57
+ </next>
58
+ </block>
59
+ </statement>
60
+ <next>
61
+ <block type="hardware_led_off">
62
+ <field name="PIN">D4</field>
63
+ <next>
64
+ <block type="hardware_rgb_led_off">
65
+ <field name="AC">cathode</field>
66
+ <field name="PIN">D9</field>
67
+ <next>
68
+ <block type="hardware_two_wheel_drive_car_backward">
69
+ <field name="PIN">D2</field>
70
+ <next>
71
+ <block type="hardware_on_sensor_change">
72
+ <field name="PIN">A0</field>
73
+ <statement name="DO">
74
+ <block type="control_if" inline="true">
75
+ <value name="COND">
76
+ <block type="operators_compare_lt" inline="true">
77
+ <value name="A">
78
+ <block type="hardware_sensor_value">
79
+ <field name="PIN">A0</field>
80
+ </block>
81
+ </value>
82
+ <value name="B">
83
+ <block type="math_number">
84
+ <field name="NUM">200</field>
85
+ </block>
86
+ </value>
87
+ </block>
88
+ </value>
89
+ <statement name="THEN">
90
+ <block type="hardware_two_wheel_drive_car_turn_left">
91
+ <field name="PIN">D2</field>
92
+ <next>
93
+ <block type="hardware_two_wheel_drive_car_turn_right">
94
+ <field name="PIN">D2</field>
95
+ <next>
96
+ <block type="hardware_two_wheel_drive_car_stop">
97
+ <field name="PIN">D2</field>
98
+ </block>
99
+ </next>
100
+ </block>
101
+ </next>
102
+ </block>
103
+ </statement>
104
+ </block>
105
+ </statement>
106
+ </block>
107
+ </next>
108
+ </block>
109
+ </next>
110
+ </block>
111
+ </next>
112
+ </block>
113
+ </next>
114
+ </block>
115
+ </statement>
116
+ </block>
117
+ XML
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,79 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require_relative 'shared/block_examples'
4
+
5
+ # rubocop:disable EmptyLines, LineLength
6
+
7
+ describe RubyToBlock::Block::LooksSay, to_blocks: true do
8
+ parts = <<-EOS
9
+ say(message: "こんにちは")
10
+ EOS
11
+ describe compact_source_code(parts), on_start_data: true do
12
+ _parts = parts
13
+ let(:parts) { _parts }
14
+
15
+ it '結果が正しいこと' do
16
+ should eq_block_xml(<<-XML)
17
+ <block type="looks_say" inline="true">
18
+ <value name="TEXT">
19
+ <block type="text">
20
+ <field name="TEXT">こんにちは</field>
21
+ </block>
22
+ </value>
23
+ </block>
24
+ XML
25
+ end
26
+ end
27
+
28
+ parts = <<-EOS
29
+ car1.say(message: "こんにちは")
30
+ EOS
31
+ describe compact_source_code(parts), character_new_data: true do
32
+ _parts = parts
33
+ let(:parts) { _parts }
34
+
35
+ it '結果が正しいこと' do
36
+ should eq_block_xml(<<-XML)
37
+ <block type="looks_say" inline="true">
38
+ <value name="TEXT">
39
+ <block type="text">
40
+ <field name="TEXT">こんにちは</field>
41
+ </block>
42
+ </value>
43
+ </block>
44
+ XML
45
+ end
46
+ end
47
+
48
+ parts = <<-EOS
49
+ say(message: "こんにちは")
50
+ EOS
51
+ describe compact_source_code(parts) do
52
+ _parts = parts
53
+ let(:data) { _parts }
54
+
55
+ it '結果が正しいこと' do
56
+ should eq_block_xml(<<-XML)
57
+ <block type="ruby_statement">
58
+ <field name="STATEMENT">say(message: &quot;こんにちは&quot;)</field>
59
+ </block>
60
+ XML
61
+ end
62
+ end
63
+
64
+ parts = <<-EOS
65
+ self.say(message: "こんにちは")
66
+ EOS
67
+ describe compact_source_code(parts) do
68
+ _parts = parts
69
+ let(:data) { _parts }
70
+
71
+ it '結果が正しいこと' do
72
+ should eq_block_xml(<<-XML)
73
+ <block type="ruby_statement">
74
+ <field name="STATEMENT">self.say(message: &quot;こんにちは&quot;)</field>
75
+ </block>
76
+ XML
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,74 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require_relative 'shared/block_examples'
4
+
5
+ # rubocop:disable EmptyLines, LineLength
6
+
7
+ describe RubyToBlock::Block, '見た目ジャンル', to_blocks: true do
8
+ parts = <<-EOS
9
+ car1.on(:start) do
10
+ say(message: "こんにちは!")
11
+ self.visible = true
12
+ self.visible = false
13
+ vanish
14
+ end
15
+ car1.say(message: "こんにちは!")
16
+ car1.visible = true
17
+ car1.visible = false
18
+ car1.vanish
19
+ EOS
20
+ describe compact_source_code(parts), character_new_data: true do
21
+ _parts = parts
22
+ let(:parts) { _parts }
23
+
24
+ it '結果が正しいこと' do
25
+ should eq_block_xml(<<-XML)
26
+ <field name="NAME">car1</field>
27
+ <statement name="DO">
28
+ <block type="events_on_start">
29
+ <statement name="DO">
30
+ <block type="looks_say" inline="true">
31
+ <value name="TEXT">
32
+ <block type="text">
33
+ <field name="TEXT">こんにちは!</field>
34
+ </block>
35
+ </value>
36
+ <next>
37
+ <block type="looks_show">
38
+ <next>
39
+ <block type="looks_hide">
40
+ <next>
41
+ <block type="looks_vanish" />
42
+ </next>
43
+ </block>
44
+ </next>
45
+ </block>
46
+ </next>
47
+ </block>
48
+ </statement>
49
+ <next>
50
+ <block type="looks_say" inline="true">
51
+ <value name="TEXT">
52
+ <block type="text">
53
+ <field name="TEXT">こんにちは!</field>
54
+ </block>
55
+ </value>
56
+ <next>
57
+ <block type="looks_show">
58
+ <next>
59
+ <block type="looks_hide">
60
+ <next>
61
+ <block type="looks_vanish" />
62
+ </next>
63
+ </block>
64
+ </next>
65
+ </block>
66
+ </next>
67
+ </block>
68
+ </next>
69
+ </block>
70
+ </statement>
71
+ XML
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,63 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require_relative 'shared/block_examples'
4
+
5
+ # rubocop:disable EmptyLines, LineLength
6
+
7
+ describe RubyToBlock::Block::MotionMove, to_blocks: true do
8
+ parts = <<-EOS
9
+ move(6)
10
+ EOS
11
+ describe compact_source_code(parts), on_start_data: true do
12
+ _parts = parts
13
+ let(:parts) { _parts }
14
+
15
+ it '結果が正しいこと' do
16
+ should eq_block_xml(<<-XML)
17
+ <block type="motion_move" inline="true">
18
+ <value name="STEP">
19
+ <block type="math_number">
20
+ <field name="NUM">6</field>
21
+ </block>
22
+ </value>
23
+ </block>
24
+ XML
25
+ end
26
+ end
27
+
28
+ parts = <<-EOS
29
+ car1.move(6)
30
+ EOS
31
+ describe compact_source_code(parts), character_new_data: true do
32
+ _parts = parts
33
+ let(:parts) { _parts }
34
+
35
+ it '結果が正しいこと' do
36
+ should eq_block_xml(<<-XML)
37
+ <block type="motion_move" inline="true">
38
+ <value name="STEP">
39
+ <block type="math_number">
40
+ <field name="NUM">6</field>
41
+ </block>
42
+ </value>
43
+ </block>
44
+ XML
45
+ end
46
+ end
47
+
48
+ parts = <<-EOS
49
+ move(6)
50
+ EOS
51
+ describe compact_source_code(parts) do
52
+ _parts = parts
53
+ let(:data) { _parts }
54
+
55
+ it '結果が正しいこと' do
56
+ should eq_block_xml(<<-XML)
57
+ <block type="ruby_statement">
58
+ <field name="STATEMENT">move(6)</field>
59
+ </block>
60
+ XML
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,67 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require_relative 'shared/block_examples'
4
+
5
+ # rubocop:disable EmptyLines, LineLength
6
+
7
+ describe RubyToBlock::Block::MotionReachWall, to_blocks: true do
8
+ parts = <<-EOS
9
+ if reach_wall?
10
+
11
+ end
12
+ EOS
13
+ describe compact_source_code(parts), on_start_data: true do
14
+ _parts = parts
15
+ let(:parts) { _parts }
16
+
17
+ it '結果が正しいこと' do
18
+ should eq_block_xml(<<-XML)
19
+ <block type="control_if" inline="true">
20
+ <value name="COND">
21
+ <block type="motion_reach_wall" />
22
+ </value>
23
+ </block>
24
+ XML
25
+ end
26
+ end
27
+
28
+ parts = <<-EOS
29
+ if car1.reach_wall?
30
+
31
+ end
32
+ EOS
33
+ describe compact_source_code(parts), character_new_data: true do
34
+ _parts = parts
35
+ let(:parts) { _parts }
36
+
37
+ it '結果が正しいこと' do
38
+ should eq_block_xml(<<-XML)
39
+ <block type="ruby_expression">
40
+ <field name="EXP">car1.reach_wall?</field>
41
+ </block>
42
+ XML
43
+ end
44
+ end
45
+
46
+ parts = <<-EOS
47
+ if reach_wall?
48
+
49
+ end
50
+ EOS
51
+ describe compact_source_code(parts) do
52
+ _parts = parts
53
+ let(:data) { _parts }
54
+
55
+ it '結果が正しいこと' do
56
+ should eq_block_xml(<<-XML)
57
+ <block type="control_if" inline="true">
58
+ <value name="COND">
59
+ <block type="ruby_expression">
60
+ <field name="EXP">reach_wall?</field>
61
+ </block>
62
+ </value>
63
+ </block>
64
+ XML
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,392 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require_relative 'shared/block_examples'
4
+
5
+ # rubocop:disable EmptyLines, LineLength
6
+
7
+ describe RubyToBlock::Block, '移動・回転ジャンル', to_blocks: true do
8
+ parts = <<-EOS
9
+ car1.on(:start) do
10
+ move(10)
11
+ self.x = 0
12
+ self.y = 0
13
+ self.x += 10
14
+ self.x = 0
15
+ self.y += 10
16
+ self.y = 0
17
+ if x < 300
18
+ if y < 300
19
+
20
+ end
21
+ end
22
+ end
23
+ car1.move(10)
24
+ car1.x = 0
25
+ car1.y = 0
26
+ car1.x += 10
27
+ car1.x = 0
28
+ car1.y += 10
29
+ car1.y = 0
30
+ EOS
31
+ describe compact_source_code(parts), character_new_data: true do
32
+ _parts = parts
33
+ let(:parts) { _parts }
34
+
35
+ it '結果が正しいこと' do
36
+ should eq_block_xml(<<-XML)
37
+ <field name="NAME">car1</field>
38
+ <statement name="DO">
39
+ <block type="events_on_start">
40
+ <statement name="DO">
41
+ <block type="motion_move" inline="true">
42
+ <value name="STEP">
43
+ <block type="math_number">
44
+ <field name="NUM">10</field>
45
+ </block>
46
+ </value>
47
+ <next>
48
+ <block type="motion_set_x_y" inline="true">
49
+ <value name="X">
50
+ <block type="math_number">
51
+ <field name="NUM">0</field>
52
+ </block>
53
+ </value>
54
+ <value name="Y">
55
+ <block type="math_number">
56
+ <field name="NUM">0</field>
57
+ </block>
58
+ </value>
59
+ <next>
60
+ <block type="motion_change_x_by" inline="true">
61
+ <value name="X">
62
+ <block type="math_number">
63
+ <field name="NUM">10</field>
64
+ </block>
65
+ </value>
66
+ <next>
67
+ <block type="motion_set_x" inline="true">
68
+ <value name="X">
69
+ <block type="math_number">
70
+ <field name="NUM">0</field>
71
+ </block>
72
+ </value>
73
+ <next>
74
+ <block type="motion_change_y_by" inline="true">
75
+ <value name="Y">
76
+ <block type="math_number">
77
+ <field name="NUM">10</field>
78
+ </block>
79
+ </value>
80
+ <next>
81
+ <block type="motion_set_y" inline="true">
82
+ <value name="Y">
83
+ <block type="math_number">
84
+ <field name="NUM">0</field>
85
+ </block>
86
+ </value>
87
+ <next>
88
+ <block type="control_if" inline="true">
89
+ <value name="COND">
90
+ <block type="operators_compare_lt" inline="true">
91
+ <value name="A">
92
+ <block type="motion_self_x" />
93
+ </value>
94
+ <value name="B">
95
+ <block type="math_number">
96
+ <field name="NUM">300</field>
97
+ </block>
98
+ </value>
99
+ </block>
100
+ </value>
101
+ <statement name="THEN">
102
+ <block type="control_if" inline="true">
103
+ <value name="COND">
104
+ <block type="operators_compare_lt" inline="true">
105
+ <value name="A">
106
+ <block type="motion_self_y" />
107
+ </value>
108
+ <value name="B">
109
+ <block type="math_number">
110
+ <field name="NUM">300</field>
111
+ </block>
112
+ </value>
113
+ </block>
114
+ </value>
115
+ </block>
116
+ </statement>
117
+ </block>
118
+ </next>
119
+ </block>
120
+ </next>
121
+ </block>
122
+ </next>
123
+ </block>
124
+ </next>
125
+ </block>
126
+ </next>
127
+ </block>
128
+ </next>
129
+ </block>
130
+ </statement>
131
+ <next>
132
+ <block type="motion_move" inline="true">
133
+ <value name="STEP">
134
+ <block type="math_number">
135
+ <field name="NUM">10</field>
136
+ </block>
137
+ </value>
138
+ <next>
139
+ <block type="motion_set_x_y" inline="true">
140
+ <value name="X">
141
+ <block type="math_number">
142
+ <field name="NUM">0</field>
143
+ </block>
144
+ </value>
145
+ <value name="Y">
146
+ <block type="math_number">
147
+ <field name="NUM">0</field>
148
+ </block>
149
+ </value>
150
+ <next>
151
+ <block type="motion_change_x_by" inline="true">
152
+ <value name="X">
153
+ <block type="math_number">
154
+ <field name="NUM">10</field>
155
+ </block>
156
+ </value>
157
+ <next>
158
+ <block type="motion_set_x" inline="true">
159
+ <value name="X">
160
+ <block type="math_number">
161
+ <field name="NUM">0</field>
162
+ </block>
163
+ </value>
164
+ <next>
165
+ <block type="motion_change_y_by" inline="true">
166
+ <value name="Y">
167
+ <block type="math_number">
168
+ <field name="NUM">10</field>
169
+ </block>
170
+ </value>
171
+ <next>
172
+ <block type="motion_set_y" inline="true">
173
+ <value name="Y">
174
+ <block type="math_number">
175
+ <field name="NUM">0</field>
176
+ </block>
177
+ </value>
178
+ </block>
179
+ </next>
180
+ </block>
181
+ </next>
182
+ </block>
183
+ </next>
184
+ </block>
185
+ </next>
186
+ </block>
187
+ </next>
188
+ </block>
189
+ </next>
190
+ </block>
191
+ </statement>
192
+ XML
193
+ end
194
+ end
195
+
196
+ parts = <<-EOS
197
+ car1.move(10)
198
+ car1.x = 0
199
+ car1.y = 0
200
+ car1.x += 10
201
+ EOS
202
+ describe compact_source_code(parts), character_new_data: true do
203
+ _parts = parts
204
+ let(:parts) { _parts }
205
+
206
+ it '結果が正しいこと' do
207
+ should eq_block_xml(<<-XML)
208
+ <field name="NAME">car1</field>
209
+ <statement name="DO">
210
+ <block type="motion_move" inline="true">
211
+ <value name="STEP">
212
+ <block type="math_number">
213
+ <field name="NUM">10</field>
214
+ </block>
215
+ </value>
216
+ <next>
217
+ <block type="motion_set_x_y" inline="true">
218
+ <value name="X">
219
+ <block type="math_number">
220
+ <field name="NUM">0</field>
221
+ </block>
222
+ </value>
223
+ <value name="Y">
224
+ <block type="math_number">
225
+ <field name="NUM">0</field>
226
+ </block>
227
+ </value>
228
+ <next>
229
+ <block type="motion_change_x_by" inline="true">
230
+ <value name="X">
231
+ <block type="math_number">
232
+ <field name="NUM">10</field>
233
+ </block>
234
+ </value>
235
+ </block>
236
+ </next>
237
+ </block>
238
+ </next>
239
+ </block>
240
+ </statement>
241
+ XML
242
+ end
243
+ end
244
+
245
+ parts = <<-EOS
246
+ car1.on(:start) do
247
+ turn_if_reach_wall
248
+ if reach_wall?
249
+ turn
250
+ end
251
+ rotate(15)
252
+ rotate(-15)
253
+ self.angle = 90
254
+ point_towards(:mouse)
255
+ point_towards(car1)
256
+ if angle < 90
257
+
258
+ end
259
+ end
260
+ car1.turn_if_reach_wall
261
+ car1.turn
262
+ car1.rotate(15)
263
+ car1.rotate(-15)
264
+ car1.angle = 90
265
+ car1.point_towards(:mouse)
266
+ car1.point_towards(car1)
267
+ EOS
268
+ describe compact_source_code(parts), character_new_data: true do
269
+ _parts = parts
270
+ let(:parts) { _parts }
271
+
272
+ it '結果が正しいこと' do
273
+ should eq_block_xml(<<-XML)
274
+ <field name="NAME">car1</field>
275
+ <statement name="DO">
276
+ <block type="events_on_start">
277
+ <statement name="DO">
278
+ <block type="motion_turn_if_reach_wall">
279
+ <next>
280
+ <block type="control_if" inline="true">
281
+ <value name="COND">
282
+ <block type="motion_reach_wall" />
283
+ </value>
284
+ <statement name="THEN">
285
+ <block type="motion_turn" />
286
+ </statement>
287
+ <next>
288
+ <block type="motion_rotate_right" inline="true">
289
+ <value name="ANGLE">
290
+ <block type="math_number">
291
+ <field name="NUM">15</field>
292
+ </block>
293
+ </value>
294
+ <next>
295
+ <block type="motion_rotate_left" inline="true">
296
+ <value name="ANGLE">
297
+ <block type="math_number">
298
+ <field name="NUM">15</field>
299
+ </block>
300
+ </value>
301
+ <next>
302
+ <block type="motion_set_angle" inline="true">
303
+ <value name="ANGLE">
304
+ <block type="math_number">
305
+ <field name="NUM">90</field>
306
+ </block>
307
+ </value>
308
+ <next>
309
+ <block type="motion_point_towards_mouse">
310
+ <next>
311
+ <block type="motion_point_towards_character">
312
+ <field name="CHAR">car1</field>
313
+ <next>
314
+ <block type="control_if" inline="true">
315
+ <value name="COND">
316
+ <block type="operators_compare_lt" inline="true">
317
+ <value name="A">
318
+ <block type="motion_self_angle" />
319
+ </value>
320
+ <value name="B">
321
+ <block type="math_number">
322
+ <field name="NUM">90</field>
323
+ </block>
324
+ </value>
325
+ </block>
326
+ </value>
327
+ </block>
328
+ </next>
329
+ </block>
330
+ </next>
331
+ </block>
332
+ </next>
333
+ </block>
334
+ </next>
335
+ </block>
336
+ </next>
337
+ </block>
338
+ </next>
339
+ </block>
340
+ </next>
341
+ </block>
342
+ </statement>
343
+ <next>
344
+ <block type="motion_turn_if_reach_wall">
345
+ <next>
346
+ <block type="motion_turn">
347
+ <next>
348
+ <block type="motion_rotate_right" inline="true">
349
+ <value name="ANGLE">
350
+ <block type="math_number">
351
+ <field name="NUM">15</field>
352
+ </block>
353
+ </value>
354
+ <next>
355
+ <block type="motion_rotate_left" inline="true">
356
+ <value name="ANGLE">
357
+ <block type="math_number">
358
+ <field name="NUM">15</field>
359
+ </block>
360
+ </value>
361
+ <next>
362
+ <block type="motion_set_angle" inline="true">
363
+ <value name="ANGLE">
364
+ <block type="math_number">
365
+ <field name="NUM">90</field>
366
+ </block>
367
+ </value>
368
+ <next>
369
+ <block type="motion_point_towards_mouse">
370
+ <next>
371
+ <block type="motion_point_towards_character">
372
+ <field name="CHAR">car1</field>
373
+ </block>
374
+ </next>
375
+ </block>
376
+ </next>
377
+ </block>
378
+ </next>
379
+ </block>
380
+ </next>
381
+ </block>
382
+ </next>
383
+ </block>
384
+ </next>
385
+ </block>
386
+ </next>
387
+ </block>
388
+ </statement>
389
+ XML
390
+ end
391
+ end
392
+ end