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.
@@ -1,212 +1,212 @@
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
- ###############
8
- # ADDITION
9
-
10
- test "should parse simple addition expression with integers" do
11
- tree = Parser.parse('test = 1 + 1')
12
- assert_expression(tree, AdditionOperator)
13
- end
14
-
15
- test "should parse simple addition expression with floats" do
16
- tree = Parser.parse('test = 1.0 + 1.0')
17
- assert_expression(tree, AdditionOperator)
18
- end
19
-
20
- test "should parse simple addition expression with strings" do
21
- tree = Parser.parse('test = "1" + "1"')
22
- assert_expression(tree, AdditionOperator)
23
- end
24
-
25
- test "should parse simple addition expression with identifiers" do
26
- tree = Parser.parse('test = test1 + test2')
27
- assert_expression(tree, AdditionOperator)
28
- end
29
-
30
-
31
- ###############
32
- # SUBTRACTION
33
-
34
- test "should parse simple subtraction expression with integers" do
35
- tree = Parser.parse('test = 1 - 1')
36
- assert_expression(tree, SubtractionOperator)
37
- end
38
-
39
- test "should parse simple subtraction expression with floats" do
40
- tree = Parser.parse('test = 1.0 - 1.0')
41
- assert_expression(tree, SubtractionOperator)
42
- end
43
-
44
- test "should parse simple subtraction expression with strings" do
45
- tree = Parser.parse('test = "1" - "1"')
46
- assert_expression(tree, SubtractionOperator)
47
- end
48
-
49
- test "should parse simple subtraction expression with identifiers" do
50
- tree = Parser.parse('test = test1 - test2')
51
- assert_expression(tree, SubtractionOperator)
52
- end
53
-
54
-
55
- ###############
56
- # MULTIPLICATION
57
-
58
- test "should parse simple multiplication expression with integers" do
59
- tree = Parser.parse('test = 1 * 1')
60
- assert_expression(tree, MultiplicationOperator)
61
- end
62
-
63
- test "should parse simple multiplication expression with floats" do
64
- tree = Parser.parse('test = 1.0 * 1.0')
65
- assert_expression(tree, MultiplicationOperator)
66
- end
67
-
68
- test "should parse simple multiplication expression with strings" do
69
- tree = Parser.parse('test = "1" * "1"')
70
- assert_expression(tree, MultiplicationOperator)
71
- end
72
-
73
- test "should parse simple multiplication expression with identifiers" do
74
- tree = Parser.parse('test = test1 * test2')
75
- assert_expression(tree, MultiplicationOperator)
76
- end
77
-
78
-
79
- ###############
80
- # DIVISION
81
-
82
- test "should parse simple division expression with integers" do
83
- tree = Parser.parse('test = 1 / 1')
84
- assert_expression(tree, DivisionOperator)
85
- end
86
-
87
- test "should parse simple division expression with floats" do
88
- tree = Parser.parse('test = 1.0 / 1.0')
89
- assert_expression(tree, DivisionOperator)
90
- end
91
-
92
- test "should parse simple division expression with strings" do
93
- tree = Parser.parse('test = "1" / "1"')
94
- assert_expression(tree, DivisionOperator)
95
- end
96
-
97
- test "should parse simple division expression with identifiers" do
98
- tree = Parser.parse('test = test1 / test2')
99
- assert_expression(tree, DivisionOperator)
100
- end
101
-
102
-
103
- ###############
104
- # EQUALITY
105
-
106
- test "should parse simple equality expression with integers" do
107
- tree = Parser.parse('test = 1 == 1')
108
- assert_expression(tree, EqualityOperator)
109
- end
110
-
111
- test "should parse simple equality expression with floats" do
112
- tree = Parser.parse('test = 1.0 == 1.0')
113
- assert_expression(tree, EqualityOperator)
114
- end
115
-
116
- test "should parse simple equality expression with strings" do
117
- tree = Parser.parse('test = "1" == "1"')
118
- assert_expression(tree, EqualityOperator)
119
- end
120
-
121
- test "should parse simple equality expression with identifiers" do
122
- tree = Parser.parse('test = test1 == test2')
123
- assert_expression(tree, EqualityOperator)
124
- end
125
-
126
-
127
- ###############
128
- # INEQUALITY
129
-
130
- test "should parse simple inequality expression with integers" do
131
- tree = Parser.parse('test = 1 != 1')
132
- assert_expression(tree, InequalityOperator)
133
- end
134
-
135
- test "should parse simple inequality expression with floats" do
136
- tree = Parser.parse('test = 1.0 != 1.0')
137
- assert_expression(tree, InequalityOperator)
138
- end
139
-
140
- test "should parse simple inequality expression with strings" do
141
- tree = Parser.parse('test = "1" != "1"')
142
- assert_expression(tree, InequalityOperator)
143
- end
144
-
145
- test "should parse simple inequality expression with identifiers" do
146
- tree = Parser.parse('test = test1 != test2')
147
- assert_expression(tree, InequalityOperator)
148
- end
149
-
150
-
151
- ###############
152
- # GREATER THAN
153
-
154
- test "should parse simple 'greater than' expression with integers" do
155
- tree = Parser.parse('test = 1 > 1')
156
- assert_expression(tree, GreaterThanOperator)
157
- end
158
-
159
- test "should parse simple 'greater than' expression with floats" do
160
- tree = Parser.parse('test = 1.0 > 1.0')
161
- assert_expression(tree, GreaterThanOperator)
162
- end
163
-
164
- test "should parse simple 'greater than' expression with strings" do
165
- tree = Parser.parse('test = "1" > "1"')
166
- assert_expression(tree, GreaterThanOperator)
167
- end
168
-
169
- test "should parse simple 'greater than' expression with identifiers" do
170
- tree = Parser.parse('test = test1 > test2')
171
- assert_expression(tree, GreaterThanOperator)
172
- end
173
-
174
-
175
- ###############
176
- # LESS THAN
177
-
178
- test "should parse simple 'less than' expression with integers" do
179
- tree = Parser.parse('test = 1 < 1')
180
- assert_expression(tree, LessThanOperator)
181
- end
182
-
183
- test "should parse simple 'less than' expression with floats" do
184
- tree = Parser.parse('test = 1.0 < 1.0')
185
- assert_expression(tree, LessThanOperator)
186
- end
187
-
188
- test "should parse simple 'less than' expression with strings" do
189
- tree = Parser.parse('test = "1" < "1"')
190
- assert_expression(tree, LessThanOperator)
191
- end
192
-
193
- test "should parse simple 'less than' expression with identifiers" do
194
- tree = Parser.parse('test = test1 < test2')
195
- assert_expression(tree, LessThanOperator)
196
- end
197
-
198
-
199
- private
200
-
201
- def assert_expression(tree, operator = nil)
202
- assert_kind_of Block, tree
203
- assert_kind_of Statement, tree.elements.first
204
- assert_kind_of Assignment, tree.elements.first.elements.last
205
- assert_kind_of Identifier, tree.elements.first.elements.last.elements[0]
206
- assert_kind_of AssignmentOperator, tree.elements.first.elements.last.elements[1]
207
- assert_kind_of Expression, tree.elements.first.elements.last.elements[2]
208
- assert_equal 3, tree.elements.first.elements.last.elements[2].elements.first.elements.size
209
- assert_kind_of operator, tree.elements.first.elements.last.elements[2].elements.first.elements[1] unless(operator.nil?)
210
- end
211
-
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
+ ###############
8
+ # ADDITION
9
+
10
+ test "should parse simple addition expression with integers" do
11
+ tree = Parser.parse('test = 1 + 1')
12
+ assert_expression(tree, AdditionOperator)
13
+ end
14
+
15
+ test "should parse simple addition expression with floats" do
16
+ tree = Parser.parse('test = 1.0 + 1.0')
17
+ assert_expression(tree, AdditionOperator)
18
+ end
19
+
20
+ test "should parse simple addition expression with strings" do
21
+ tree = Parser.parse('test = "1" + "1"')
22
+ assert_expression(tree, AdditionOperator)
23
+ end
24
+
25
+ test "should parse simple addition expression with identifiers" do
26
+ tree = Parser.parse('test = test1 + test2')
27
+ assert_expression(tree, AdditionOperator)
28
+ end
29
+
30
+
31
+ ###############
32
+ # SUBTRACTION
33
+
34
+ test "should parse simple subtraction expression with integers" do
35
+ tree = Parser.parse('test = 1 - 1')
36
+ assert_expression(tree, SubtractionOperator)
37
+ end
38
+
39
+ test "should parse simple subtraction expression with floats" do
40
+ tree = Parser.parse('test = 1.0 - 1.0')
41
+ assert_expression(tree, SubtractionOperator)
42
+ end
43
+
44
+ test "should parse simple subtraction expression with strings" do
45
+ tree = Parser.parse('test = "1" - "1"')
46
+ assert_expression(tree, SubtractionOperator)
47
+ end
48
+
49
+ test "should parse simple subtraction expression with identifiers" do
50
+ tree = Parser.parse('test = test1 - test2')
51
+ assert_expression(tree, SubtractionOperator)
52
+ end
53
+
54
+
55
+ ###############
56
+ # MULTIPLICATION
57
+
58
+ test "should parse simple multiplication expression with integers" do
59
+ tree = Parser.parse('test = 1 * 1')
60
+ assert_expression(tree, MultiplicationOperator)
61
+ end
62
+
63
+ test "should parse simple multiplication expression with floats" do
64
+ tree = Parser.parse('test = 1.0 * 1.0')
65
+ assert_expression(tree, MultiplicationOperator)
66
+ end
67
+
68
+ test "should parse simple multiplication expression with strings" do
69
+ tree = Parser.parse('test = "1" * "1"')
70
+ assert_expression(tree, MultiplicationOperator)
71
+ end
72
+
73
+ test "should parse simple multiplication expression with identifiers" do
74
+ tree = Parser.parse('test = test1 * test2')
75
+ assert_expression(tree, MultiplicationOperator)
76
+ end
77
+
78
+
79
+ ###############
80
+ # DIVISION
81
+
82
+ test "should parse simple division expression with integers" do
83
+ tree = Parser.parse('test = 1 / 1')
84
+ assert_expression(tree, DivisionOperator)
85
+ end
86
+
87
+ test "should parse simple division expression with floats" do
88
+ tree = Parser.parse('test = 1.0 / 1.0')
89
+ assert_expression(tree, DivisionOperator)
90
+ end
91
+
92
+ test "should parse simple division expression with strings" do
93
+ tree = Parser.parse('test = "1" / "1"')
94
+ assert_expression(tree, DivisionOperator)
95
+ end
96
+
97
+ test "should parse simple division expression with identifiers" do
98
+ tree = Parser.parse('test = test1 / test2')
99
+ assert_expression(tree, DivisionOperator)
100
+ end
101
+
102
+
103
+ ###############
104
+ # EQUALITY
105
+
106
+ test "should parse simple equality expression with integers" do
107
+ tree = Parser.parse('test = 1 == 1')
108
+ assert_expression(tree, EqualityOperator)
109
+ end
110
+
111
+ test "should parse simple equality expression with floats" do
112
+ tree = Parser.parse('test = 1.0 == 1.0')
113
+ assert_expression(tree, EqualityOperator)
114
+ end
115
+
116
+ test "should parse simple equality expression with strings" do
117
+ tree = Parser.parse('test = "1" == "1"')
118
+ assert_expression(tree, EqualityOperator)
119
+ end
120
+
121
+ test "should parse simple equality expression with identifiers" do
122
+ tree = Parser.parse('test = test1 == test2')
123
+ assert_expression(tree, EqualityOperator)
124
+ end
125
+
126
+
127
+ ###############
128
+ # INEQUALITY
129
+
130
+ test "should parse simple inequality expression with integers" do
131
+ tree = Parser.parse('test = 1 != 1')
132
+ assert_expression(tree, InequalityOperator)
133
+ end
134
+
135
+ test "should parse simple inequality expression with floats" do
136
+ tree = Parser.parse('test = 1.0 != 1.0')
137
+ assert_expression(tree, InequalityOperator)
138
+ end
139
+
140
+ test "should parse simple inequality expression with strings" do
141
+ tree = Parser.parse('test = "1" != "1"')
142
+ assert_expression(tree, InequalityOperator)
143
+ end
144
+
145
+ test "should parse simple inequality expression with identifiers" do
146
+ tree = Parser.parse('test = test1 != test2')
147
+ assert_expression(tree, InequalityOperator)
148
+ end
149
+
150
+
151
+ ###############
152
+ # GREATER THAN
153
+
154
+ test "should parse simple 'greater than' expression with integers" do
155
+ tree = Parser.parse('test = 1 > 1')
156
+ assert_expression(tree, GreaterThanOperator)
157
+ end
158
+
159
+ test "should parse simple 'greater than' expression with floats" do
160
+ tree = Parser.parse('test = 1.0 > 1.0')
161
+ assert_expression(tree, GreaterThanOperator)
162
+ end
163
+
164
+ test "should parse simple 'greater than' expression with strings" do
165
+ tree = Parser.parse('test = "1" > "1"')
166
+ assert_expression(tree, GreaterThanOperator)
167
+ end
168
+
169
+ test "should parse simple 'greater than' expression with identifiers" do
170
+ tree = Parser.parse('test = test1 > test2')
171
+ assert_expression(tree, GreaterThanOperator)
172
+ end
173
+
174
+
175
+ ###############
176
+ # LESS THAN
177
+
178
+ test "should parse simple 'less than' expression with integers" do
179
+ tree = Parser.parse('test = 1 < 1')
180
+ assert_expression(tree, LessThanOperator)
181
+ end
182
+
183
+ test "should parse simple 'less than' expression with floats" do
184
+ tree = Parser.parse('test = 1.0 < 1.0')
185
+ assert_expression(tree, LessThanOperator)
186
+ end
187
+
188
+ test "should parse simple 'less than' expression with strings" do
189
+ tree = Parser.parse('test = "1" < "1"')
190
+ assert_expression(tree, LessThanOperator)
191
+ end
192
+
193
+ test "should parse simple 'less than' expression with identifiers" do
194
+ tree = Parser.parse('test = test1 < test2')
195
+ assert_expression(tree, LessThanOperator)
196
+ end
197
+
198
+
199
+ private
200
+
201
+ def assert_expression(tree, operator = nil)
202
+ assert_kind_of Block, tree
203
+ assert_kind_of Statement, tree.elements.first
204
+ assert_kind_of Assignment, tree.elements.first.elements.last
205
+ assert_kind_of Identifier, tree.elements.first.elements.last.elements[0]
206
+ assert_kind_of AssignmentOperator, tree.elements.first.elements.last.elements[1]
207
+ assert_kind_of Expression, tree.elements.first.elements.last.elements[2]
208
+ assert_equal 3, tree.elements.first.elements.last.elements[2].elements.first.elements.size
209
+ assert_kind_of operator, tree.elements.first.elements.last.elements[2].elements.first.elements[1] unless(operator.nil?)
210
+ end
211
+
212
212
  end
@@ -1,22 +1,22 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper.rb'))
2
-
3
- class StatementTest < Test::Unit::TestCase
4
-
5
- include KoiReferenceParser
6
-
7
- test "should parse statments on separate lines as separate" do
8
- tree = Parser.parse("test = 1\ntest = 1")
9
- assert_kind_of Block, tree
10
- assert_kind_of Statement, tree.elements[0]
11
- assert_kind_of Statement, tree.elements[1]
12
- end
13
-
14
- test "should parse statements on same line separated by ';' as separate" do
15
- tree = Parser.parse("test = 1;test = 1")
16
- assert_kind_of Block, tree
17
- assert_kind_of Statement, tree.elements[0]
18
- assert_kind_of Statement, tree.elements[1]
19
- end
20
-
21
-
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper.rb'))
2
+
3
+ class StatementTest < Test::Unit::TestCase
4
+
5
+ include KoiReferenceParser
6
+
7
+ test "should parse statments on separate lines as separate" do
8
+ tree = Parser.parse("test = 1\ntest = 1")
9
+ assert_kind_of Block, tree
10
+ assert_kind_of Statement, tree.elements[0]
11
+ assert_kind_of Statement, tree.elements[1]
12
+ end
13
+
14
+ test "should parse statements on same line separated by ';' as separate" do
15
+ tree = Parser.parse("test = 1;test = 1")
16
+ assert_kind_of Block, tree
17
+ assert_kind_of Statement, tree.elements[0]
18
+ assert_kind_of Statement, tree.elements[1]
19
+ end
20
+
21
+
22
22
  end