3 require 'antimony/generators/ruby_to_ast_proxy'
12 def add section, *code
13 unless @sections.has_key? section
14 @sections[section] = []
16 @sections[section] = @sections[section] + code
23 attr_accessor :sections
26 class RubyToAstProxyTest < Test::Unit::TestCase
28 # Create a RubyToAstProxy that feeds the translated code to our
30 @stub = GeneratorStub.new
31 @proxy = RubyToAstProxy.new @stub
36 @proxy.add :code, [:label, :test], [:goto, :test]
37 @proxy.add :data, [:label, :x], [:word, 42]
38 assert @stub.sections.has_key? :code
39 assert_equal 2, @stub.sections[:code].length
40 assert @stub.sections.has_key? :data
41 assert_equal 2, @stub.sections[:data].length
46 @proxy.add_function [:x, :y], [:return, :add, :x, :y]
47 assert @stub.sections.has_key? :functions
48 code = @stub.sections[:functions]
51 if x.kind_of?(Ast::Statement) && x[0].kind_of?(Ast::Symbol) &&
52 x[0].name == :function
58 assert_equal 4, func.exprs.length
59 assert_kind_of Ast::Symbol, func[1]
60 assert_equal :x, func[1].name
61 assert_kind_of Ast::Symbol, func[2]
62 assert_equal :y, func[2].name
63 assert_kind_of Ast::Block, func[-1]
66 if x.kind_of? Ast::Statement
67 if x[0].kind_of? Ast::Symbol
68 if x[0].name == :return
76 assert_equal :add, ret[1].name
77 assert_equal :x, ret[2].name
78 assert_equal :y, ret[3].name