From 461a6933c66491d4107d1e4df788ee7ef2b97829 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 23 Feb 2019 18:17:26 +0200 Subject: [PATCH] better tests for class sending still #24 --- lib/vool/variables.rb | 2 +- test/vool/class_send/helper.rb | 44 +++++++++++++++++++ test/vool/class_send/test_class_def.rb | 44 +++++++++++++++++++ test/vool/class_send/test_harness.rb | 13 ++++++ .../{send => class_send}/test_send_class.rb | 5 ++- 5 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 test/vool/class_send/helper.rb create mode 100644 test/vool/class_send/test_class_def.rb create mode 100644 test/vool/class_send/test_harness.rb rename test/vool/{send => class_send}/test_send_class.rb (82%) diff --git a/lib/vool/variables.rb b/lib/vool/variables.rb index cea85af7..3a8e5ceb 100644 --- a/lib/vool/variables.rb +++ b/lib/vool/variables.rb @@ -40,7 +40,7 @@ module Vool class ModuleName < Expression include Named def ct_type - get_named_class.instance_type + get_named_class.meta_class.instance_type end def slot_definition(_) return Mom::SlotDefinition.new( get_named_class, []) diff --git a/test/vool/class_send/helper.rb b/test/vool/class_send/helper.rb new file mode 100644 index 00000000..3775f127 --- /dev/null +++ b/test/vool/class_send/helper.rb @@ -0,0 +1,44 @@ +require_relative "../helper" + +module Vool + # relies on @ins and receiver_type method + + module ClassHarness + include MomCompile + + def setup + Parfait.boot!(Parfait.default_test_options) + Risc::Builtin.boot_functions + @ins = compile_first_method( send_method ) + end + + def test_first_not_array + assert Array != @ins.class , @ins + end + def test_class_compiles + assert_equal Mom::MessageSetup , @ins.class , @ins + end + def test_two_instructions_are_returned + assert_equal 3 , @ins.length , @ins + end + def test_receiver_move_class + assert_equal Mom::ArgumentTransfer, @ins.next(1).class + end + def test_receiver_move + assert_equal Mom::SlotDefinition, @ins.next.receiver.class + end + def test_receiver + assert_equal Parfait::Class, @ins.next.receiver.known_object.class + end + def test_call_is + assert_equal Mom::SimpleCall, @ins.next(2).class + end + def test_call_has_method + assert_equal Parfait::CallableMethod, @ins.next(2).method.class + end + def test_array + check_array [Mom::MessageSetup,Mom::ArgumentTransfer,Mom::SimpleCall] , @ins + end + end + +end diff --git a/test/vool/class_send/test_class_def.rb b/test/vool/class_send/test_class_def.rb new file mode 100644 index 00000000..f75139c0 --- /dev/null +++ b/test/vool/class_send/test_class_def.rb @@ -0,0 +1,44 @@ +require_relative "helper" + +module Vool + class TestClassDef < MiniTest::Test + include Mom + def class_main + <<-eos + class Space + def self.one_plus() + return 1 + 1 + end + def main(arg) + return Space.one_plus + end + end + eos + end + + def setup + statements = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_vool(class_main) + assert_equal Vool::ClassStatement, statements.class + ret = statements.to_mom(nil) + assert_equal Parfait::Class , statements.clazz.class , statements + @method = statements.clazz.get_method(:main) + assert_equal Parfait::VoolMethod , @method.class + assert_equal Mom::MomCompiler , ret.class + compiler = ret.method_compilers.find{|c| c.get_method.name == :main } + assert_equal Risc::MethodCompiler , compiler.class + @ins = @method.source.to_mom( compiler ) + end + + def test_any + assert_equal Mom::MessageSetup , @ins.class + end + + def test_no_arg + assert_equal Mom::ArgumentTransfer, @ins.next(1).class + assert_equal 0, @ins.next(1).arguments.length + end + def test_call_two + assert_equal SimpleCall, @ins.next(2).class + end + end +end diff --git a/test/vool/class_send/test_harness.rb b/test/vool/class_send/test_harness.rb new file mode 100644 index 00000000..d12f52c7 --- /dev/null +++ b/test/vool/class_send/test_harness.rb @@ -0,0 +1,13 @@ +require_relative "helper" + +module Vool + class ClassSendHarness < MiniTest::Test + include MomCompile + include ClassHarness + + def send_method + "Object.get_internal_word(0)" + end + + end +end diff --git a/test/vool/send/test_send_class.rb b/test/vool/class_send/test_send_class.rb similarity index 82% rename from test/vool/send/test_send_class.rb rename to test/vool/class_send/test_send_class.rb index 7fabfd20..fef6aa62 100644 --- a/test/vool/send/test_send_class.rb +++ b/test/vool/class_send/test_send_class.rb @@ -2,14 +2,17 @@ require_relative "helper" module Vool class TestSendClassMom < MiniTest::Test - include SimpleSendHarness + include ClassHarness include Mom def send_method "Object.get_internal_word(0)" end + def test_receiver assert_equal SlotDefinition, @ins.next.receiver.class + assert_equal Parfait::Class, @ins.next.receiver.known_object.class + assert_equal :Object , @ins.next.receiver.known_object.name end def test_arg_one assert_equal SlotLoad, @ins.next(1).arguments[0].class