tests for word macros

This commit is contained in:
2019-09-11 18:53:20 +03:00
parent f264aec94a
commit e8bfb9a58c
10 changed files with 148 additions and 13 deletions

View File

@ -3,7 +3,8 @@ require_relative "../helper"
module RubyX
module BuiltinHelper
def setup
@mom = RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(source)
whole ="class Space;def main(arg);return;end;end;" + source
@mom = RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(whole)
@mom.method_compilers.first
assert_equal Mom::MomCollection , @mom.class
assert_equal Mom::MethodCompiler , compiler.class

View File

@ -6,11 +6,6 @@ module RubyX
include BuiltinHelper
def source
<<GET
class Space
def main(arg)
return
end
end
class Object
def exit(at)
X.exit

View File

@ -6,11 +6,6 @@ module RubyX
include BuiltinHelper
def source
<<GET
class Space
def main(arg)
return
end
end
class Object
def __init(at)
X.__init

View File

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

View File

@ -0,0 +1,30 @@
require_relative "helper"
module RubyX
module Builtin
class TestWordPutstring < MiniTest::Test
include BuiltinHelper
def source
<<GET
class Word
def putstring
X.putstring
end
end
GET
end
def test_mom_meth
assert_equal :putstring , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_get
assert_equal Mom::Putstring , compiler.mom_instructions.next.class
end
def test_risc
assert_equal 44 , compiler.to_risc.risc_instructions.length
end
end
end
end

View File

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