Integer macros tests and defs

This commit is contained in:
2019-09-11 19:23:56 +03:00
parent e8bfb9a58c
commit 5ea91df4c1
10 changed files with 266 additions and 6 deletions

View File

@ -0,0 +1,47 @@
require_relative "helper"
module RubyX
module Builtin
class TestIntegerSame < MiniTest::Test
include BuiltinHelper
def op ; :== ; end
def len ; 25 ; end
def source
<<GET
class Integer
def #{op}(other)
X.comparison(:"#{op}")
end
end
GET
end
def test_mom_meth
assert_equal op , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_op
assert_equal Mom::Comparison , compiler.mom_instructions.next.class
assert_equal op , compiler.mom_instructions.next.operator
end
def test_risc
assert_equal len , compiler.to_risc.risc_instructions.length
end
end
class TestIntegerLg < TestIntegerSame
def op ; :> ; end
def len ; 26 ; end
end
class TestIntegerSm < TestIntegerSame
def op ; :< ; end
def len ; 26 ; end
end
class TestIntegerLe < TestIntegerSame
def op ; :>= ; end
end
class TestIntegerSe < TestIntegerSame
def op ; :<= ; end
end
end
end

View File

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

View File

@ -0,0 +1,30 @@
require_relative "helper"
module RubyX
module Builtin
class TestIntegerDiv4 < MiniTest::Test
include BuiltinHelper
def source
<<GET
class Integer
def div4
X.div4
end
end
GET
end
def test_mom_meth
assert_equal :div4 , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_get
assert_equal Mom::Div4 , 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,50 @@
require_relative "helper"
module RubyX
module Builtin
class TestIntegerPlus < MiniTest::Test
include BuiltinHelper
def op ; :+ ; end
def source
<<GET
class Integer
def #{op}(other)
X.int_operator(:"#{op}")
end
end
GET
end
def test_mom_meth
assert_equal op , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_op
assert_equal Mom::IntOperator , compiler.mom_instructions.next.class
assert_equal op , compiler.mom_instructions.next.operator
end
def test_risc
assert_equal 42 , compiler.to_risc.risc_instructions.length
end
end
class TestIntegerMinus < TestIntegerPlus
def op ; :- ; end
end
class TestIntegerRS < TestIntegerPlus
def op ; :<< ; end
end
class TestIntegerRS < TestIntegerPlus
def op ; :>> ; end
end
class TestIntegerMul < TestIntegerPlus
def op ; :* ; end
end
class TestIntegerAnd < TestIntegerPlus
def op ; :& ; end
end
class TestIntegerOr < TestIntegerPlus
def op ; :| ; end
end
end
end