rubyx/test/compiler/test_basic.rb

68 lines
1.5 KiB
Ruby
Raw Normal View History

2015-07-19 10:54:36 +03:00
require_relative "compiler_helper"
2014-06-26 17:52:15 +03:00
2015-07-18 15:28:57 +03:00
2014-06-26 17:52:15 +03:00
class TestBasic < MiniTest::Test
2015-07-18 15:28:57 +03:00
def check
expressions = Virtual.machine.boot.compile_main @string_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
2014-07-01 15:57:13 +03:00
2014-06-26 17:52:15 +03:00
def test_number
@string_input = '42 '
@output = "- Virtual::Return(:type => Virtual::Integer, :value => 42)"
2014-06-26 17:52:15 +03:00
check
end
2014-07-01 15:57:13 +03:00
def test_true
@string_input = 'true '
@output = "- Virtual::Return(:type => Virtual::Reference, :value => true)"
2014-07-01 15:57:13 +03:00
check
end
def test_false
@string_input = 'false '
@output = "- Virtual::Return(:type => Virtual::Reference, :value => false)"
2014-07-01 15:57:13 +03:00
check
end
def test_nil
@string_input = 'nil '
@output = "- Virtual::Return(:type => Virtual::Reference)"
2014-07-01 15:57:13 +03:00
check
end
def test_name
2014-06-26 17:52:15 +03:00
@string_input = 'foo '
@output = "- Virtual::Return(:type => Virtual::Unknown)"
2014-06-29 19:05:35 +03:00
check
2014-06-26 17:52:15 +03:00
end
def test_self
@string_input = 'self '
@output = "- Virtual::Self(:type => Virtual::Reference())"
check
end
2014-06-26 17:52:15 +03:00
def test_instance_variable
@string_input = '@foo_bar '
@output = "- Virtual::Return(:type => Virtual::Unknown)"
2014-06-29 19:05:35 +03:00
check
2014-06-26 17:52:15 +03:00
end
2015-05-05 14:04:37 +03:00
def pest_module_name
2014-06-26 17:52:15 +03:00
@string_input = 'FooBar '
@output = ""
2014-06-29 19:05:35 +03:00
check
2014-06-26 17:52:15 +03:00
end
def test_string
@string_input = "\"hello\""
@output = "- Virtual::Return(:type => Virtual::Reference, :value => :hello)"
2014-06-29 19:05:35 +03:00
check
2014-06-26 17:52:15 +03:00
end
2015-05-05 14:04:37 +03:00
end