# -*- coding: utf-8 -*-
require 'spec_helper'
require_relative 'shared/block_examples'
# rubocop:disable EmptyLines, LineLength
describe RubyToBlock::Block, '移動・回転ジャンル', to_blocks: true do
parts = <<-EOS
car1.on(:start) do
move(10)
self.position = [0, 0]
self.x += 10
self.x = 0
self.y += 10
self.y = 0
if x < 300
if y < 300
end
end
end
car1.move(10)
car1.position = [0, 0]
car1.x += 10
car1.x = 0
car1.y += 10
car1.y = 0
EOS
describe compact_source_code(parts), character_new_data: true do
_parts = parts
let(:parts) { _parts }
it '結果が正しいこと' do
should eq_block_xml(<<-XML)
car1
10
0
0
10
0
10
0
300
300
10
0
0
10
0
10
0
XML
end
end
parts = <<-EOS
car1.move(10)
car1.position = [0, 0]
car1.x += 10
EOS
describe compact_source_code(parts), character_new_data: true do
_parts = parts
let(:parts) { _parts }
it '結果が正しいこと' do
should eq_block_xml(<<-XML)
car1
10
0
0
10
XML
end
end
parts = <<-EOS
car1.on(:start) do
turn_if_reach_wall
if reach_wall?
turn
end
rotate(15)
rotate(-15)
self.angle = 90
point_towards(:mouse)
point_towards(car1)
if angle < 90
end
end
car1.turn_if_reach_wall
car1.turn
car1.rotate(15)
car1.rotate(-15)
car1.angle = 90
car1.point_towards(:mouse)
car1.point_towards(car1)
EOS
describe compact_source_code(parts), character_new_data: true do
_parts = parts
let(:parts) { _parts }
it '結果が正しいこと' do
should eq_block_xml(<<-XML)
car1
15
15
90
car1
90
15
15
90
car1
XML
end
end
end