macro tests for all object mom instructions

This commit is contained in:
2019-09-11 18:43:20 +03:00
parent 2c4f040654
commit f264aec94a
9 changed files with 200 additions and 12 deletions

View File

@ -1 +1,16 @@
require_relative "../helper"
module RubyX
module BuiltinHelper
def setup
@mom = RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(source)
@mom.method_compilers.first
assert_equal Mom::MomCollection , @mom.class
assert_equal Mom::MethodCompiler , compiler.class
end
def compiler
@mom.method_compilers.last
end
end
end

View File

@ -0,0 +1,35 @@
require_relative "helper"
module RubyX
module Builtin
class TestObjectExit < MiniTest::Test
include BuiltinHelper
def source
<<GET
class Space
def main(arg)
return
end
end
class Object
def exit(at)
X.exit
end
end
GET
end
def test_mom_meth
assert_equal :exit , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_get
assert_equal Mom::Exit , compiler.mom_instructions.next.class
end
def test_risc
assert_equal 40 , compiler.to_risc.risc_instructions.length
end
end
end
end

View File

@ -1,25 +1,17 @@
require_relative "helper"
module RubyX
module Builtin
class TestObjectGet < MiniTest::Test
def setup
get = <<GET
include BuiltinHelper
def source
<<GET
class Object
def get_internal_word(at)
X.get_internal_word
end
end
GET
@mom = RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(get)
end
def compiler
@mom.method_compilers.first
end
def test_mom_col
assert_equal Mom::MomCollection , @mom.class
end
def test_mom_com
assert_equal Mom::MethodCompiler , @mom.method_compilers.first.class
end
def test_mom_meth
assert_equal :get_internal_word , compiler.callable.name

View File

@ -0,0 +1,35 @@
require_relative "helper"
module RubyX
module Builtin
class TestObjectInit < MiniTest::Test
include BuiltinHelper
def source
<<GET
class Space
def main(arg)
return
end
end
class Object
def __init(at)
X.__init
end
end
GET
end
def test_mom_meth
assert_equal :__init , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_get
assert_equal Mom::Init , compiler.mom_instructions.next.class
end
def test_risc
assert_equal 31 , compiler.to_risc.risc_instructions.length
end
end
end
end

View File

@ -0,0 +1,35 @@
require_relative "helper"
module RubyX
module Builtin
class TestObjectMissing < MiniTest::Test
include BuiltinHelper
def source
<<GET
class Space
def main(arg)
return
end
end
class Object
def method_missing(at)
X.method_missing
end
end
GET
end
def test_mom_meth
assert_equal :method_missing , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_get
assert_equal Mom::MethodMissing , compiler.mom_instructions.next.class
end
def test_risc
assert_equal 42 , compiler.to_risc.risc_instructions.length
end
end
end
end

View File

@ -0,0 +1,30 @@
require_relative "helper"
module RubyX
module Builtin
class TestObjectGet < MiniTest::Test
include BuiltinHelper
def source
<<GET
class Object
def set_internal_word(at , value)
X.set_internal_word
end
end
GET
end
def test_mom_meth
assert_equal :set_internal_word , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_get
assert_equal Mom::SetInternalWord , compiler.mom_instructions.next.class
end
def test_risc
assert_equal 19 , compiler.to_risc.risc_instructions.length
end
end
end
end