rkelly 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. data/CHANGELOG.txt +7 -0
  2. data/Manifest.txt +199 -0
  3. data/README.txt +58 -0
  4. data/Rakefile +85 -0
  5. data/lib/parser.y +870 -0
  6. data/lib/rkelly.rb +13 -0
  7. data/lib/rkelly/constants.rb +3 -0
  8. data/lib/rkelly/generated_parser.rb +3237 -0
  9. data/lib/rkelly/js.rb +14 -0
  10. data/lib/rkelly/js/array.rb +15 -0
  11. data/lib/rkelly/js/base.rb +91 -0
  12. data/lib/rkelly/js/boolean.rb +21 -0
  13. data/lib/rkelly/js/function.rb +39 -0
  14. data/lib/rkelly/js/function_prototype.rb +15 -0
  15. data/lib/rkelly/js/global_object.rb +52 -0
  16. data/lib/rkelly/js/math.rb +10 -0
  17. data/lib/rkelly/js/nan.rb +18 -0
  18. data/lib/rkelly/js/number.rb +22 -0
  19. data/lib/rkelly/js/object.rb +30 -0
  20. data/lib/rkelly/js/object_prototype.rb +14 -0
  21. data/lib/rkelly/js/property.rb +20 -0
  22. data/lib/rkelly/js/scope.rb +6 -0
  23. data/lib/rkelly/js/string.rb +21 -0
  24. data/lib/rkelly/lexeme.rb +18 -0
  25. data/lib/rkelly/nodes.rb +5 -0
  26. data/lib/rkelly/nodes/binary_node.rb +18 -0
  27. data/lib/rkelly/nodes/bracket_accessor_node.rb +11 -0
  28. data/lib/rkelly/nodes/case_clause_node.rb +11 -0
  29. data/lib/rkelly/nodes/comma_node.rb +11 -0
  30. data/lib/rkelly/nodes/conditional_node.rb +11 -0
  31. data/lib/rkelly/nodes/dot_accessor_node.rb +11 -0
  32. data/lib/rkelly/nodes/for_in_node.rb +12 -0
  33. data/lib/rkelly/nodes/for_node.rb +13 -0
  34. data/lib/rkelly/nodes/function_call_node.rb +16 -0
  35. data/lib/rkelly/nodes/function_decl_node.rb +6 -0
  36. data/lib/rkelly/nodes/function_expr_node.rb +12 -0
  37. data/lib/rkelly/nodes/if_node.rb +12 -0
  38. data/lib/rkelly/nodes/label_node.rb +11 -0
  39. data/lib/rkelly/nodes/new_expr_node.rb +11 -0
  40. data/lib/rkelly/nodes/node.rb +88 -0
  41. data/lib/rkelly/nodes/not_strict_equal_node.rb +6 -0
  42. data/lib/rkelly/nodes/op_equal_node.rb +16 -0
  43. data/lib/rkelly/nodes/postfix_node.rb +11 -0
  44. data/lib/rkelly/nodes/prefix_node.rb +6 -0
  45. data/lib/rkelly/nodes/property_node.rb +13 -0
  46. data/lib/rkelly/nodes/resolve_node.rb +19 -0
  47. data/lib/rkelly/nodes/strict_equal_node.rb +6 -0
  48. data/lib/rkelly/nodes/try_node.rb +13 -0
  49. data/lib/rkelly/nodes/var_decl_node.rb +15 -0
  50. data/lib/rkelly/parser.rb +100 -0
  51. data/lib/rkelly/runtime.rb +36 -0
  52. data/lib/rkelly/runtime/ruby_function.rb +13 -0
  53. data/lib/rkelly/runtime/scope_chain.rb +57 -0
  54. data/lib/rkelly/token.rb +15 -0
  55. data/lib/rkelly/tokenizer.rb +122 -0
  56. data/lib/rkelly/visitable.rb +16 -0
  57. data/lib/rkelly/visitors.rb +4 -0
  58. data/lib/rkelly/visitors/dot_visitor.rb +228 -0
  59. data/lib/rkelly/visitors/ecma_visitor.rb +314 -0
  60. data/lib/rkelly/visitors/enumerable_visitor.rb +18 -0
  61. data/lib/rkelly/visitors/evaluation_visitor.rb +419 -0
  62. data/lib/rkelly/visitors/function_visitor.rb +46 -0
  63. data/lib/rkelly/visitors/pointcut_visitor.rb +31 -0
  64. data/lib/rkelly/visitors/real_sexp_visitor.rb +16 -0
  65. data/lib/rkelly/visitors/sexp_visitor.rb +373 -0
  66. data/lib/rkelly/visitors/visitor.rb +136 -0
  67. data/rkelly.gemspec +33 -0
  68. data/test/ecma_script_test_case.rb +21 -0
  69. data/test/execute_test_case.rb +16 -0
  70. data/test/execution_contexts/test_10_1_3-1.rb +32 -0
  71. data/test/expressions/test_11_3_1.rb +64 -0
  72. data/test/expressions/test_11_3_2.rb +64 -0
  73. data/test/expressions/test_11_4_2.rb +13 -0
  74. data/test/expressions/test_11_4_3.rb +52 -0
  75. data/test/expressions/test_11_4_4.rb +68 -0
  76. data/test/expressions/test_11_4_5.rb +69 -0
  77. data/test/expressions/test_11_4_6.rb +88 -0
  78. data/test/expressions/test_11_4_8.rb +28 -0
  79. data/test/expressions/test_11_4_9.rb +103 -0
  80. data/test/expressions/test_11_5_1.rb +51 -0
  81. data/test/expressions/test_11_5_2.rb +80 -0
  82. data/test/expressions/test_11_5_3.rb +88 -0
  83. data/test/expressions/test_11_6_1-1.rb +19 -0
  84. data/test/expressions/test_11_9_1.rb +19 -0
  85. data/test/function/test_15_3_1_1-1.rb +34 -0
  86. data/test/global_object/test_15_1_1_1.rb +29 -0
  87. data/test/global_object/test_15_1_1_2.rb +17 -0
  88. data/test/global_object/test_15_1_1_3.rb +9 -0
  89. data/test/helper.rb +5 -0
  90. data/test/node_test_case.rb +11 -0
  91. data/test/object/test_15_2_1_1.rb +257 -0
  92. data/test/object/test_15_2_1_2.rb +21 -0
  93. data/test/object/test_15_2_2_1.rb +52 -0
  94. data/test/statements/test_12_5-1.rb +27 -0
  95. data/test/test_add_node.rb +8 -0
  96. data/test/test_arguments_node.rb +8 -0
  97. data/test/test_array_node.rb +9 -0
  98. data/test/test_assign_expr_node.rb +8 -0
  99. data/test/test_automatic_semicolon_insertion.rb +137 -0
  100. data/test/test_bit_and_node.rb +8 -0
  101. data/test/test_bit_or_node.rb +8 -0
  102. data/test/test_bit_x_or_node.rb +8 -0
  103. data/test/test_bitwise_not_node.rb +8 -0
  104. data/test/test_block_node.rb +14 -0
  105. data/test/test_bracket_accessor_node.rb +16 -0
  106. data/test/test_break_node.rb +11 -0
  107. data/test/test_case_block_node.rb +11 -0
  108. data/test/test_case_clause_node.rb +15 -0
  109. data/test/test_comma_node.rb +13 -0
  110. data/test/test_comments.rb +44 -0
  111. data/test/test_conditional_node.rb +17 -0
  112. data/test/test_const_statement_node.rb +14 -0
  113. data/test/test_continue_node.rb +11 -0
  114. data/test/test_delete_node.rb +8 -0
  115. data/test/test_divide_node.rb +8 -0
  116. data/test/test_do_while_node.rb +13 -0
  117. data/test/test_dot_accessor_node.rb +9 -0
  118. data/test/test_ecma_visitor.rb +192 -0
  119. data/test/test_element_node.rb +8 -0
  120. data/test/test_empty_statement_node.rb +8 -0
  121. data/test/test_equal_node.rb +8 -0
  122. data/test/test_evaluation_visitor.rb +66 -0
  123. data/test/test_expression_statement_node.rb +10 -0
  124. data/test/test_false_node.rb +8 -0
  125. data/test/test_for_in_node.rb +17 -0
  126. data/test/test_for_node.rb +24 -0
  127. data/test/test_function_body_node.rb +8 -0
  128. data/test/test_function_call_node.rb +10 -0
  129. data/test/test_function_decl_node.rb +16 -0
  130. data/test/test_function_expr_node.rb +16 -0
  131. data/test/test_function_visitor.rb +26 -0
  132. data/test/test_getter_property_node.rb +10 -0
  133. data/test/test_global_object.rb +49 -0
  134. data/test/test_greater_node.rb +8 -0
  135. data/test/test_greater_or_equal_node.rb +8 -0
  136. data/test/test_if_node.rb +17 -0
  137. data/test/test_in_node.rb +8 -0
  138. data/test/test_instance_of_node.rb +8 -0
  139. data/test/test_label_node.rb +13 -0
  140. data/test/test_left_shift_node.rb +8 -0
  141. data/test/test_less_node.rb +8 -0
  142. data/test/test_less_or_equal_node.rb +8 -0
  143. data/test/test_line_number.rb +23 -0
  144. data/test/test_logical_and_node.rb +8 -0
  145. data/test/test_logical_not_node.rb +8 -0
  146. data/test/test_logical_or_node.rb +8 -0
  147. data/test/test_modulus_node.rb +8 -0
  148. data/test/test_multiply_node.rb +8 -0
  149. data/test/test_new_expr_node.rb +9 -0
  150. data/test/test_not_equal_node.rb +8 -0
  151. data/test/test_not_strict_equal_node.rb +8 -0
  152. data/test/test_null_node.rb +8 -0
  153. data/test/test_number_node.rb +8 -0
  154. data/test/test_object_literal_node.rb +9 -0
  155. data/test/test_op_and_equal_node.rb +10 -0
  156. data/test/test_op_divide_equal_node.rb +10 -0
  157. data/test/test_op_equal_node.rb +10 -0
  158. data/test/test_op_l_shift_equal_node.rb +10 -0
  159. data/test/test_op_minus_equal_node.rb +10 -0
  160. data/test/test_op_mod_equal_node.rb +10 -0
  161. data/test/test_op_multiply_equal_node.rb +10 -0
  162. data/test/test_op_or_equal_node.rb +10 -0
  163. data/test/test_op_plus_equal_node.rb +10 -0
  164. data/test/test_op_r_shift_equal_node.rb +10 -0
  165. data/test/test_op_u_r_shift_equal_node.rb +10 -0
  166. data/test/test_op_x_or_equal_node.rb +10 -0
  167. data/test/test_parameter_node.rb +8 -0
  168. data/test/test_parser.rb +1355 -0
  169. data/test/test_pointcut_visitor.rb +34 -0
  170. data/test/test_postfix_node.rb +8 -0
  171. data/test/test_prefix_node.rb +8 -0
  172. data/test/test_property_node.rb +8 -0
  173. data/test/test_regexp_node.rb +8 -0
  174. data/test/test_resolve_node.rb +22 -0
  175. data/test/test_return_node.rb +11 -0
  176. data/test/test_right_shift_node.rb +8 -0
  177. data/test/test_rkelly.rb +19 -0
  178. data/test/test_runtime.rb +12 -0
  179. data/test/test_scope_chain.rb +50 -0
  180. data/test/test_setter_property_node.rb +10 -0
  181. data/test/test_source_elements.rb +9 -0
  182. data/test/test_strict_equal_node.rb +8 -0
  183. data/test/test_string_node.rb +8 -0
  184. data/test/test_subtract_node.rb +8 -0
  185. data/test/test_switch_node.rb +12 -0
  186. data/test/test_this_node.rb +8 -0
  187. data/test/test_throw_node.rb +7 -0
  188. data/test/test_tokenizer.rb +143 -0
  189. data/test/test_true_node.rb +8 -0
  190. data/test/test_try_node.rb +59 -0
  191. data/test/test_type_of_node.rb +8 -0
  192. data/test/test_unary_minus_node.rb +8 -0
  193. data/test/test_unary_plus_node.rb +8 -0
  194. data/test/test_unsigned_right_shift_node.rb +8 -0
  195. data/test/test_var_decl_node.rb +21 -0
  196. data/test/test_var_statement_node.rb +14 -0
  197. data/test/test_void_node.rb +8 -0
  198. data/test/test_while_node.rb +15 -0
  199. data/test/test_with_node.rb +8 -0
  200. metadata +390 -0
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class DivideNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ node = DivideNode.new(NumberNode.new(5), NumberNode.new(10))
6
+ assert_sexp([:divide, [:lit, 5], [:lit, 10]], node)
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class DoWhileNodeTest < NodeTestCase
4
+ def test_to_sepx
5
+ initializer = AssignExprNode.new(NumberNode.new(10))
6
+ decl = VarDeclNode.new('foo', initializer)
7
+ stmt = VarStatementNode.new([decl])
8
+ node = DoWhileNode.new(stmt, TrueNode.new('true'))
9
+
10
+ assert_sexp([:do_while, [:var, [[:var_decl, :foo, [:assign, [:lit, 10]]]]],
11
+ [:true]], node)
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class DotAccessorNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ resolve = ResolveNode.new('foo')
6
+ node = DotAccessorNode.new(resolve, 'bar')
7
+ assert_sexp([:dot_access, [:resolve, 'foo'], 'bar', ], node)
8
+ end
9
+ end
@@ -0,0 +1,192 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class ECMAVisitorTest < Test::Unit::TestCase
4
+ def setup
5
+ @parser = RKelly::Parser.new
6
+ end
7
+
8
+ def test_anonymous_function_expr
9
+ assert_to_ecma('a = function() { };')
10
+ end
11
+
12
+
13
+ def test_this_node
14
+ assert_to_ecma('this.foo;')
15
+ end
16
+
17
+ def test_bitwise_not_node
18
+ assert_to_ecma('~10;')
19
+ end
20
+
21
+ def test_delete_node
22
+ assert_to_ecma('delete foo;')
23
+ end
24
+
25
+ def test_element_node
26
+ assert_to_ecma('var foo = [1];')
27
+ end
28
+
29
+ def test_logical_not_node
30
+ assert_to_ecma('!foo;')
31
+ end
32
+
33
+ def test_unary_minus_node
34
+ assert_to_ecma('-0;')
35
+ end
36
+
37
+ def test_return_node
38
+ assert_to_ecma('return foo;')
39
+ assert_to_ecma('return;')
40
+ end
41
+
42
+ def test_throw_node
43
+ assert_to_ecma('throw foo;')
44
+ end
45
+
46
+ def test_type_of_node
47
+ assert_to_ecma('typeof foo;')
48
+ end
49
+
50
+ def test_unary_plus_node
51
+ assert_to_ecma('+10;')
52
+ end
53
+
54
+ def test_void_node
55
+ assert_to_ecma('void(0);')
56
+ end
57
+
58
+ [
59
+ [:add, '+'],
60
+ [:and_equal, '&='],
61
+ [:bit_and, '&'],
62
+ [:bit_or, '|'],
63
+ [:bit_xor, '^'],
64
+ [:divide, '/'],
65
+ [:divide_equal, '/='],
66
+ [:equal_equal, '=='],
67
+ [:greater, '>'],
68
+ [:greater_or_equal, '>='],
69
+ [:left_shift, '<<'],
70
+ [:left_shift_equal, '<<='],
71
+ [:less_or_equal, '<='],
72
+ [:logical_and, '&&'],
73
+ [:logical_or, '||'],
74
+ [:minus_equal, '-='],
75
+ [:mod, '%'],
76
+ [:mod_equal, '%='],
77
+ [:multiply, '*'],
78
+ [:multiply_equal, '*='],
79
+ [:not_equal, '!='],
80
+ [:not_strict_equal, '!=='],
81
+ [:or_equal, '|='],
82
+ [:plus_equal, '+='],
83
+ [:right_shift, '>>'],
84
+ [:right_shift_equal, '>>='],
85
+ [:strict_equal, '==='],
86
+ [:subtract, '-'],
87
+ [:ur_shift, '>>>'],
88
+ [:uright_shift_equal, '>>>='],
89
+ [:xor_equal, '^='],
90
+ [:instanceof, 'instanceof'],
91
+ ].each do |name, value|
92
+ define_method(:"test_#{name}_node") do
93
+ assert_to_ecma("10 #{value} 20;")
94
+ end
95
+ end
96
+
97
+ def test_while_node
98
+ assert_to_ecma("while(true) { foo(); }")
99
+ end
100
+
101
+ def test_switch_node
102
+ assert_to_ecma("switch(a) { }")
103
+ end
104
+
105
+ def test_switch_case_node
106
+ assert_to_ecma("switch(a) {
107
+ case 1:
108
+ foo();
109
+ break;
110
+ }")
111
+ end
112
+
113
+ def test_do_while_node
114
+ assert_to_ecma("do { foo(); } while(true);")
115
+ end
116
+
117
+ def test_with_node
118
+ assert_to_ecma("with(o) { foo(); }")
119
+ end
120
+
121
+ def test_const_statement_node
122
+ assert_to_ecma("const foo;")
123
+ end
124
+
125
+ def test_label_node
126
+ assert_to_ecma("foo: var foo;")
127
+ end
128
+
129
+ def test_object_literal
130
+ assert_to_ecma("var foo = { };")
131
+ end
132
+
133
+ def test_property
134
+ assert_to_ecma("var foo = { bar: 10 };")
135
+ end
136
+
137
+ def test_getter_node
138
+ assert_to_ecma("var foo = { get a() { } };")
139
+ end
140
+
141
+ def test_setter_node
142
+ assert_to_ecma("var foo = { set a(b) { } };")
143
+ end
144
+
145
+ def test_bracket_access_node
146
+ assert_to_ecma("var foo = foo.bar[10];")
147
+ end
148
+
149
+ def test_new_expr_node
150
+ assert_to_ecma("var foo = new Array();")
151
+ assert_to_ecma("var foo = new Array(10);")
152
+ assert_to_ecma("var foo = new Array(a, 10);")
153
+ end
154
+
155
+ def test_try_finally
156
+ assert_to_ecma('try { var x = 10; } finally { var x = 20; }')
157
+ end
158
+
159
+ def test_try_catch
160
+ assert_to_ecma('try { var x = 10; } catch(a) { var x = 20; }')
161
+ end
162
+
163
+ def test_comma_node
164
+ assert_to_ecma('i = 10, j = 11;')
165
+ end
166
+
167
+ def test_in_node
168
+ assert_to_ecma('var x = 0 in foo;')
169
+ end
170
+
171
+ def test_if_node
172
+ assert_to_ecma('if(5 && 10) var foo = 20;')
173
+ assert_to_ecma('if(5 && 10) { var foo = 20; }')
174
+ assert_to_ecma('if(5 && 10) { var foo = 20; } else var foo = 10;')
175
+ assert_to_ecma('if(5 && 10) { var foo = 20; } else { var foo = 10; }')
176
+ end
177
+
178
+ def test_conditional_node
179
+ assert_to_ecma('var x = 5 < 10 ? 20 : 30;')
180
+ end
181
+
182
+ def test_for_in_node
183
+ assert_to_ecma('for(foo in bar) { var x = 10; }')
184
+ end
185
+
186
+ def assert_to_ecma(expected, actual = nil)
187
+ ecma = @parser.parse(actual || expected).to_ecma
188
+ ecma = ecma.gsub(/\n/, ' ').gsub(/\s+/, ' ')
189
+ expected = expected.gsub(/\n/, ' ').gsub(/\s+/, ' ')
190
+ assert_equal(expected, ecma)
191
+ end
192
+ end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class ElementNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ node = ElementNode.new(NumberNode.new(10))
6
+ assert_sexp([:element, [:lit, 10]], node)
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class EmptyStatementNodeTest < NodeTestCase
4
+ def test_to_to_sexp
5
+ node = EmptyStatementNode.new(';')
6
+ assert_sexp([:empty], node)
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class EqualNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ node = EqualNode.new(NumberNode.new(5), NumberNode.new(10))
6
+ assert_sexp([:equal, [:lit, 5], [:lit, 10]], node)
7
+ end
8
+ end
@@ -0,0 +1,66 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class EvaluationVisitorTest < Test::Unit::TestCase
4
+ def setup
5
+ @parser = RKelly::Parser.new
6
+ @scope = RKelly::Runtime::ScopeChain.new
7
+ @visitor = RKelly::Visitors::EvaluationVisitor.new(@scope)
8
+ end
9
+
10
+ def assert_properties(actual, js_code)
11
+ tree = @parser.parse(js_code)
12
+ @visitor.accept(tree)
13
+ actual.each do |property, value|
14
+ assert @visitor.scope_chain.has_property?(property)
15
+ assert_equal value, @visitor.scope_chain[property].value
16
+ end
17
+ end
18
+
19
+ def test_variable
20
+ assert_properties({
21
+ 'foo' => 10,
22
+ }, 'var foo = 10;')
23
+ end
24
+
25
+ def test_add
26
+ assert_properties({
27
+ 'foo' => 6,
28
+ }, 'var foo = 1 + 5;')
29
+ end
30
+
31
+ def test_subtract
32
+ assert_properties({
33
+ 'foo' => 3,
34
+ }, 'var foo = 4 - 1;')
35
+ end
36
+
37
+ def test_multiply
38
+ assert_properties({
39
+ 'foo' => 8,
40
+ }, 'var foo = 4 * 2;')
41
+ end
42
+
43
+ def test_divide
44
+ assert_properties({
45
+ 'foo' => 2,
46
+ }, 'var foo = 4 / 2;')
47
+ end
48
+
49
+ def test_a_bunch
50
+ assert_properties({
51
+ 'foo' => 2,
52
+ }, 'var foo = 1 + 2 * 2 / 4;')
53
+ end
54
+
55
+ def test_add_resolve
56
+ assert_properties({
57
+ 'foo' => 3,
58
+ }, 'foo = 1 + 2;')
59
+ end
60
+
61
+ def test_plus_equal
62
+ assert_properties({
63
+ 'foo' => 3,
64
+ }, 'var foo = 1; foo += 2;')
65
+ end
66
+ end
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class ExpressionStatementNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ resolve = ResolveNode.new('foo')
6
+ access = DotAccessorNode.new(resolve, 'bar')
7
+ node = ExpressionStatementNode.new(access)
8
+ assert_sexp([:expression, [:dot_access, [:resolve, 'foo'], 'bar', ]], node)
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class FalseNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ node = FalseNode.new('false')
6
+ assert_sexp [:false], node
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class ForInNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ initializer = AssignExprNode.new(NumberNode.new(10))
6
+ decl = VarDeclNode.new('foo', initializer)
7
+ stmt = VarStatementNode.new([decl])
8
+ block = BlockNode.new(SourceElementsNode.new([stmt]))
9
+
10
+ node = ForInNode.new(ResolveNode.new('foo'), ResolveNode.new('bar'), block)
11
+ assert_sexp([:for_in,
12
+ [:resolve, 'foo'],
13
+ [:resolve, 'bar'],
14
+ [:block, [[:var, [[:var_decl, :foo, [:assign, [:lit, 10]]]]]]]
15
+ ], node)
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class ForNodeTest < NodeTestCase
4
+ def test_failure
5
+ initializer = AssignExprNode.new(NumberNode.new(10))
6
+ decl = VarDeclNode.new('foo', initializer)
7
+ stmt = VarStatementNode.new([decl])
8
+
9
+ compare = LessNode.new(ResolveNode.new('foo'), NumberNode.new(10))
10
+ exec = PostfixNode.new(ResolveNode.new('foo'), '++')
11
+
12
+ block = BlockNode.new(SourceElementsNode.new([stmt]))
13
+
14
+ node = ForNode.new(nil, nil, nil, block)
15
+ assert_sexp([:for, nil, nil, nil, [:block, [[:var, [[:var_decl, :foo, [:assign, [:lit, 10]]]]]]]], node)
16
+
17
+ node = ForNode.new(stmt, compare, exec, block)
18
+ assert_sexp([:for,
19
+ [:var, [[:var_decl, :foo, [:assign, [:lit, 10]]]]],
20
+ [:less, [:resolve, 'foo'], [:lit, 10]],
21
+ [:postfix, [:resolve, 'foo'], '++'],
22
+ [:block, [[:var, [[:var_decl, :foo, [:assign, [:lit, 10]]]]]]]], node)
23
+ end
24
+ end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class FunctionBodyNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ node = FunctionBodyNode.new(SourceElementsNode.new([]))
6
+ assert_sexp([:func_body, []], node)
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class FunctionCallNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ resolve = ResolveNode.new('foo')
6
+ args = ArgumentsNode.new([])
7
+ node = FunctionCallNode.new(resolve, args)
8
+ assert_sexp([:function_call, [:resolve, 'foo'], [:args, []]], node)
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class FunctionDeclNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ body = FunctionBodyNode.new(SourceElementsNode.new([]))
6
+ node = FunctionDeclNode.new(nil, body)
7
+ assert_sexp([:func_decl, nil, [], [:func_body, []]], node)
8
+ end
9
+
10
+ def test_to_sexp_with_args
11
+ body = FunctionBodyNode.new(SourceElementsNode.new([]))
12
+ node = FunctionDeclNode.new(nil, body, [ParameterNode.new('a')])
13
+ assert_sexp([:func_decl, nil, [[:param, 'a']], [:func_body, []]],
14
+ node)
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class FunctionExprNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ body = FunctionBodyNode.new(SourceElementsNode.new([]))
6
+ node = FunctionExprNode.new(nil, body)
7
+ assert_sexp([:func_expr, nil, [], [:func_body, []]], node)
8
+ end
9
+
10
+ def test_to_sexp_with_args
11
+ body = FunctionBodyNode.new(SourceElementsNode.new([]))
12
+ node = FunctionExprNode.new(nil, body, [ParameterNode.new('a')])
13
+ assert_sexp([:func_expr, nil, [[:param, 'a']], [:func_body, []]],
14
+ node)
15
+ end
16
+ end