rkelly-turbo 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.rdoc +38 -0
- data/Manifest.txt +203 -0
- data/README.rdoc +135 -0
- data/Rakefile +41 -0
- data/lib/parser.y +883 -0
- data/lib/rkelly.rb +14 -0
- data/lib/rkelly/char_pos.rb +39 -0
- data/lib/rkelly/char_range.rb +33 -0
- data/lib/rkelly/constants.rb +3 -0
- data/lib/rkelly/generated_parser.rb +3380 -0
- data/lib/rkelly/js.rb +14 -0
- data/lib/rkelly/js/array.rb +15 -0
- data/lib/rkelly/js/base.rb +91 -0
- data/lib/rkelly/js/boolean.rb +21 -0
- data/lib/rkelly/js/function.rb +39 -0
- data/lib/rkelly/js/function_prototype.rb +15 -0
- data/lib/rkelly/js/global_object.rb +52 -0
- data/lib/rkelly/js/math.rb +10 -0
- data/lib/rkelly/js/nan.rb +18 -0
- data/lib/rkelly/js/number.rb +22 -0
- data/lib/rkelly/js/object.rb +30 -0
- data/lib/rkelly/js/object_prototype.rb +14 -0
- data/lib/rkelly/js/property.rb +20 -0
- data/lib/rkelly/js/scope.rb +6 -0
- data/lib/rkelly/js/string.rb +21 -0
- data/lib/rkelly/lexeme.rb +18 -0
- data/lib/rkelly/nodes.rb +25 -0
- data/lib/rkelly/nodes/binary_node.rb +18 -0
- data/lib/rkelly/nodes/bracket_accessor_node.rb +11 -0
- data/lib/rkelly/nodes/case_clause_node.rb +11 -0
- data/lib/rkelly/nodes/comma_node.rb +11 -0
- data/lib/rkelly/nodes/conditional_node.rb +11 -0
- data/lib/rkelly/nodes/dot_accessor_node.rb +11 -0
- data/lib/rkelly/nodes/for_in_node.rb +12 -0
- data/lib/rkelly/nodes/for_node.rb +13 -0
- data/lib/rkelly/nodes/function_call_node.rb +16 -0
- data/lib/rkelly/nodes/function_decl_node.rb +6 -0
- data/lib/rkelly/nodes/function_expr_node.rb +12 -0
- data/lib/rkelly/nodes/if_node.rb +12 -0
- data/lib/rkelly/nodes/label_node.rb +11 -0
- data/lib/rkelly/nodes/new_expr_node.rb +11 -0
- data/lib/rkelly/nodes/node.rb +116 -0
- data/lib/rkelly/nodes/not_strict_equal_node.rb +6 -0
- data/lib/rkelly/nodes/op_equal_node.rb +16 -0
- data/lib/rkelly/nodes/postfix_node.rb +11 -0
- data/lib/rkelly/nodes/prefix_node.rb +6 -0
- data/lib/rkelly/nodes/property_node.rb +13 -0
- data/lib/rkelly/nodes/resolve_node.rb +19 -0
- data/lib/rkelly/nodes/strict_equal_node.rb +6 -0
- data/lib/rkelly/nodes/try_node.rb +13 -0
- data/lib/rkelly/nodes/var_decl_node.rb +15 -0
- data/lib/rkelly/parser.rb +106 -0
- data/lib/rkelly/runtime.rb +36 -0
- data/lib/rkelly/runtime/ruby_function.rb +13 -0
- data/lib/rkelly/runtime/scope_chain.rb +57 -0
- data/lib/rkelly/syntax_error.rb +4 -0
- data/lib/rkelly/token.rb +27 -0
- data/lib/rkelly/tokenizer.rb +255 -0
- data/lib/rkelly/visitable.rb +31 -0
- data/lib/rkelly/visitors.rb +4 -0
- data/lib/rkelly/visitors/dot_visitor.rb +228 -0
- data/lib/rkelly/visitors/ecma_visitor.rb +328 -0
- data/lib/rkelly/visitors/enumerable_visitor.rb +18 -0
- data/lib/rkelly/visitors/evaluation_visitor.rb +419 -0
- data/lib/rkelly/visitors/function_visitor.rb +46 -0
- data/lib/rkelly/visitors/pointcut_visitor.rb +31 -0
- data/lib/rkelly/visitors/real_sexp_visitor.rb +16 -0
- data/lib/rkelly/visitors/sexp_visitor.rb +373 -0
- data/lib/rkelly/visitors/visitor.rb +149 -0
- data/test/ecma_script_test_case.rb +21 -0
- data/test/execute_test_case.rb +16 -0
- data/test/execution_contexts/test_10_1_3-1.rb +32 -0
- data/test/expressions/test_11_3_1.rb +64 -0
- data/test/expressions/test_11_3_2.rb +64 -0
- data/test/expressions/test_11_4_2.rb +13 -0
- data/test/expressions/test_11_4_3.rb +52 -0
- data/test/expressions/test_11_4_4.rb +68 -0
- data/test/expressions/test_11_4_5.rb +69 -0
- data/test/expressions/test_11_4_6.rb +94 -0
- data/test/expressions/test_11_4_8.rb +28 -0
- data/test/expressions/test_11_4_9.rb +103 -0
- data/test/expressions/test_11_5_1.rb +51 -0
- data/test/expressions/test_11_5_2.rb +80 -0
- data/test/expressions/test_11_5_3.rb +88 -0
- data/test/expressions/test_11_6_1-1.rb +19 -0
- data/test/expressions/test_11_9_1.rb +19 -0
- data/test/function/test_15_3_1_1-1.rb +34 -0
- data/test/global_object/test_15_1_1_1.rb +29 -0
- data/test/global_object/test_15_1_1_2.rb +17 -0
- data/test/global_object/test_15_1_1_3.rb +9 -0
- data/test/helper.rb +5 -0
- data/test/node_test_case.rb +11 -0
- data/test/object/test_15_2_1_1.rb +257 -0
- data/test/object/test_15_2_1_2.rb +21 -0
- data/test/object/test_15_2_2_1.rb +52 -0
- data/test/statements/test_12_5-1.rb +27 -0
- data/test/test_add_node.rb +8 -0
- data/test/test_arguments_node.rb +8 -0
- data/test/test_array_node.rb +9 -0
- data/test/test_assign_expr_node.rb +8 -0
- data/test/test_automatic_semicolon_insertion.rb +137 -0
- data/test/test_bit_and_node.rb +8 -0
- data/test/test_bit_or_node.rb +8 -0
- data/test/test_bit_x_or_node.rb +8 -0
- data/test/test_bitwise_not_node.rb +8 -0
- data/test/test_block_node.rb +14 -0
- data/test/test_bracket_accessor_node.rb +16 -0
- data/test/test_break_node.rb +11 -0
- data/test/test_case_block_node.rb +11 -0
- data/test/test_case_clause_node.rb +15 -0
- data/test/test_char_pos.rb +39 -0
- data/test/test_char_range.rb +29 -0
- data/test/test_comma_node.rb +13 -0
- data/test/test_comments.rb +45 -0
- data/test/test_conditional_node.rb +17 -0
- data/test/test_const_statement_node.rb +14 -0
- data/test/test_continue_node.rb +11 -0
- data/test/test_delete_node.rb +8 -0
- data/test/test_divide_node.rb +8 -0
- data/test/test_do_while_node.rb +13 -0
- data/test/test_dot_accessor_node.rb +9 -0
- data/test/test_ecma_visitor.rb +213 -0
- data/test/test_element_node.rb +8 -0
- data/test/test_empty_statement_node.rb +8 -0
- data/test/test_equal_node.rb +8 -0
- data/test/test_evaluation_visitor.rb +66 -0
- data/test/test_expression_statement_node.rb +10 -0
- data/test/test_false_node.rb +8 -0
- data/test/test_for_in_node.rb +17 -0
- data/test/test_for_node.rb +24 -0
- data/test/test_function_body_node.rb +8 -0
- data/test/test_function_call_node.rb +10 -0
- data/test/test_function_decl_node.rb +16 -0
- data/test/test_function_expr_node.rb +16 -0
- data/test/test_function_visitor.rb +26 -0
- data/test/test_getter_property_node.rb +10 -0
- data/test/test_global_object.rb +49 -0
- data/test/test_greater_node.rb +8 -0
- data/test/test_greater_or_equal_node.rb +8 -0
- data/test/test_if_node.rb +17 -0
- data/test/test_in_node.rb +8 -0
- data/test/test_instance_of_node.rb +8 -0
- data/test/test_label_node.rb +13 -0
- data/test/test_left_shift_node.rb +8 -0
- data/test/test_less_node.rb +8 -0
- data/test/test_less_or_equal_node.rb +8 -0
- data/test/test_line_number.rb +81 -0
- data/test/test_logical_and_node.rb +8 -0
- data/test/test_logical_not_node.rb +8 -0
- data/test/test_logical_or_node.rb +8 -0
- data/test/test_modulus_node.rb +8 -0
- data/test/test_multiply_node.rb +8 -0
- data/test/test_new_expr_node.rb +9 -0
- data/test/test_not_equal_node.rb +8 -0
- data/test/test_not_strict_equal_node.rb +8 -0
- data/test/test_null_node.rb +8 -0
- data/test/test_number_node.rb +8 -0
- data/test/test_object_literal_node.rb +9 -0
- data/test/test_op_and_equal_node.rb +10 -0
- data/test/test_op_divide_equal_node.rb +10 -0
- data/test/test_op_equal_node.rb +10 -0
- data/test/test_op_l_shift_equal_node.rb +10 -0
- data/test/test_op_minus_equal_node.rb +10 -0
- data/test/test_op_mod_equal_node.rb +10 -0
- data/test/test_op_multiply_equal_node.rb +10 -0
- data/test/test_op_or_equal_node.rb +10 -0
- data/test/test_op_plus_equal_node.rb +10 -0
- data/test/test_op_r_shift_equal_node.rb +10 -0
- data/test/test_op_u_r_shift_equal_node.rb +10 -0
- data/test/test_op_x_or_equal_node.rb +10 -0
- data/test/test_parameter_node.rb +8 -0
- data/test/test_parser.rb +1434 -0
- data/test/test_pointcut_visitor.rb +34 -0
- data/test/test_postfix_node.rb +8 -0
- data/test/test_prefix_node.rb +8 -0
- data/test/test_property_node.rb +8 -0
- data/test/test_regexp_node.rb +8 -0
- data/test/test_resolve_node.rb +22 -0
- data/test/test_return_node.rb +11 -0
- data/test/test_right_shift_node.rb +8 -0
- data/test/test_rkelly.rb +19 -0
- data/test/test_runtime.rb +12 -0
- data/test/test_scope_chain.rb +50 -0
- data/test/test_setter_property_node.rb +10 -0
- data/test/test_source_elements.rb +9 -0
- data/test/test_strict_equal_node.rb +8 -0
- data/test/test_string_node.rb +8 -0
- data/test/test_subtract_node.rb +8 -0
- data/test/test_switch_node.rb +12 -0
- data/test/test_this_node.rb +8 -0
- data/test/test_throw_node.rb +7 -0
- data/test/test_tokenizer.rb +285 -0
- data/test/test_true_node.rb +8 -0
- data/test/test_try_node.rb +59 -0
- data/test/test_type_of_node.rb +8 -0
- data/test/test_unary_minus_node.rb +8 -0
- data/test/test_unary_plus_node.rb +8 -0
- data/test/test_unsigned_right_shift_node.rb +8 -0
- data/test/test_var_decl_node.rb +21 -0
- data/test/test_var_statement_node.rb +14 -0
- data/test/test_void_node.rb +8 -0
- data/test/test_while_node.rb +15 -0
- data/test/test_with_node.rb +8 -0
- metadata +293 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../helper"
|
2
|
+
|
3
|
+
class Statement_12_5_1_Test < ExecuteTestCase
|
4
|
+
def setup
|
5
|
+
@runtime = RKelly::Runtime.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_if_true
|
9
|
+
assert_execute({ 'x' => 'pass' },
|
10
|
+
"var x; if(true) x = 'pass'; else x = 'fail';")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_if_false
|
14
|
+
assert_execute({ 'x' => 'pass' },
|
15
|
+
"var x; if(false) x = 'fail'; else x = 'pass';")
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_if_zero
|
19
|
+
assert_execute({ 'x' => 'pass' },
|
20
|
+
"var x; if(0) x = 'fail'; else x = 'pass';")
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_if_one
|
24
|
+
assert_execute({ 'x' => 'pass' },
|
25
|
+
"var x; if(1) x = 'pass'; else x = 'fail';")
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/helper"
|
2
|
+
|
3
|
+
class AutomaticSemicolonInsertionTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@parser = RKelly::Parser.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_basic_statement
|
9
|
+
assert_sexp(
|
10
|
+
[
|
11
|
+
[:return,
|
12
|
+
[:lit, 12]]
|
13
|
+
],
|
14
|
+
@parser.parse('return 12'))
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_multiline_expression
|
18
|
+
assert_sexp(
|
19
|
+
[
|
20
|
+
[:expression,
|
21
|
+
[:add,
|
22
|
+
[:lit, 1],
|
23
|
+
[:lit, 1]
|
24
|
+
]
|
25
|
+
]
|
26
|
+
],
|
27
|
+
@parser.parse("1 +\n1"))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_multiple_statements
|
31
|
+
assert_sexp(
|
32
|
+
[
|
33
|
+
[:var,
|
34
|
+
[
|
35
|
+
[:var_decl, :foo, nil]
|
36
|
+
]
|
37
|
+
],
|
38
|
+
[:var,
|
39
|
+
[
|
40
|
+
[:var_decl, :bar, nil]
|
41
|
+
]
|
42
|
+
]
|
43
|
+
],
|
44
|
+
@parser.parse("var foo\nvar bar"))
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_bracketed_statement
|
48
|
+
assert_sexp(
|
49
|
+
[
|
50
|
+
[:block,
|
51
|
+
[
|
52
|
+
[:var,
|
53
|
+
[
|
54
|
+
[:var_decl, :foo, nil]
|
55
|
+
]
|
56
|
+
]
|
57
|
+
]
|
58
|
+
]
|
59
|
+
],
|
60
|
+
@parser.parse("{var foo}"))
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_insertion_before_plus_plus
|
64
|
+
assert_sexp(
|
65
|
+
[
|
66
|
+
[:expression,
|
67
|
+
[:op_equal,
|
68
|
+
[:resolve, "a"],
|
69
|
+
[:resolve, "b"]
|
70
|
+
]
|
71
|
+
],
|
72
|
+
[:expression,
|
73
|
+
[:prefix, [:resolve, "c"], "++"]
|
74
|
+
]
|
75
|
+
],
|
76
|
+
@parser.parse("a = b\n++c"))
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_insertion_before_minus_minus
|
80
|
+
assert_sexp(
|
81
|
+
[
|
82
|
+
[:expression,
|
83
|
+
[:op_equal,
|
84
|
+
[:resolve, "a"],
|
85
|
+
[:resolve, "b"]
|
86
|
+
]
|
87
|
+
],
|
88
|
+
[:expression,
|
89
|
+
[:prefix, [:resolve, "c"], "--"]
|
90
|
+
]
|
91
|
+
],
|
92
|
+
@parser.parse("a = b\n--c"))
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_insertion_after_continue
|
96
|
+
assert_sexp(
|
97
|
+
[
|
98
|
+
[:continue],
|
99
|
+
[:expression, [:resolve, "foo"]]
|
100
|
+
],
|
101
|
+
@parser.parse("continue\nfoo"))
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_insertion_after_break
|
105
|
+
assert_sexp(
|
106
|
+
[
|
107
|
+
[:break],
|
108
|
+
[:expression, [:resolve, "foo"]]
|
109
|
+
],
|
110
|
+
@parser.parse("break\nfoo"))
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_insertion_after_return
|
114
|
+
assert_sexp(
|
115
|
+
[
|
116
|
+
[:return],
|
117
|
+
[:expression, [:resolve, "foo"]]
|
118
|
+
],
|
119
|
+
@parser.parse("return\nfoo"))
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_insertion_after_throw
|
123
|
+
assert_nil @parser.parse("throw\nfoo")
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_no_empty_statement_insertion
|
127
|
+
assert_nil @parser.parse("if (a > b)\nelse c = d")
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_no_for_insertion
|
131
|
+
assert_nil @parser.parse("for (a;b\n){}")
|
132
|
+
end
|
133
|
+
|
134
|
+
def assert_sexp(expected, node)
|
135
|
+
assert_equal(expected, node.to_sexp)
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/helper"
|
2
|
+
|
3
|
+
class BlockNodeTest < NodeTestCase
|
4
|
+
def test_to_sexp
|
5
|
+
initializer = AssignExprNode.new(NumberNode.new(10))
|
6
|
+
var_foo = VarDeclNode.new('foo', initializer)
|
7
|
+
|
8
|
+
node = BlockNode.new(SourceElementsNode.new([]))
|
9
|
+
assert_sexp([:block, []], node)
|
10
|
+
|
11
|
+
node = BlockNode.new(SourceElementsNode.new([var_foo]))
|
12
|
+
assert_sexp([:block, [[:var_decl, :foo, [:assign, [:lit, 10]]]]], node)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/helper"
|
2
|
+
|
3
|
+
class BracketAccessorNodeTest < NodeTestCase
|
4
|
+
def test_sexp
|
5
|
+
resolve = ResolveNode.new('foo')
|
6
|
+
index = NumberNode.new(10)
|
7
|
+
node = BracketAccessorNode.new(resolve, index)
|
8
|
+
assert_sexp(
|
9
|
+
[:bracket_access,
|
10
|
+
[:resolve, 'foo'],
|
11
|
+
[:lit, 10],
|
12
|
+
],
|
13
|
+
node
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/helper"
|
2
|
+
|
3
|
+
class CaseBlockNodeTest < NodeTestCase
|
4
|
+
def test_to_sexp
|
5
|
+
clause = CaseClauseNode.new( ResolveNode.new('foo'),
|
6
|
+
SourceElementsNode.new([ResolveNode.new('bar')]))
|
7
|
+
node = CaseBlockNode.new([clause])
|
8
|
+
assert_sexp([:case_block, [[:case, [:resolve, 'foo'], [[:resolve, 'bar']]]]],
|
9
|
+
node)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/helper"
|
2
|
+
|
3
|
+
class CaseClauseNodeTest < NodeTestCase
|
4
|
+
def test_to_sexp
|
5
|
+
node = CaseClauseNode.new(ResolveNode.new('foo'))
|
6
|
+
assert_sexp([:case, [:resolve, 'foo'], []], node)
|
7
|
+
|
8
|
+
node = CaseClauseNode.new(nil)
|
9
|
+
assert_sexp([:case, nil, []], node)
|
10
|
+
|
11
|
+
node = CaseClauseNode.new( ResolveNode.new('foo'),
|
12
|
+
SourceElementsNode.new([ResolveNode.new('bar')]))
|
13
|
+
assert_sexp([:case, [:resolve, 'foo'], [[:resolve, 'bar']]], node)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/helper"
|
2
|
+
|
3
|
+
class CharPosTest < NodeTestCase
|
4
|
+
def test_advancing_empty_position
|
5
|
+
a = RKelly::CharPos::EMPTY
|
6
|
+
b = a.next("foo")
|
7
|
+
|
8
|
+
assert_equal(1, b.line)
|
9
|
+
assert_equal(3, b.char)
|
10
|
+
assert_equal(2, b.index)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_advancing_with_single_line_string
|
14
|
+
a = RKelly::CharPos.new(3,5,22)
|
15
|
+
b = a.next("foo bar")
|
16
|
+
|
17
|
+
assert_equal(3, b.line)
|
18
|
+
assert_equal(12, b.char)
|
19
|
+
assert_equal(29, b.index)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_advancing_with_multi_line_string
|
23
|
+
a = RKelly::CharPos.new(3,5,22)
|
24
|
+
b = a.next("\nfoo\nbar\nbaz")
|
25
|
+
|
26
|
+
assert_equal(6, b.line)
|
27
|
+
assert_equal(3, b.char)
|
28
|
+
assert_equal(34, b.index)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_advancing_with_multi_line_string_ending_with_newline
|
32
|
+
a = RKelly::CharPos.new(3,5,22)
|
33
|
+
b = a.next("\nfoo\nbar\n")
|
34
|
+
|
35
|
+
assert_equal(6, b.line)
|
36
|
+
assert_equal(0, b.char)
|
37
|
+
assert_equal(31, b.index)
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/helper"
|
2
|
+
|
3
|
+
class CharRangeTest < NodeTestCase
|
4
|
+
def test_advancing_empty_range
|
5
|
+
a = RKelly::CharRange::EMPTY
|
6
|
+
b = a.next("foo")
|
7
|
+
|
8
|
+
assert_equal(1, b.from.line)
|
9
|
+
assert_equal(1, b.from.char)
|
10
|
+
assert_equal(0, b.from.index)
|
11
|
+
|
12
|
+
assert_equal(1, b.to.line)
|
13
|
+
assert_equal(3, b.to.char)
|
14
|
+
assert_equal(2, b.to.index)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_advancing_with_multiline_string
|
18
|
+
a = RKelly::CharRange.new(RKelly::CharPos.new(1,1,0), RKelly::CharPos.new(1,1,0))
|
19
|
+
b = a.next("foo\nblah")
|
20
|
+
|
21
|
+
assert_equal(1, b.from.line)
|
22
|
+
assert_equal(2, b.from.char)
|
23
|
+
assert_equal(1, b.from.index)
|
24
|
+
|
25
|
+
assert_equal(2, b.to.line)
|
26
|
+
assert_equal(4, b.to.char)
|
27
|
+
assert_equal(8, b.to.index)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/helper"
|
2
|
+
|
3
|
+
class CommaNodeTest < NodeTestCase
|
4
|
+
def test_to_sexp
|
5
|
+
left = OpEqualNode.new(ResolveNode.new('foo'), NumberNode.new(10))
|
6
|
+
right = OpEqualNode.new(ResolveNode.new('bar'), NumberNode.new(11))
|
7
|
+
node = CommaNode.new(left, right)
|
8
|
+
assert_sexp([:comma,
|
9
|
+
[:op_equal, [:resolve, 'foo'], [:lit, 10]],
|
10
|
+
[:op_equal, [:resolve, 'bar'], [:lit, 11]]],
|
11
|
+
node)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/helper"
|
2
|
+
|
3
|
+
class CommentsTest < NodeTestCase
|
4
|
+
def test_some_comments
|
5
|
+
parser = RKelly::Parser.new
|
6
|
+
ast = parser.parse(<<-eojs)
|
7
|
+
/**
|
8
|
+
* This is an awesome test comment.
|
9
|
+
*/
|
10
|
+
function aaron() { // This is a side comment
|
11
|
+
var x = 10;
|
12
|
+
return 1 + 1; // America!
|
13
|
+
}
|
14
|
+
eojs
|
15
|
+
|
16
|
+
assert ast
|
17
|
+
assert_equal(3, ast.comments.length)
|
18
|
+
assert_match('awesome', ast.comments[0].value)
|
19
|
+
assert_match('side', ast.comments[1].value)
|
20
|
+
assert_match('America', ast.comments[2].value)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_only_comments
|
24
|
+
parser = RKelly::Parser.new
|
25
|
+
ast = parser.parse(<<-eojs)
|
26
|
+
/**
|
27
|
+
* The first comment
|
28
|
+
*/
|
29
|
+
/**
|
30
|
+
* This is an awesome test comment.
|
31
|
+
*/
|
32
|
+
eojs
|
33
|
+
|
34
|
+
assert ast
|
35
|
+
assert_equal(2, ast.comments.length)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_empty_source_results_in_zero_comments
|
39
|
+
parser = RKelly::Parser.new
|
40
|
+
ast = parser.parse("")
|
41
|
+
|
42
|
+
assert ast
|
43
|
+
assert_equal(0, ast.comments.length)
|
44
|
+
end
|
45
|
+
end
|