f4a4ccb98e
- all code must be in functions (which must be in classes). — changes a fair few tests — also changes api, as method is not recursive, not passed around - all state in instance vars in compiler (no accessors) - class is another such variable, surely more coming all green again
70 lines
1.4 KiB
Ruby
70 lines
1.4 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 pest_module_name
|
|
@string_input = 'FooBar '
|
|
@output = ""
|
|
check
|
|
end
|
|
|
|
def test_string
|
|
@string_input = "\"hello\""
|
|
@output = "- Virtual::Return(:type => Virtual::Reference, :value => :hello)"
|
|
check
|
|
end
|
|
|
|
end
|