tests for ast to code converter
This commit is contained in:
parent
29fb2a50f5
commit
5c2f545f8e
@ -36,7 +36,7 @@ module Typed
|
|||||||
|
|
||||||
def on_field_def statement
|
def on_field_def statement
|
||||||
type , name , value = *statement
|
type , name , value = *statement
|
||||||
w = FieldDef.new()
|
w = Tree::FieldDef.new()
|
||||||
w.type = type
|
w.type = type
|
||||||
w.name = process(name)
|
w.name = process(name)
|
||||||
w.value = process(value) if value
|
w.value = process(value) if value
|
||||||
@ -45,7 +45,7 @@ module Typed
|
|||||||
|
|
||||||
def on_class_field statement
|
def on_class_field statement
|
||||||
type , name = *statement
|
type , name = *statement
|
||||||
w = ClassField.new()
|
w = Tree::ClassField.new()
|
||||||
w.type = type
|
w.type = type
|
||||||
w.name = name
|
w.name = name
|
||||||
w
|
w
|
||||||
@ -53,7 +53,7 @@ module Typed
|
|||||||
|
|
||||||
def on_while_statement statement
|
def on_while_statement statement
|
||||||
branch_type , condition , statements = *statement
|
branch_type , condition , statements = *statement
|
||||||
w = WhileStatement.new()
|
w = Tree::WhileStatement.new()
|
||||||
w.branch_type = branch_type
|
w.branch_type = branch_type
|
||||||
w.condition = process(condition)
|
w.condition = process(condition)
|
||||||
w.statements = process(statements)
|
w.statements = process(statements)
|
||||||
@ -105,7 +105,7 @@ module Typed
|
|||||||
|
|
||||||
def on_field_access statement
|
def on_field_access statement
|
||||||
receiver_ast , field_ast = *statement
|
receiver_ast , field_ast = *statement
|
||||||
w = FieldAccess.new()
|
w = Tree::FieldAccess.new()
|
||||||
w.receiver = process(receiver_ast)
|
w.receiver = process(receiver_ast)
|
||||||
w.field = process(field_ast)
|
w.field = process(field_ast)
|
||||||
w
|
w
|
||||||
@ -148,12 +148,12 @@ module Typed
|
|||||||
end
|
end
|
||||||
|
|
||||||
def on_class_name expression
|
def on_class_name expression
|
||||||
ClassExpression.new(expression.children.first)
|
Tree::ClassExpression.new(expression.children.first)
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_assignment statement
|
def on_assignment statement
|
||||||
name , value = *statement
|
name , value = *statement
|
||||||
w = Assignment.new()
|
w = Tree::Assignment.new()
|
||||||
w.name = process name
|
w.name = process name
|
||||||
w.value = process(value)
|
w.value = process(value)
|
||||||
w
|
w
|
||||||
|
@ -4,6 +4,4 @@ require_relative "lib/test_all"
|
|||||||
|
|
||||||
require_relative "register/test_all"
|
require_relative "register/test_all"
|
||||||
|
|
||||||
require_relative "typed/parfait/test_all"
|
require_relative "typed/test_all"
|
||||||
|
|
||||||
require_relative "typed/type/test_all"
|
|
||||||
|
5
test/typed/test_all.rb
Normal file
5
test/typed/test_all.rb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
require_relative "parfait/test_all"
|
||||||
|
|
||||||
|
require_relative "type/test_all"
|
||||||
|
|
||||||
|
require_relative "test_to_code"
|
51
test/typed/test_to_code.rb
Normal file
51
test/typed/test_to_code.rb
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
class ToCodeTest < MiniTest::Test
|
||||||
|
include AST::Sexp
|
||||||
|
|
||||||
|
def check clazz
|
||||||
|
tree = Typed.ast_to_code @statement
|
||||||
|
assert_equal tree.class , Typed::Tree.const_get( clazz )
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_field_access
|
||||||
|
@statement = s(:field_access, s(:receiver, s(:name, :m)), s(:field, s(:name, :index)))
|
||||||
|
check "FieldAccess"
|
||||||
|
end
|
||||||
|
def test_field_def_value
|
||||||
|
@statement = s(:field_def, :Integer, s(:name, :abba), s(:int, 5))
|
||||||
|
check "FieldDef"
|
||||||
|
end
|
||||||
|
def test_class_field
|
||||||
|
@statement = s(:class_field, :Integer, :fff, s(:int, 3))
|
||||||
|
check "ClassField"
|
||||||
|
end
|
||||||
|
def test_simple_while
|
||||||
|
@statement = s(:while_statement, :false, s(:conditional,s(:int, 1)), s(:statements))
|
||||||
|
check "WhileStatement"
|
||||||
|
end
|
||||||
|
def test_assignment
|
||||||
|
@statement = s(:assignment, s(:name, :i), s(:int, 0))
|
||||||
|
check "Assignment"
|
||||||
|
end
|
||||||
|
def test_nil
|
||||||
|
@statement = s(:nil)
|
||||||
|
check "NilExpression"
|
||||||
|
end
|
||||||
|
def test_true
|
||||||
|
@statement = s(:true)
|
||||||
|
check "TrueExpression"
|
||||||
|
end
|
||||||
|
def test_false
|
||||||
|
@statement = s(:false)
|
||||||
|
check "FalseExpression"
|
||||||
|
end
|
||||||
|
def test_name
|
||||||
|
@statement = s(:name, :foo)
|
||||||
|
check "NameExpression"
|
||||||
|
end
|
||||||
|
def test_class_name
|
||||||
|
@statement = s(:class_name, :FooBar)
|
||||||
|
check "ClassExpression"
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user