smalruby-editor 0.1.6-x86-mingw32 → 0.1.7-x86-mingw32

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 (98) 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/block/base.rb +251 -0
  6. data/app/models/concerns/ruby_to_block/block/character.rb +42 -0
  7. data/app/models/concerns/ruby_to_block/block/character_event.rb +27 -0
  8. data/app/models/concerns/ruby_to_block/block/character_method_call.rb +29 -0
  9. data/app/models/concerns/ruby_to_block/block/character_new.rb +7 -0
  10. data/app/models/concerns/ruby_to_block/block/character_operation.rb +80 -0
  11. data/app/models/concerns/ruby_to_block/block/control_if.rb +45 -0
  12. data/app/models/concerns/ruby_to_block/block/control_loop.rb +19 -0
  13. data/app/models/concerns/ruby_to_block/block/control_sleep.rb +18 -0
  14. data/app/models/concerns/ruby_to_block/block/do.rb +24 -0
  15. data/app/models/concerns/ruby_to_block/block/else.rb +12 -0
  16. data/app/models/concerns/ruby_to_block/block/end.rb +26 -0
  17. data/app/models/concerns/ruby_to_block/block/events_on_click.rb +14 -0
  18. data/app/models/concerns/ruby_to_block/block/events_on_key_push_or_down.rb +17 -0
  19. data/app/models/concerns/ruby_to_block/block/events_on_start.rb +14 -0
  20. data/app/models/concerns/ruby_to_block/block/hardware_init_hardware.rb +14 -0
  21. data/app/models/concerns/ruby_to_block/block/hardware_led_off.rb +16 -0
  22. data/app/models/concerns/ruby_to_block/block/hardware_led_on.rb +16 -0
  23. data/app/models/concerns/ruby_to_block/block/hardware_on_sensor_change.rb +17 -0
  24. data/app/models/concerns/ruby_to_block/block/hardware_rgb_led_off.rb +18 -0
  25. data/app/models/concerns/ruby_to_block/block/hardware_rgb_led_on.rb +23 -0
  26. data/app/models/concerns/ruby_to_block/block/hardware_sensor_value.rb +23 -0
  27. data/app/models/concerns/ruby_to_block/block/hardware_two_wheel_drive_car.rb +26 -0
  28. data/app/models/concerns/ruby_to_block/block/looks_hide.rb +8 -0
  29. data/app/models/concerns/ruby_to_block/block/looks_say.rb +20 -0
  30. data/app/models/concerns/ruby_to_block/block/looks_show.rb +8 -0
  31. data/app/models/concerns/ruby_to_block/block/looks_vanish.rb +8 -0
  32. data/app/models/concerns/ruby_to_block/block/math_number.rb +14 -0
  33. data/app/models/concerns/ruby_to_block/block/motion_change_x_by.rb +20 -0
  34. data/app/models/concerns/ruby_to_block/block/motion_change_y_by.rb +20 -0
  35. data/app/models/concerns/ruby_to_block/block/motion_move.rb +15 -0
  36. data/app/models/concerns/ruby_to_block/block/motion_point_towards_character.rb +24 -0
  37. data/app/models/concerns/ruby_to_block/block/motion_point_towards_mouse.rb +9 -0
  38. data/app/models/concerns/ruby_to_block/block/motion_reach_wall.rb +24 -0
  39. data/app/models/concerns/ruby_to_block/block/motion_rotate_left.rb +20 -0
  40. data/app/models/concerns/ruby_to_block/block/motion_rotate_right.rb +20 -0
  41. data/app/models/concerns/ruby_to_block/block/motion_self_angle.rb +23 -0
  42. data/app/models/concerns/ruby_to_block/block/motion_self_x.rb +23 -0
  43. data/app/models/concerns/ruby_to_block/block/motion_self_y.rb +23 -0
  44. data/app/models/concerns/ruby_to_block/block/motion_set_angle.rb +15 -0
  45. data/app/models/concerns/ruby_to_block/block/motion_set_x.rb +38 -0
  46. data/app/models/concerns/ruby_to_block/block/motion_set_y.rb +15 -0
  47. data/app/models/concerns/ruby_to_block/block/motion_turn.rb +8 -0
  48. data/app/models/concerns/ruby_to_block/block/motion_turn_if_reach_wall.rb +8 -0
  49. data/app/models/concerns/ruby_to_block/block/null.rb +17 -0
  50. data/app/models/concerns/ruby_to_block/block/operators_compare.rb +36 -0
  51. data/app/models/concerns/ruby_to_block/block/operators_false.rb +8 -0
  52. data/app/models/concerns/ruby_to_block/block/operators_true.rb +8 -0
  53. data/app/models/concerns/ruby_to_block/block/require_smalruby.rb +7 -0
  54. data/app/models/concerns/ruby_to_block/block/ruby_comment.rb +16 -0
  55. data/app/models/concerns/ruby_to_block/block/ruby_expression.rb +14 -0
  56. data/app/models/concerns/ruby_to_block/block/ruby_statement.rb +23 -0
  57. data/app/models/concerns/ruby_to_block/block/sensing_hit.rb +23 -0
  58. data/app/models/concerns/ruby_to_block/block/sound_play.rb +15 -0
  59. data/app/models/concerns/ruby_to_block/block/sound_preset_sounds.rb +31 -0
  60. data/app/models/concerns/ruby_to_block/block/text.rb +15 -0
  61. data/app/models/concerns/ruby_to_block/block/value.rb +12 -0
  62. data/app/models/concerns/ruby_to_block/block.rb +97 -0
  63. data/app/models/concerns/ruby_to_block/context.rb +97 -0
  64. data/app/models/concerns/ruby_to_block/formatter.rb +26 -0
  65. data/app/models/concerns/ruby_to_block.rb +17 -360
  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/public/assets/{application-64a390efe879c386a5950515064f062d.css → application-28b7bed56c5389dfa372e972c75b6676.css} +17 -10
  70. data/public/assets/application-28b7bed56c5389dfa372e972c75b6676.css.gz +0 -0
  71. data/public/assets/{application-8bfffad1222d4e198f3c7ccc1cbd774f.js → application-4f747690ebc8ec4815ae36021fdb2c44.js} +135 -0
  72. data/public/assets/{application-8bfffad1222d4e198f3c7ccc1cbd774f.js.gz → application-4f747690ebc8ec4815ae36021fdb2c44.js.gz} +0 -0
  73. data/public/assets/manifest-332a5a1668194028b55103e0ea45c054.json +1 -1
  74. data/smalruby-editor.gemspec +1 -1
  75. data/spec/acceptance/block_mode/blocks/hardware/two_wheel_drive_car.feature +69 -0
  76. data/spec/acceptance/ruby_mode/translate.feature +1 -1
  77. data/spec/controllers/source_codes_controller_spec.rb +14 -11
  78. data/spec/models/concerns/ruby_to_block/block/character_method_call_spec.rb +175 -0
  79. data/spec/models/concerns/ruby_to_block/block/control_if_spec.rb +75 -0
  80. data/spec/models/concerns/ruby_to_block/block/control_loop_spec.rb +68 -0
  81. data/spec/models/concerns/ruby_to_block/block/events_on_start_spec.rb +120 -0
  82. data/spec/models/concerns/ruby_to_block/block/hardware_spec.rb +120 -0
  83. data/spec/models/concerns/ruby_to_block/block/looks_say_spec.rb +79 -0
  84. data/spec/models/concerns/ruby_to_block/block/looks_spec.rb +74 -0
  85. data/spec/models/concerns/ruby_to_block/block/motion_move_spec.rb +63 -0
  86. data/spec/models/concerns/ruby_to_block/block/motion_reach_wall_spec.rb +67 -0
  87. data/spec/models/concerns/ruby_to_block/block/motion_spec.rb +392 -0
  88. data/spec/models/concerns/ruby_to_block/block/motion_turn_spec.rb +54 -0
  89. data/spec/models/concerns/ruby_to_block/block/require_smalruby_spec.rb +39 -0
  90. data/spec/models/concerns/ruby_to_block/block/ruby_comment_spec.rb +55 -0
  91. data/spec/models/concerns/ruby_to_block/block/ruby_statement_spec.rb +113 -0
  92. data/spec/models/concerns/ruby_to_block/block/shared/block_examples.rb +44 -0
  93. data/spec/models/concerns/ruby_to_block/block/sound_spec.rb +46 -0
  94. data/spec/models/concerns/ruby_to_block/block_spec.rb +49 -0
  95. data/spec/models/concerns/ruby_to_block_spec.rb +421 -217
  96. data/spec/support/ruby_to_block.rb +10 -0
  97. metadata +108 -10
  98. data/public/assets/application-64a390efe879c386a5950515064f062d.css.gz +0 -0
@@ -68,7 +68,7 @@ Gem::Specification.new do |spec|
68
68
  ['launchy'],
69
69
  ['mime-types', '~> 1.16'],
70
70
  ['haml-rails'],
71
- ['smalruby'],
71
+ ['smalruby', '~> 0.0.15'],
72
72
  ]
73
73
  runtime_dependencies << ['therubyracer'] unless is_windows
74
74
  runtime_dependencies.each do |args|
@@ -0,0 +1,69 @@
1
+ # encoding: utf-8
2
+ # language: ja
3
+ @javascript
4
+ 機能: hardware_two_wheel_drive_car_{forward,backward,turn_left,turn_right,stop} - 「2WD車[▼ピン]を{進める,バックさせる,左に曲げる,右に曲げる,止める}」ブロック
5
+ 背景:
6
+ 前提 "ブロック" タブを表示する
7
+ かつ 次のキャラクターを追加する:
8
+ | name | costumes | x | y | angle |
9
+ | car1 | car1.png | 0 | 0 | 0 |
10
+
11
+ シナリオテンプレート: ブロックのみ、キャラクターとブロック、キャラクターとイベントとブロックをそれぞれ配置する
12
+ # ブロックのみ配置する
13
+ もし 次のブロック("hardware_two_wheel_drive_car_<ブロック名のサフィックス>")を配置する:
14
+ """
15
+ %block{:type => "hardware_two_wheel_drive_car_<ブロック名のサフィックス>", :x => "0", :y => "0"}
16
+ %field{:name => "PIN"}<
17
+ D2
18
+ """
19
+ かつ ブロックからソースコードを生成する
20
+
21
+ ならば テキストエディタのプログラムは "" であること
22
+
23
+ # キャラクターとブロックを配置する
24
+ もし 次のブロック("hardware_two_wheel_drive_car_<ブロック名のサフィックス>")を配置する:
25
+ """
26
+ %block{:type => "character_new", :x => "21", :y => "15"}
27
+ %field{:name => "NAME"}<
28
+ car1
29
+ %statement{:name => "DO"}
30
+ %block{:type => "hardware_two_wheel_drive_car_<ブロック名のサフィックス>", :x => "0", :y => "0"}
31
+ %field{:name => "PIN"}<
32
+ D2
33
+ """
34
+ かつ ブロックからソースコードを生成する
35
+
36
+ ならば テキストエディタのプログラムは以下を含むこと:
37
+ """
38
+ car1.two_wheel_drive_car("D2").<ブロック名のサフィックス>
39
+ """
40
+
41
+ # キャラクターとイベントとブロックを配置する
42
+ もし 次のブロック("hardware_two_wheel_drive_car_<ブロック名のサフィックス>")を配置する:
43
+ """
44
+ %block{:type => "character_new", :x => "21", :y => "15"}
45
+ %field{:name => "NAME"}<
46
+ car1
47
+ %statement{:name => "DO"}
48
+ %block{:type => "events_on_start"}
49
+ %statement{:name => "DO"}
50
+ %block{:type => "hardware_two_wheel_drive_car_<ブロック名のサフィックス>", :x => "0", :y => "0"}
51
+ %field{:name => "PIN"}<
52
+ D2
53
+ """
54
+ かつ ブロックからソースコードを生成する
55
+
56
+ ならば テキストエディタのプログラムは以下を含むこと:
57
+ """
58
+ car1.on(:start) do
59
+ two_wheel_drive_car("D2").<ブロック名のサフィックス>
60
+ end
61
+ """
62
+
63
+ 例:
64
+ | ブロック名のサフィックス |
65
+ | forward |
66
+ | backward |
67
+ | turn_left |
68
+ | turn_right |
69
+ | stop |
@@ -29,7 +29,7 @@
29
29
  """
30
30
  <xml>
31
31
  <character x="0" y="0" name="car1" costumes="car1.png" angle="0"></character>
32
- <block type="character_new" x="4" y="4">
32
+ <block type="character_new" x="0" y="0">
33
33
  <field name="NAME">car1</field>
34
34
  <statement name="DO">
35
35
  <block type="events_on_start">
@@ -468,24 +468,27 @@ describe SourceCodesController do
468
468
  end
469
469
 
470
470
  describe 'プログラムをXML形式のブロックに変換する (POST to_blocks)' do
471
+ let(:data) { 'data' }
472
+
471
473
  before do
474
+ allow_any_instance_of(SourceCode).to receive(:to_blocks) {
475
+ fail if data == '__FAIL__'
476
+ 'success'
477
+ }
478
+
472
479
  post :to_blocks, source_code: { data: data }
473
480
  end
474
481
 
475
- describe '動作確認用のモックアップ' do
476
- context '成功する場合' do
477
- let(:data) { SourceCode::SUCCESS_DATA_MOCK }
478
-
479
- it 'XML形式のブロックを返すこと' do
480
- expect(response.body).to eq(SourceCode::SUCCESS_XML_MOCK)
481
- end
482
+ context '成功する場合' do
483
+ it 'SourceCode#to_blocksの結果をそのまま返すこと' do
484
+ expect(response.body).to eq('success')
482
485
  end
486
+ end
483
487
 
484
- context '失敗する場合' do
485
- let(:data) { '__FAIL__' }
488
+ context '失敗する場合' do
489
+ let(:data) { '__FAIL__' }
486
490
 
487
- it { expect(response.status).to eq(400) }
488
- end
491
+ it { expect(response.status).to eq(400) }
489
492
  end
490
493
  end
491
494
  end
@@ -0,0 +1,175 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require_relative 'shared/block_examples'
4
+
5
+ # ここではCharacterMethodCallのexamplesとしてlooks_sayブロックを利用
6
+ # します。そのかわりlooks_sayのようにCharacterMethodCallを継承したブ
7
+ # ロックでは最低限のexamplesしか実装しません。
8
+
9
+ # rubocop:disable EmptyLines, LineLength
10
+
11
+ describe RubyToBlock::Block::CharacterMethodCall, to_blocks: true do
12
+ parts = <<-EOS
13
+ say(message: "こんにちは")
14
+ EOS
15
+ describe compact_source_code(parts), on_start_data: true do
16
+ _parts = parts
17
+ let(:parts) { _parts }
18
+
19
+ it '結果が正しいこと' do
20
+ should eq_block_xml(<<-XML)
21
+ <block type="looks_say" inline="true">
22
+ <value name="TEXT">
23
+ <block type="text">
24
+ <field name="TEXT">こんにちは</field>
25
+ </block>
26
+ </value>
27
+ </block>
28
+ XML
29
+ end
30
+ end
31
+
32
+ parts = <<-EOS
33
+ self.say(message: "こんにちは")
34
+ EOS
35
+ describe compact_source_code(parts), on_start_data: true do
36
+ _parts = parts
37
+ let(:parts) { _parts }
38
+
39
+ it '結果が正しいこと' do
40
+ should eq_block_xml(<<-XML)
41
+ <block type="looks_say" inline="true">
42
+ <value name="TEXT">
43
+ <block type="text">
44
+ <field name="TEXT">こんにちは</field>
45
+ </block>
46
+ </value>
47
+ </block>
48
+ XML
49
+ end
50
+ end
51
+
52
+ parts = <<-EOS
53
+ say(message: "こんにちは")
54
+ puts "Hello, World!"
55
+ EOS
56
+ describe compact_source_code(parts), on_start_data: true do
57
+ _parts = parts
58
+ let(:parts) { _parts }
59
+
60
+ it '結果が正しいこと' do
61
+ should eq_block_xml(<<-XML)
62
+ <block type="looks_say" inline="true">
63
+ <value name="TEXT">
64
+ <block type="text">
65
+ <field name="TEXT">こんにちは</field>
66
+ </block>
67
+ </value>
68
+ <next>
69
+ <block type="ruby_statement">
70
+ <field name="STATEMENT">puts &quot;Hello, World!&quot;</field>
71
+ </block>
72
+ </next>
73
+ </block>
74
+ XML
75
+ end
76
+ end
77
+
78
+ parts = <<-EOS
79
+ car1.say(message: "こんにちは")
80
+ EOS
81
+ describe compact_source_code(parts), character_new_data: true do
82
+ _parts = parts
83
+ let(:parts) { _parts }
84
+
85
+ it '結果が正しいこと' do
86
+ should eq_block_xml(<<-XML)
87
+ <block type="looks_say" inline="true">
88
+ <value name="TEXT">
89
+ <block type="text">
90
+ <field name="TEXT">こんにちは</field>
91
+ </block>
92
+ </value>
93
+ </block>
94
+ XML
95
+ end
96
+ end
97
+
98
+ parts = <<-EOS
99
+ car1.say(message: "こんにちは")
100
+ car1.say(message: "こんにちは")
101
+ EOS
102
+ describe compact_source_code(parts), character_new_data: true do
103
+ _parts = parts
104
+ let(:parts) { _parts }
105
+
106
+ it '結果が正しいこと' do
107
+ should eq_block_xml(<<-XML)
108
+ <block type="looks_say" inline="true">
109
+ <value name="TEXT">
110
+ <block type="text">
111
+ <field name="TEXT">こんにちは</field>
112
+ </block>
113
+ </value>
114
+ <next>
115
+ <block type="looks_say" inline="true">
116
+ <value name="TEXT">
117
+ <block type="text">
118
+ <field name="TEXT">こんにちは</field>
119
+ </block>
120
+ </value>
121
+ </block>
122
+ </next>
123
+ </block>
124
+ XML
125
+ end
126
+ end
127
+
128
+ parts = <<-EOS
129
+ car1.say(message: "こんにちは")
130
+ unknown.say(message: "こんにちは")
131
+ say(message: "こんにちは")
132
+ EOS
133
+ describe compact_source_code(parts), character_new_data: true do
134
+ _parts = parts
135
+ let(:parts) { _parts }
136
+
137
+ it '結果が正しいこと' do
138
+ should eq_block_xml(<<-XML)
139
+ <block type="looks_say" inline="true">
140
+ <value name="TEXT">
141
+ <block type="text">
142
+ <field name="TEXT">こんにちは</field>
143
+ </block>
144
+ </value>
145
+ <next>
146
+ <block type="ruby_statement">
147
+ <field name="STATEMENT">unknown.say(message: &quot;こんにちは&quot;)</field>
148
+ <next>
149
+ <block type="ruby_statement">
150
+ <field name="STATEMENT">say(message: &quot;こんにちは&quot;)</field>
151
+ </block>
152
+ </next>
153
+ </block>
154
+ </next>
155
+ </block>
156
+ XML
157
+ end
158
+ end
159
+
160
+ _data = <<-EOS
161
+ say(message: "こんにちは")
162
+ EOS
163
+ describe compact_source_code(_data) do
164
+ __data = _data
165
+ let(:data) { __data }
166
+
167
+ it '結果が正しいこと' do
168
+ should eq_block_xml(<<-XML)
169
+ <block type="ruby_statement">
170
+ <field name="STATEMENT">say(message: &quot;こんにちは&quot;)</field>
171
+ </block>
172
+ XML
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,75 @@
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::ControlIf,
8
+ RubyToBlock::Block::OperatorsTrue,
9
+ RubyToBlock::Block::OperatorsFalse,
10
+ to_blocks: true do
11
+ _data = <<-EOS
12
+ if true
13
+
14
+ end
15
+ EOS
16
+ describe compact_source_code(_data) do
17
+ __data = _data
18
+ let(:data) { __data }
19
+
20
+ it '結果が正しいこと' do
21
+ should eq_block_xml(<<-XML)
22
+ <block type="control_if" inline="true">
23
+ <value name="COND">
24
+ <block type="operators_true" />
25
+ </value>
26
+ </block>
27
+ XML
28
+ end
29
+ end
30
+
31
+ _data = <<-EOS
32
+ if false
33
+
34
+ end
35
+ EOS
36
+ describe compact_source_code(_data) do
37
+ __data = _data
38
+ let(:data) { __data }
39
+
40
+ it '結果が正しいこと' do
41
+ should eq_block_xml(<<-XML)
42
+ <block type="control_if" inline="true">
43
+ <value name="COND">
44
+ <block type="operators_false" />
45
+ </value>
46
+ </block>
47
+ XML
48
+ end
49
+ end
50
+
51
+ _data = <<-EOS
52
+ if true
53
+ puts "Hello, World!"
54
+ end
55
+ EOS
56
+ describe compact_source_code(_data) do
57
+ __data = _data
58
+ let(:data) { __data }
59
+
60
+ it '結果が正しいこと' do
61
+ should eq_block_xml(<<-XML)
62
+ <block type="control_if" inline="true">
63
+ <value name="COND">
64
+ <block type="operators_true" />
65
+ </value>
66
+ <statement name="THEN">
67
+ <block type="ruby_statement">
68
+ <field name="STATEMENT">puts &quot;Hello, World!&quot;</field>
69
+ </block>
70
+ </statement>
71
+ </block>
72
+ XML
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,68 @@
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::ControlLoop, to_blocks: true do
8
+ parts = <<-EOS
9
+ loop do
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_loop" />
20
+ XML
21
+ end
22
+ end
23
+
24
+ parts = <<-EOS
25
+ loop do
26
+ puts "Hello, World!"
27
+ end
28
+ EOS
29
+ describe compact_source_code(parts), on_start_data: true do
30
+ _parts = parts
31
+ let(:parts) { _parts }
32
+
33
+ it '結果が正しいこと' do
34
+ should eq_block_xml(<<-XML)
35
+ <block type="control_loop">
36
+ <statement name="DO">
37
+ <block type="ruby_statement">
38
+ <field name="STATEMENT">puts &quot;Hello, World!&quot;</field>
39
+ </block>
40
+ </statement>
41
+ </block>
42
+ XML
43
+ end
44
+ end
45
+
46
+ _data = <<-EOS
47
+ loop do
48
+
49
+ end
50
+ EOS
51
+ describe compact_source_code(_data) do
52
+ __data = _data
53
+ let(:data) { __data }
54
+
55
+ it '結果が正しいこと' do
56
+ should eq_block_xml(<<-XML)
57
+ <block type="ruby_statement">
58
+ <field name="STATEMENT">loop do</field>
59
+ <next>
60
+ <block type="ruby_statement">
61
+ <field name="STATEMENT">end</field>
62
+ </block>
63
+ </next>
64
+ </block>
65
+ XML
66
+ end
67
+ end
68
+ end
@@ -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::EventsOnStart, to_blocks: true do
8
+ parts = <<-EOS
9
+ car1.on(:start) do
10
+
11
+ end
12
+ EOS
13
+ describe compact_source_code(parts), character_new_data: true do
14
+ _parts = parts
15
+ let(:parts) { _parts }
16
+
17
+ it '結果が正しいこと' do
18
+ should eq_block_xml(<<-XML)
19
+ <block type="events_on_start" />
20
+ XML
21
+ end
22
+ end
23
+
24
+ parts = <<-EOS
25
+ cat1 = Character.new(costume: "cat1.png", x: 200, y: 150, angle: 90)
26
+
27
+ car1.on(:start) do
28
+
29
+ end
30
+
31
+ car1.on(:start) do
32
+
33
+ end
34
+
35
+
36
+ cat1.on(:start) do
37
+
38
+ end
39
+ EOS
40
+ describe compact_source_code(parts), character_new_data: true do
41
+ _parts = parts
42
+ let(:parts) { _parts }
43
+
44
+ it '結果が正しいこと' do
45
+ should eq_block_xml(<<-XML)
46
+ <character name="car1" x="0" y="0" angle="0" costumes="car1.png" />
47
+ <character name="cat1" x="200" y="150" angle="90" costumes="cat1.png" />
48
+ <block type="character_new">
49
+ <field name="NAME">car1</field>
50
+ <statement name="DO">
51
+ <block type="events_on_start">
52
+ <next>
53
+ <block type="events_on_start" />
54
+ </next>
55
+ </block>
56
+ </statement>
57
+ </block>
58
+ <block type="character_new">
59
+ <field name="NAME">cat1</field>
60
+ <statement name="DO">
61
+ <block type="events_on_start" />
62
+ </statement>
63
+ </block>
64
+ XML
65
+ end
66
+ end
67
+
68
+ parts = <<-EOS
69
+ cat1 = Character.new(costume: "cat1.png", x: 200, y: 150, angle: 90)
70
+
71
+ car1.on(:start) do
72
+
73
+ cat1.on(:start) do
74
+
75
+ end
76
+ end
77
+ EOS
78
+ describe compact_source_code(parts), character_new_data: true do
79
+ _parts = parts
80
+ let(:parts) { _parts }
81
+
82
+ it '結果が正しいこと' do
83
+ should eq_block_xml(<<-XML)
84
+ <character name="car1" x="0" y="0" angle="0" costumes="car1.png" />
85
+ <character name="cat1" x="200" y="150" angle="90" costumes="cat1.png" />
86
+ <block type="character_new">
87
+ <field name="NAME">car1</field>
88
+ <statement name="DO">
89
+ <block type="events_on_start">
90
+ <statement name="DO">
91
+ <block type="character_new">
92
+ <field name="NAME">cat1</field>
93
+ <statement name="DO">
94
+ <block type="events_on_start" />
95
+ </statement>
96
+ </block>
97
+ </statement>
98
+ </block>
99
+ </statement>
100
+ </block>
101
+ XML
102
+ end
103
+ end
104
+
105
+ parts = <<-EOS
106
+ on(:start) do
107
+
108
+ end
109
+ EOS
110
+ describe compact_source_code(parts), on_start_data: true do
111
+ _parts = parts
112
+ let(:parts) { _parts }
113
+
114
+ it '結果が正しいこと' do
115
+ should eq_block_xml(<<-XML)
116
+ <block type="events_on_start" />
117
+ XML
118
+ end
119
+ end
120
+ end
@@ -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