Extracting the mom instruction from builtin modules
Since they were embedded at first (easier copy/paste) they now got own files, like their brethren also mini tests for each instruction , nice start
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
# Builtin Testing
|
||||
|
||||
Mostly testing that
|
||||
At the Module level (word/object/integer) mostly testing that
|
||||
- functions exist
|
||||
- they compile
|
||||
- basic length tests (no "contents")
|
||||
|
||||
Minimal tests for risc compilation, and again length only (should be array too)
|
||||
|
||||
Functionality is tested by interpreter over in interpreter dir
|
||||
|
30
test/mom/builtin/test_comparison.rb
Normal file
30
test/mom/builtin/test_comparison.rb
Normal file
@ -0,0 +1,30 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestIntComp1Risc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_compiler(:<)
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 28 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestIntComp2Risc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_compiler(:>=)
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 27 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
18
test/mom/builtin/test_div10.rb
Normal file
18
test/mom/builtin/test_div10.rb
Normal file
@ -0,0 +1,18 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestIntDiv10Risc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_compiler(:div10)
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 76 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
18
test/mom/builtin/test_div4.rb
Normal file
18
test/mom/builtin/test_div4.rb
Normal file
@ -0,0 +1,18 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestIntDiv4Risc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_compiler(:div4)
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 47 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
18
test/mom/builtin/test_exit.rb
Normal file
18
test/mom/builtin/test_exit.rb
Normal file
@ -0,0 +1,18 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestObjectExitRisc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_compiler(:exit)
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 46 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
18
test/mom/builtin/test_get_internal_byte.rb
Normal file
18
test/mom/builtin/test_get_internal_byte.rb
Normal file
@ -0,0 +1,18 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestWordGetRisc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_compiler(:get_internal_byte)
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 48 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
18
test/mom/builtin/test_get_internal_word.rb
Normal file
18
test/mom/builtin/test_get_internal_word.rb
Normal file
@ -0,0 +1,18 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestWordGetRisc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_compiler(:get_internal_byte)
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 48 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
18
test/mom/builtin/test_init.rb
Normal file
18
test/mom/builtin/test_init.rb
Normal file
@ -0,0 +1,18 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestObjectInitRisc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_compiler(:__init__)
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 48 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -13,12 +13,6 @@ module Mom
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 47 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestIntDiv10 < BootTest
|
||||
def setup
|
||||
@ -31,12 +25,6 @@ module Mom
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 76 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestIntComp1 < BootTest
|
||||
def setup
|
||||
@ -49,12 +37,6 @@ module Mom
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 28 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestIntComp2 < BootTest
|
||||
def setup
|
||||
@ -67,12 +49,6 @@ module Mom
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 27 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestIntOperators < BootTest
|
||||
def setup
|
||||
@ -90,16 +66,6 @@ module Mom
|
||||
assert_equal 5 , method.mom_instructions.length
|
||||
end
|
||||
end
|
||||
def test_compile
|
||||
each_method do |method|
|
||||
assert_equal Risc::MethodCompiler , method.to_risc.class
|
||||
end
|
||||
end
|
||||
def test_risc_length
|
||||
each_method do |method|
|
||||
assert_equal 49 , method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
18
test/mom/builtin/test_method_missing.rb
Normal file
18
test/mom/builtin/test_method_missing.rb
Normal file
@ -0,0 +1,18 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestObjectMissingRisc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_compiler(:method_missing)
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 48 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -2,7 +2,7 @@ require_relative "helper"
|
||||
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestObjectFunctionGet < BootTest
|
||||
class TestObjectGet < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_compiler(:get_internal_word)
|
||||
@ -13,14 +13,8 @@ module Mom
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 20 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestObjectFunctionSet < BootTest
|
||||
class TestObjectSet < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_compiler(:set_internal_word)
|
||||
@ -31,14 +25,8 @@ module Mom
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 21 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestObjectFunctionMissing < BootTest
|
||||
class TestObjectMissing < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_compiler(:method_missing)
|
||||
@ -49,14 +37,8 @@ module Mom
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 48 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestObjectFunctionExit < BootTest
|
||||
class TestObjectExit < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_compiler(:exit)
|
||||
@ -67,14 +49,8 @@ module Mom
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 46 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestObjectFunctionInit < BootTest
|
||||
class TestObjectInit < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_compiler(:__init__)
|
||||
@ -85,12 +61,6 @@ module Mom
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 48 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
27
test/mom/builtin/test_operator.rb
Normal file
27
test/mom/builtin/test_operator.rb
Normal file
@ -0,0 +1,27 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestIntOperatorsRisc < BootTest
|
||||
def setup
|
||||
super
|
||||
end
|
||||
def each_method &block
|
||||
Risc.operators.each do |name|
|
||||
method = get_compiler(name)
|
||||
block.yield(method)
|
||||
end
|
||||
end
|
||||
def test_compile
|
||||
each_method do |method|
|
||||
assert_equal Risc::MethodCompiler , method.to_risc.class
|
||||
end
|
||||
end
|
||||
def test_risc_length
|
||||
each_method do |method|
|
||||
assert_equal 49 , method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
18
test/mom/builtin/test_putstring.rb
Normal file
18
test/mom/builtin/test_putstring.rb
Normal file
@ -0,0 +1,18 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestWordPutRisc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_compiler(:putstring)
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 50 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
18
test/mom/builtin/test_set_internal_byte.rb
Normal file
18
test/mom/builtin/test_set_internal_byte.rb
Normal file
@ -0,0 +1,18 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestWordSetRisc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_compiler(:set_internal_byte)
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 22 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
18
test/mom/builtin/test_set_internal_word.rb
Normal file
18
test/mom/builtin/test_set_internal_word.rb
Normal file
@ -0,0 +1,18 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestWordSetRisc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_compiler(:set_internal_byte)
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 22 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -13,12 +13,6 @@ module Mom
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 50 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestWordGet < BootTest
|
||||
def setup
|
||||
@ -31,12 +25,6 @@ module Mom
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 48 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestWordSet < BootTest
|
||||
def setup
|
||||
@ -49,12 +37,6 @@ module Mom
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 22 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user