rubyx/test/compiler/test_basic.rb
2015-10-07 10:53:45 +03:00

64 lines
1.3 KiB
Ruby

require_relative "compiler_helper"
class TestBasic < MiniTest::Test
def check
input = <<HERE
class Object
int main()
#{@string_input}
end
end
HERE
expressions = Virtual.machine.boot.parse_and_compile input
if( expressions.first.is_a? Virtual::Self )
expressions.first.type.instance_variable_set :@of_class , nil
end
is = Sof.write(expressions)
#puts is
assert_equal @output , is
end
def test_number
@string_input = '42 '
@output = "- Virtual::Return(:type => Virtual::Integer, :value => 42)"
check
end
def test_true
@string_input = 'true '
@output = "- Virtual::Return(:type => Virtual::Reference, :value => true)"
check
end
def test_false
@string_input = 'false '
@output = "- Virtual::Return(:type => Virtual::Reference, :value => false)"
check
end
def test_nil
@string_input = 'nil '
@output = "- Virtual::Return(:type => Virtual::Reference)"
check
end
def test_var
@string_input = 'int foo '
@output = "- Virtual::Return(:type => :int)"
check
end
def test_self
@string_input = 'self '
@output = "- Virtual::Self(:type => Virtual::Reference())"
check
end
def test_string
@string_input = "\"hello\""
@output = "- Virtual::Return(:type => Virtual::Reference, :value => :hello)"
check
end
end