2015-07-19 09:54:36 +02:00
|
|
|
require_relative "compiler_helper"
|
2014-06-26 16:52:15 +02:00
|
|
|
|
2015-07-18 14:28:57 +02:00
|
|
|
|
2014-06-26 16:52:15 +02:00
|
|
|
class TestBasic < MiniTest::Test
|
2015-07-18 14:28:57 +02:00
|
|
|
def check
|
2015-10-05 23:27:13 +02:00
|
|
|
input = <<HERE
|
|
|
|
class Object
|
|
|
|
int main()
|
|
|
|
#{@string_input}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
|
|
|
|
|
|
|
expressions = Virtual.machine.boot.parse_and_compile input
|
2015-07-18 14:28:57 +02:00
|
|
|
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 14:57:13 +02:00
|
|
|
|
2014-06-26 16:52:15 +02:00
|
|
|
def test_number
|
|
|
|
@string_input = '42 '
|
2015-07-02 09:26:48 +02:00
|
|
|
@output = "- Virtual::Return(:type => Virtual::Integer, :value => 42)"
|
2014-06-26 16:52:15 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
2014-07-01 14:57:13 +02:00
|
|
|
def test_true
|
|
|
|
@string_input = 'true '
|
2015-07-02 09:26:48 +02:00
|
|
|
@output = "- Virtual::Return(:type => Virtual::Reference, :value => true)"
|
2014-07-01 14:57:13 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
def test_false
|
|
|
|
@string_input = 'false '
|
2015-07-02 09:26:48 +02:00
|
|
|
@output = "- Virtual::Return(:type => Virtual::Reference, :value => false)"
|
2014-07-01 14:57:13 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
def test_nil
|
|
|
|
@string_input = 'nil '
|
2015-07-02 09:26:48 +02:00
|
|
|
@output = "- Virtual::Return(:type => Virtual::Reference)"
|
2014-07-01 14:57:13 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
2015-09-27 15:06:48 +02:00
|
|
|
def test_var
|
|
|
|
@string_input = 'int foo '
|
2015-09-23 17:35:37 +02:00
|
|
|
@output = "- Virtual::Return(:type => :int)"
|
2014-06-29 18:05:35 +02:00
|
|
|
check
|
2014-06-26 16:52:15 +02:00
|
|
|
end
|
|
|
|
|
2014-07-14 13:29:33 +02:00
|
|
|
def test_self
|
|
|
|
@string_input = 'self '
|
2015-07-02 09:26:48 +02:00
|
|
|
@output = "- Virtual::Self(:type => Virtual::Reference())"
|
2014-07-14 13:29:33 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
2015-05-05 13:04:37 +02:00
|
|
|
def pest_module_name
|
2014-06-26 16:52:15 +02:00
|
|
|
@string_input = 'FooBar '
|
2015-05-16 19:16:49 +02:00
|
|
|
@output = ""
|
2014-06-29 18:05:35 +02:00
|
|
|
check
|
2014-06-26 16:52:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_string
|
|
|
|
@string_input = "\"hello\""
|
2015-07-02 09:26:48 +02:00
|
|
|
@output = "- Virtual::Return(:type => Virtual::Reference, :value => :hello)"
|
2014-06-29 18:05:35 +02:00
|
|
|
check
|
2014-06-26 16:52:15 +02:00
|
|
|
end
|
|
|
|
|
2015-05-05 13:04:37 +02:00
|
|
|
end
|