2018-03-29 17:17:19 +02:00
|
|
|
require_relative "../helper"
|
|
|
|
|
|
|
|
module Risc
|
2018-07-02 16:01:07 +02:00
|
|
|
class TestTextWriter < MiniTest::Test
|
2018-03-29 17:17:19 +02:00
|
|
|
|
|
|
|
def setup
|
2019-02-08 22:03:23 +01:00
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
2018-07-02 16:01:07 +02:00
|
|
|
Risc.boot!
|
|
|
|
@linker = Mom::MomCompiler.new.translate(:arm)
|
2018-03-29 17:17:19 +02:00
|
|
|
end
|
|
|
|
def test_init
|
2018-07-02 16:01:07 +02:00
|
|
|
@text_writer = TextWriter.new(@linker)
|
2018-03-29 17:17:19 +02:00
|
|
|
end
|
|
|
|
def test_write_fails
|
2018-07-02 16:01:07 +02:00
|
|
|
@text_writer = TextWriter.new(@linker)
|
2018-03-29 17:17:19 +02:00
|
|
|
assert_raises{ @text_writer.write_as_string} #must translate first
|
|
|
|
end
|
2018-05-13 14:28:10 +02:00
|
|
|
end
|
|
|
|
class TestTextWriterPositions < MiniTest::Test
|
|
|
|
|
|
|
|
def setup
|
2019-02-08 22:03:23 +01:00
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
2018-07-02 16:01:07 +02:00
|
|
|
Risc.boot!
|
|
|
|
@linker = Mom::MomCompiler.new.translate(:arm)
|
|
|
|
@linker.position_all
|
|
|
|
@linker.create_binary
|
|
|
|
@text_writer = TextWriter.new(@linker)
|
2018-05-13 14:28:10 +02:00
|
|
|
end
|
|
|
|
def test_write_all
|
2018-03-29 17:17:19 +02:00
|
|
|
assert @text_writer.write_as_string
|
|
|
|
end
|
2018-05-13 14:28:10 +02:00
|
|
|
def test_sorted_class
|
|
|
|
assert_equal Array , @text_writer.sorted_objects.class
|
|
|
|
end
|
|
|
|
def test_sorted_positions1
|
|
|
|
sorted_objects = @text_writer.sorted_objects
|
2018-08-06 13:07:17 +02:00
|
|
|
check_positions(sorted_objects)
|
2018-05-13 14:28:10 +02:00
|
|
|
end
|
|
|
|
def test_sorted_positions2
|
|
|
|
sorted_objects = @text_writer.sorted_objects
|
|
|
|
sorted_objects.shift
|
2018-08-06 13:07:17 +02:00
|
|
|
check_positions(sorted_objects)
|
|
|
|
end
|
|
|
|
def check_positions(objects)
|
|
|
|
objects.each_slice(2) do |l,r|
|
2018-05-13 14:28:10 +02:00
|
|
|
next unless r
|
2018-06-16 09:58:54 +02:00
|
|
|
next if l.is_a?(Label) or r.is_a?(Label)
|
2018-08-06 13:07:17 +02:00
|
|
|
#assert Position.get(l).at < Position.get(r).at , "#{Position.get(l)} < #{Position.get(r)} , #{l.object_id.to_s(16)}, #{r.object_id.to_s(16)}, #{l.class}, #{r.class}"
|
2018-05-13 14:28:10 +02:00
|
|
|
end
|
|
|
|
end
|
2018-03-29 17:17:19 +02:00
|
|
|
end
|
|
|
|
end
|