koi-reference-parser 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -3
- data/MIT-LICENSE +19 -19
- data/README.rdoc +43 -43
- data/Rakefile +42 -42
- data/VERSION +1 -0
- data/lib/koi-reference-parser.rb +8 -8
- data/lib/parser/exceptions.rb +1 -1
- data/lib/parser/koi-reference-parser.treetop +197 -197
- data/lib/parser/parser.rb +42 -42
- data/lib/parser/syntax_node_extensions.rb +20 -0
- data/lib/parser/syntax_nodes.rb +113 -113
- data/test/parser/functional/function_call_as_argument.rb +16 -16
- data/test/parser/functional/simple_program_test.rb +34 -34
- data/test/parser/unit/assignment_test.rb +114 -114
- data/test/parser/unit/compound_expression_test.rb +34 -34
- data/test/parser/unit/function_call_test.rb +51 -51
- data/test/parser/unit/function_definition_test.rb +18 -18
- data/test/parser/unit/hash_accessor_test.rb +40 -40
- data/test/parser/unit/identifier_test.rb +54 -54
- data/test/parser/unit/if_test.rb +24 -24
- data/test/parser/unit/simple_expression_test.rb +211 -211
- data/test/parser/unit/statement_test.rb +21 -21
- data/test/parser/unit/syntax_node_to_hash_test.rb +43 -0
- data/test/parser/unit/unless_test.rb +24 -24
- data/test/setup/test_unit_extensions.rb +20 -20
- data/test/test_helper.rb +9 -9
- metadata +11 -4
@@ -1,35 +1,35 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper.rb'))
|
2
|
-
|
3
|
-
class SimpleExpressionTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
include KoiReferenceParser
|
6
|
-
|
7
|
-
test "should parse expression that contains function call as value" do
|
8
|
-
tree = Parser.parse('test = blah(1) + 1')
|
9
|
-
assert_kind_of Assignment, tree.elements.first.elements.last
|
10
|
-
assert_kind_of Expression, tree.elements.first.elements.last.elements[2]
|
11
|
-
assert_kind_of AdditiveExpression, tree.elements.first.elements.last.elements[2].elements.first
|
12
|
-
assert_kind_of FunctionCall, tree.elements.first.elements.last.elements[2].elements.first.elements.first
|
13
|
-
end
|
14
|
-
|
15
|
-
test "should parse expression that contains sub-expression as value" do
|
16
|
-
tree = Parser.parse('test = 2 * 3 * 2')
|
17
|
-
assert_kind_of Assignment, tree.elements.first.elements.last
|
18
|
-
assert_kind_of Expression, tree.elements.first.elements.last.elements[2]
|
19
|
-
assert_kind_of MultitiveExpression, tree.elements.first.elements.last.elements[2].elements.first
|
20
|
-
assert_kind_of IntegerLiteral, tree.elements.first.elements.last.elements[2].elements.first.elements[0]
|
21
|
-
assert_kind_of MultiplicationOperator, tree.elements.first.elements.last.elements[2].elements.first.elements[1]
|
22
|
-
assert_kind_of MultitiveExpression, tree.elements.first.elements.last.elements[2].elements.first.elements[2]
|
23
|
-
end
|
24
|
-
|
25
|
-
test "should parse expression that contains parenthesized sub-expression as value" do
|
26
|
-
tree = Parser.parse('test = (2 * 3) * 2')
|
27
|
-
assert_kind_of Assignment, tree.elements.first.elements.last
|
28
|
-
assert_kind_of Expression, tree.elements.first.elements.last.elements[2]
|
29
|
-
assert_kind_of MultitiveExpression, tree.elements.first.elements.last.elements[2].elements.first
|
30
|
-
assert_kind_of Expression, tree.elements.first.elements.last.elements[2].elements.first.elements[0]
|
31
|
-
assert_kind_of MultiplicationOperator, tree.elements.first.elements.last.elements[2].elements.first.elements[1]
|
32
|
-
assert_kind_of IntegerLiteral, tree.elements.first.elements.last.elements[2].elements.first.elements[2]
|
33
|
-
end
|
34
|
-
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper.rb'))
|
2
|
+
|
3
|
+
class SimpleExpressionTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include KoiReferenceParser
|
6
|
+
|
7
|
+
test "should parse expression that contains function call as value" do
|
8
|
+
tree = Parser.parse('test = blah(1) + 1')
|
9
|
+
assert_kind_of Assignment, tree.elements.first.elements.last
|
10
|
+
assert_kind_of Expression, tree.elements.first.elements.last.elements[2]
|
11
|
+
assert_kind_of AdditiveExpression, tree.elements.first.elements.last.elements[2].elements.first
|
12
|
+
assert_kind_of FunctionCall, tree.elements.first.elements.last.elements[2].elements.first.elements.first
|
13
|
+
end
|
14
|
+
|
15
|
+
test "should parse expression that contains sub-expression as value" do
|
16
|
+
tree = Parser.parse('test = 2 * 3 * 2')
|
17
|
+
assert_kind_of Assignment, tree.elements.first.elements.last
|
18
|
+
assert_kind_of Expression, tree.elements.first.elements.last.elements[2]
|
19
|
+
assert_kind_of MultitiveExpression, tree.elements.first.elements.last.elements[2].elements.first
|
20
|
+
assert_kind_of IntegerLiteral, tree.elements.first.elements.last.elements[2].elements.first.elements[0]
|
21
|
+
assert_kind_of MultiplicationOperator, tree.elements.first.elements.last.elements[2].elements.first.elements[1]
|
22
|
+
assert_kind_of MultitiveExpression, tree.elements.first.elements.last.elements[2].elements.first.elements[2]
|
23
|
+
end
|
24
|
+
|
25
|
+
test "should parse expression that contains parenthesized sub-expression as value" do
|
26
|
+
tree = Parser.parse('test = (2 * 3) * 2')
|
27
|
+
assert_kind_of Assignment, tree.elements.first.elements.last
|
28
|
+
assert_kind_of Expression, tree.elements.first.elements.last.elements[2]
|
29
|
+
assert_kind_of MultitiveExpression, tree.elements.first.elements.last.elements[2].elements.first
|
30
|
+
assert_kind_of Expression, tree.elements.first.elements.last.elements[2].elements.first.elements[0]
|
31
|
+
assert_kind_of MultiplicationOperator, tree.elements.first.elements.last.elements[2].elements.first.elements[1]
|
32
|
+
assert_kind_of IntegerLiteral, tree.elements.first.elements.last.elements[2].elements.first.elements[2]
|
33
|
+
end
|
34
|
+
|
35
35
|
end
|
@@ -1,52 +1,52 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper.rb'))
|
2
|
-
|
3
|
-
class FunctionCallTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
include KoiReferenceParser
|
6
|
-
|
7
|
-
test "should parse function call with no arguments" do
|
8
|
-
tree = Parser.parse('test()')
|
9
|
-
assert_kind_of Block, tree
|
10
|
-
assert_kind_of Statement, tree.elements.first
|
11
|
-
assert_kind_of FunctionCall, tree.elements.first.elements.last
|
12
|
-
assert_kind_of Identifier, tree.elements.first.elements.last.elements.first
|
13
|
-
end
|
14
|
-
|
15
|
-
test "should parse function call with identifier as argument" do
|
16
|
-
tree = Parser.parse('test(blah)')
|
17
|
-
assert_kind_of Block, tree
|
18
|
-
assert_kind_of Statement, tree.elements.first
|
19
|
-
assert_kind_of FunctionCall, tree.elements.first.elements.last
|
20
|
-
assert_kind_of Identifier, tree.elements.first.elements.last.elements[0]
|
21
|
-
assert_kind_of Expression, tree.elements.first.elements.last.elements[1]
|
22
|
-
end
|
23
|
-
|
24
|
-
test "should parse function call with multiple arguments" do
|
25
|
-
tree = Parser.parse('test(blah, blah2)')
|
26
|
-
assert_kind_of Block, tree
|
27
|
-
assert_kind_of Statement, tree.elements.first
|
28
|
-
assert_kind_of FunctionCall, tree.elements.first.elements.last
|
29
|
-
assert_kind_of Identifier, tree.elements.first.elements.last.elements[0]
|
30
|
-
assert_kind_of Expression, tree.elements.first.elements.last.elements[1]
|
31
|
-
assert_kind_of Expression, tree.elements.first.elements.last.elements[2]
|
32
|
-
end
|
33
|
-
|
34
|
-
test "should parse function call with expression as argument" do
|
35
|
-
tree = Parser.parse('test(1 * 2)')
|
36
|
-
assert_kind_of Block, tree
|
37
|
-
assert_kind_of Statement, tree.elements.first
|
38
|
-
assert_kind_of FunctionCall, tree.elements.first.elements.last
|
39
|
-
assert_kind_of Identifier, tree.elements.first.elements.last.elements[0]
|
40
|
-
assert_kind_of Expression, tree.elements.first.elements.last.elements[1]
|
41
|
-
end
|
42
|
-
|
43
|
-
test "should parse function call with function call as argument" do
|
44
|
-
tree = Parser.parse('test( call())')
|
45
|
-
assert_kind_of Block, tree
|
46
|
-
assert_kind_of Statement, tree.elements.first
|
47
|
-
assert_kind_of FunctionCall, tree.elements.first.elements.last
|
48
|
-
assert_kind_of Identifier, tree.elements.first.elements.last.elements[0]
|
49
|
-
assert_kind_of Expression, tree.elements.first.elements.last.elements[1]
|
50
|
-
end
|
51
|
-
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper.rb'))
|
2
|
+
|
3
|
+
class FunctionCallTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include KoiReferenceParser
|
6
|
+
|
7
|
+
test "should parse function call with no arguments" do
|
8
|
+
tree = Parser.parse('test()')
|
9
|
+
assert_kind_of Block, tree
|
10
|
+
assert_kind_of Statement, tree.elements.first
|
11
|
+
assert_kind_of FunctionCall, tree.elements.first.elements.last
|
12
|
+
assert_kind_of Identifier, tree.elements.first.elements.last.elements.first
|
13
|
+
end
|
14
|
+
|
15
|
+
test "should parse function call with identifier as argument" do
|
16
|
+
tree = Parser.parse('test(blah)')
|
17
|
+
assert_kind_of Block, tree
|
18
|
+
assert_kind_of Statement, tree.elements.first
|
19
|
+
assert_kind_of FunctionCall, tree.elements.first.elements.last
|
20
|
+
assert_kind_of Identifier, tree.elements.first.elements.last.elements[0]
|
21
|
+
assert_kind_of Expression, tree.elements.first.elements.last.elements[1]
|
22
|
+
end
|
23
|
+
|
24
|
+
test "should parse function call with multiple arguments" do
|
25
|
+
tree = Parser.parse('test(blah, blah2)')
|
26
|
+
assert_kind_of Block, tree
|
27
|
+
assert_kind_of Statement, tree.elements.first
|
28
|
+
assert_kind_of FunctionCall, tree.elements.first.elements.last
|
29
|
+
assert_kind_of Identifier, tree.elements.first.elements.last.elements[0]
|
30
|
+
assert_kind_of Expression, tree.elements.first.elements.last.elements[1]
|
31
|
+
assert_kind_of Expression, tree.elements.first.elements.last.elements[2]
|
32
|
+
end
|
33
|
+
|
34
|
+
test "should parse function call with expression as argument" do
|
35
|
+
tree = Parser.parse('test(1 * 2)')
|
36
|
+
assert_kind_of Block, tree
|
37
|
+
assert_kind_of Statement, tree.elements.first
|
38
|
+
assert_kind_of FunctionCall, tree.elements.first.elements.last
|
39
|
+
assert_kind_of Identifier, tree.elements.first.elements.last.elements[0]
|
40
|
+
assert_kind_of Expression, tree.elements.first.elements.last.elements[1]
|
41
|
+
end
|
42
|
+
|
43
|
+
test "should parse function call with function call as argument" do
|
44
|
+
tree = Parser.parse('test( call())')
|
45
|
+
assert_kind_of Block, tree
|
46
|
+
assert_kind_of Statement, tree.elements.first
|
47
|
+
assert_kind_of FunctionCall, tree.elements.first.elements.last
|
48
|
+
assert_kind_of Identifier, tree.elements.first.elements.last.elements[0]
|
49
|
+
assert_kind_of Expression, tree.elements.first.elements.last.elements[1]
|
50
|
+
end
|
51
|
+
|
52
52
|
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper.rb'))
|
2
|
-
|
3
|
-
class FunctionDefinitionTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
include KoiReferenceParser
|
6
|
-
|
7
|
-
test "should parse function definition including it's statements" do
|
8
|
-
tree = Parser.parse("test = function(args)\n teest1 = 1\n test2 = 2\nend")
|
9
|
-
assert_kind_of Block, tree
|
10
|
-
assert_kind_of Statement, tree.elements.first
|
11
|
-
assert_kind_of Assignment, tree.elements.first.elements.first
|
12
|
-
assert_kind_of FunctionDefinition, tree.elements.first.elements.first.elements.last
|
13
|
-
assert_kind_of Identifier, tree.elements.first.elements.first.elements.last.elements.first
|
14
|
-
assert_kind_of Block, tree.elements.first.elements.first.elements.last.elements.last
|
15
|
-
assert_kind_of Statement, tree.elements.first.elements.first.elements.last.elements.last.elements[0]
|
16
|
-
assert_kind_of Statement, tree.elements.first.elements.first.elements.last.elements.last.elements[1]
|
17
|
-
end
|
18
|
-
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper.rb'))
|
2
|
+
|
3
|
+
class FunctionDefinitionTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include KoiReferenceParser
|
6
|
+
|
7
|
+
test "should parse function definition including it's statements" do
|
8
|
+
tree = Parser.parse("test = function(args)\n teest1 = 1\n test2 = 2\nend")
|
9
|
+
assert_kind_of Block, tree
|
10
|
+
assert_kind_of Statement, tree.elements.first
|
11
|
+
assert_kind_of Assignment, tree.elements.first.elements.first
|
12
|
+
assert_kind_of FunctionDefinition, tree.elements.first.elements.first.elements.last
|
13
|
+
assert_kind_of Identifier, tree.elements.first.elements.first.elements.last.elements.first
|
14
|
+
assert_kind_of Block, tree.elements.first.elements.first.elements.last.elements.last
|
15
|
+
assert_kind_of Statement, tree.elements.first.elements.first.elements.last.elements.last.elements[0]
|
16
|
+
assert_kind_of Statement, tree.elements.first.elements.first.elements.last.elements.last.elements[1]
|
17
|
+
end
|
18
|
+
|
19
19
|
end
|
@@ -1,41 +1,41 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper.rb'))
|
2
|
-
|
3
|
-
class HashAccessorTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
include KoiReferenceParser
|
6
|
-
|
7
|
-
test "assignment to hash key" do
|
8
|
-
tree = Parser.parse('test[1] = 1')
|
9
|
-
assert_kind_of Block, tree
|
10
|
-
assert_kind_of Statement, tree.elements.first
|
11
|
-
assert_kind_of HashAssignment, tree.elements.first.elements.first
|
12
|
-
assert_kind_of Identifier, tree.elements.first.elements.first.elements.first
|
13
|
-
assert_kind_of HashAccessorList, tree.elements.first.elements.first.elements[1]
|
14
|
-
assert_kind_of HashAccessor, tree.elements.first.elements.first.elements[1].elements.first
|
15
|
-
assert_equal 1, tree.elements.first.elements.first.elements[1].elements.length
|
16
|
-
end
|
17
|
-
|
18
|
-
test "assignment to a chain of hash key" do
|
19
|
-
tree = Parser.parse('test[1][2][3] = 1')
|
20
|
-
assert_kind_of Block, tree
|
21
|
-
assert_kind_of Statement, tree.elements.first
|
22
|
-
assert_kind_of HashAssignment, tree.elements.first.elements.first
|
23
|
-
assert_kind_of Identifier, tree.elements.first.elements.first.elements.first
|
24
|
-
assert_kind_of HashAccessorList, tree.elements.first.elements.first.elements[1]
|
25
|
-
assert_kind_of HashAccessor, tree.elements.first.elements.first.elements[1].elements.first
|
26
|
-
assert_equal 3, tree.elements.first.elements.first.elements[1].elements.length
|
27
|
-
end
|
28
|
-
|
29
|
-
test "assignment of hash key" do
|
30
|
-
tree = Parser.parse('test = test[1]')
|
31
|
-
assert_kind_of Block, tree
|
32
|
-
assert_kind_of Statement, tree.elements.first
|
33
|
-
assert_kind_of Assignment, tree.elements.first.elements.first
|
34
|
-
assert_kind_of Identifier, tree.elements.first.elements.first.elements[0]
|
35
|
-
assert_kind_of Expression, tree.elements.first.elements.first.elements[2]
|
36
|
-
assert_kind_of HashAccess, tree.elements.first.elements.first.elements[2].elements.first
|
37
|
-
assert_kind_of Identifier, tree.elements.first.elements.first.elements[2].elements.first.elements[0]
|
38
|
-
assert_kind_of HashAccessorList, tree.elements.first.elements.first.elements[2].elements.first.elements[1]
|
39
|
-
end
|
40
|
-
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper.rb'))
|
2
|
+
|
3
|
+
class HashAccessorTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include KoiReferenceParser
|
6
|
+
|
7
|
+
test "assignment to hash key" do
|
8
|
+
tree = Parser.parse('test[1] = 1')
|
9
|
+
assert_kind_of Block, tree
|
10
|
+
assert_kind_of Statement, tree.elements.first
|
11
|
+
assert_kind_of HashAssignment, tree.elements.first.elements.first
|
12
|
+
assert_kind_of Identifier, tree.elements.first.elements.first.elements.first
|
13
|
+
assert_kind_of HashAccessorList, tree.elements.first.elements.first.elements[1]
|
14
|
+
assert_kind_of HashAccessor, tree.elements.first.elements.first.elements[1].elements.first
|
15
|
+
assert_equal 1, tree.elements.first.elements.first.elements[1].elements.length
|
16
|
+
end
|
17
|
+
|
18
|
+
test "assignment to a chain of hash key" do
|
19
|
+
tree = Parser.parse('test[1][2][3] = 1')
|
20
|
+
assert_kind_of Block, tree
|
21
|
+
assert_kind_of Statement, tree.elements.first
|
22
|
+
assert_kind_of HashAssignment, tree.elements.first.elements.first
|
23
|
+
assert_kind_of Identifier, tree.elements.first.elements.first.elements.first
|
24
|
+
assert_kind_of HashAccessorList, tree.elements.first.elements.first.elements[1]
|
25
|
+
assert_kind_of HashAccessor, tree.elements.first.elements.first.elements[1].elements.first
|
26
|
+
assert_equal 3, tree.elements.first.elements.first.elements[1].elements.length
|
27
|
+
end
|
28
|
+
|
29
|
+
test "assignment of hash key" do
|
30
|
+
tree = Parser.parse('test = test[1]')
|
31
|
+
assert_kind_of Block, tree
|
32
|
+
assert_kind_of Statement, tree.elements.first
|
33
|
+
assert_kind_of Assignment, tree.elements.first.elements.first
|
34
|
+
assert_kind_of Identifier, tree.elements.first.elements.first.elements[0]
|
35
|
+
assert_kind_of Expression, tree.elements.first.elements.first.elements[2]
|
36
|
+
assert_kind_of HashAccess, tree.elements.first.elements.first.elements[2].elements.first
|
37
|
+
assert_kind_of Identifier, tree.elements.first.elements.first.elements[2].elements.first.elements[0]
|
38
|
+
assert_kind_of HashAccessorList, tree.elements.first.elements.first.elements[2].elements.first.elements[1]
|
39
|
+
end
|
40
|
+
|
41
41
|
end
|
@@ -1,55 +1,55 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper.rb'))
|
2
|
-
|
3
|
-
class FunctionCallTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
include KoiReferenceParser
|
6
|
-
|
7
|
-
test "should parse all lowercase identifier" do
|
8
|
-
tree = Parser.parse('test = "test"')
|
9
|
-
assert_kind_of Block, tree
|
10
|
-
assert_kind_of Statement, tree.elements.first
|
11
|
-
assert_kind_of Assignment, tree.elements.first.elements.last
|
12
|
-
assert_kind_of Identifier, tree.elements.first.elements.last.elements.first
|
13
|
-
end
|
14
|
-
|
15
|
-
test "should parse identifier with trailing numeral" do
|
16
|
-
tree = Parser.parse('test1 = "test"')
|
17
|
-
assert_kind_of Block, tree
|
18
|
-
assert_kind_of Statement, tree.elements.first
|
19
|
-
assert_kind_of Assignment, tree.elements.first.elements.last
|
20
|
-
assert_kind_of Identifier, tree.elements.first.elements.last.elements.first
|
21
|
-
end
|
22
|
-
|
23
|
-
test "should parse identifier with leading capital letter" do
|
24
|
-
tree = Parser.parse('Test = "test"')
|
25
|
-
assert_kind_of Block, tree
|
26
|
-
assert_kind_of Statement, tree.elements.first
|
27
|
-
assert_kind_of Assignment, tree.elements.first.elements.last
|
28
|
-
assert_kind_of Identifier, tree.elements.first.elements.last.elements.first
|
29
|
-
end
|
30
|
-
|
31
|
-
test "should parse identifier that contains an underscore" do
|
32
|
-
tree = Parser.parse('test_test = "test"')
|
33
|
-
assert_kind_of Block, tree
|
34
|
-
assert_kind_of Statement, tree.elements.first
|
35
|
-
assert_kind_of Assignment, tree.elements.first.elements.last
|
36
|
-
assert_kind_of Identifier, tree.elements.first.elements.last.elements.first
|
37
|
-
end
|
38
|
-
|
39
|
-
test "should parse single character identifier" do
|
40
|
-
tree = Parser.parse('x = "test"')
|
41
|
-
assert_kind_of Block, tree
|
42
|
-
assert_kind_of Statement, tree.elements.first
|
43
|
-
assert_kind_of Assignment, tree.elements.first.elements.last
|
44
|
-
assert_kind_of Identifier, tree.elements.first.elements.last.elements.first
|
45
|
-
end
|
46
|
-
|
47
|
-
test "should parse identifier with leading $" do
|
48
|
-
tree = Parser.parse('$test = "test"')
|
49
|
-
assert_kind_of Block, tree
|
50
|
-
assert_kind_of Statement, tree.elements.first
|
51
|
-
assert_kind_of Assignment, tree.elements.first.elements.last
|
52
|
-
assert_kind_of Identifier, tree.elements.first.elements.last.elements.first
|
53
|
-
end
|
54
|
-
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper.rb'))
|
2
|
+
|
3
|
+
class FunctionCallTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include KoiReferenceParser
|
6
|
+
|
7
|
+
test "should parse all lowercase identifier" do
|
8
|
+
tree = Parser.parse('test = "test"')
|
9
|
+
assert_kind_of Block, tree
|
10
|
+
assert_kind_of Statement, tree.elements.first
|
11
|
+
assert_kind_of Assignment, tree.elements.first.elements.last
|
12
|
+
assert_kind_of Identifier, tree.elements.first.elements.last.elements.first
|
13
|
+
end
|
14
|
+
|
15
|
+
test "should parse identifier with trailing numeral" do
|
16
|
+
tree = Parser.parse('test1 = "test"')
|
17
|
+
assert_kind_of Block, tree
|
18
|
+
assert_kind_of Statement, tree.elements.first
|
19
|
+
assert_kind_of Assignment, tree.elements.first.elements.last
|
20
|
+
assert_kind_of Identifier, tree.elements.first.elements.last.elements.first
|
21
|
+
end
|
22
|
+
|
23
|
+
test "should parse identifier with leading capital letter" do
|
24
|
+
tree = Parser.parse('Test = "test"')
|
25
|
+
assert_kind_of Block, tree
|
26
|
+
assert_kind_of Statement, tree.elements.first
|
27
|
+
assert_kind_of Assignment, tree.elements.first.elements.last
|
28
|
+
assert_kind_of Identifier, tree.elements.first.elements.last.elements.first
|
29
|
+
end
|
30
|
+
|
31
|
+
test "should parse identifier that contains an underscore" do
|
32
|
+
tree = Parser.parse('test_test = "test"')
|
33
|
+
assert_kind_of Block, tree
|
34
|
+
assert_kind_of Statement, tree.elements.first
|
35
|
+
assert_kind_of Assignment, tree.elements.first.elements.last
|
36
|
+
assert_kind_of Identifier, tree.elements.first.elements.last.elements.first
|
37
|
+
end
|
38
|
+
|
39
|
+
test "should parse single character identifier" do
|
40
|
+
tree = Parser.parse('x = "test"')
|
41
|
+
assert_kind_of Block, tree
|
42
|
+
assert_kind_of Statement, tree.elements.first
|
43
|
+
assert_kind_of Assignment, tree.elements.first.elements.last
|
44
|
+
assert_kind_of Identifier, tree.elements.first.elements.last.elements.first
|
45
|
+
end
|
46
|
+
|
47
|
+
test "should parse identifier with leading $" do
|
48
|
+
tree = Parser.parse('$test = "test"')
|
49
|
+
assert_kind_of Block, tree
|
50
|
+
assert_kind_of Statement, tree.elements.first
|
51
|
+
assert_kind_of Assignment, tree.elements.first.elements.last
|
52
|
+
assert_kind_of Identifier, tree.elements.first.elements.last.elements.first
|
53
|
+
end
|
54
|
+
|
55
55
|
end
|
data/test/parser/unit/if_test.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper.rb'))
|
2
|
-
|
3
|
-
class IfTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
include KoiReferenceParser
|
6
|
-
|
7
|
-
test "should parse if statement" do
|
8
|
-
tree = Parser.parse("if(1 == 1)\n test = 1\nend")
|
9
|
-
assert_kind_of Block, tree
|
10
|
-
assert_kind_of Statement, tree.elements.first
|
11
|
-
assert_kind_of If, tree.elements.first.elements.first
|
12
|
-
assert_kind_of Expression, tree.elements.first.elements.first.elements.first
|
13
|
-
assert_kind_of Block, tree.elements.first.elements.first.elements.last
|
14
|
-
end
|
15
|
-
|
16
|
-
test "should parse single line if statement" do
|
17
|
-
tree = Parser.parse("if(1 == 1) test = 1; end")
|
18
|
-
assert_kind_of Block, tree
|
19
|
-
assert_kind_of Statement, tree.elements.first
|
20
|
-
assert_kind_of If, tree.elements.first.elements.first
|
21
|
-
assert_kind_of Expression, tree.elements.first.elements.first.elements.first
|
22
|
-
assert_kind_of Block, tree.elements.first.elements.first.elements.last
|
23
|
-
end
|
24
|
-
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper.rb'))
|
2
|
+
|
3
|
+
class IfTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include KoiReferenceParser
|
6
|
+
|
7
|
+
test "should parse if statement" do
|
8
|
+
tree = Parser.parse("if(1 == 1)\n test = 1\nend")
|
9
|
+
assert_kind_of Block, tree
|
10
|
+
assert_kind_of Statement, tree.elements.first
|
11
|
+
assert_kind_of If, tree.elements.first.elements.first
|
12
|
+
assert_kind_of Expression, tree.elements.first.elements.first.elements.first
|
13
|
+
assert_kind_of Block, tree.elements.first.elements.first.elements.last
|
14
|
+
end
|
15
|
+
|
16
|
+
test "should parse single line if statement" do
|
17
|
+
tree = Parser.parse("if(1 == 1) test = 1; end")
|
18
|
+
assert_kind_of Block, tree
|
19
|
+
assert_kind_of Statement, tree.elements.first
|
20
|
+
assert_kind_of If, tree.elements.first.elements.first
|
21
|
+
assert_kind_of Expression, tree.elements.first.elements.first.elements.first
|
22
|
+
assert_kind_of Block, tree.elements.first.elements.first.elements.last
|
23
|
+
end
|
24
|
+
|
25
25
|
end
|