ruby-lint 0.0.1a → 0.0.1a1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.yardopts +1 -1
- data/MANIFEST +65 -62
- data/README.md +114 -13
- data/bin/ruby-lint +6 -0
- data/lib/ruby-lint.rb +36 -0
- data/lib/{rlint → ruby-lint}/analyze/coding_style.rb +32 -32
- data/lib/{rlint → ruby-lint}/analyze/definitions.rb +13 -13
- data/lib/{rlint → ruby-lint}/analyze/method_validation.rb +5 -5
- data/lib/{rlint → ruby-lint}/analyze/shadowing_variables.rb +5 -5
- data/lib/{rlint → ruby-lint}/analyze/undefined_variables.rb +7 -7
- data/lib/{rlint → ruby-lint}/analyze/unused_variables.rb +6 -6
- data/lib/{rlint → ruby-lint}/callback.rb +11 -11
- data/lib/{rlint → ruby-lint}/cli.rb +17 -17
- data/lib/{rlint → ruby-lint}/constant_importer.rb +18 -8
- data/lib/{rlint → ruby-lint}/definition.rb +10 -10
- data/lib/{rlint → ruby-lint}/formatter/text.rb +6 -6
- data/lib/{rlint → ruby-lint}/helper/definition_resolver.rb +11 -11
- data/lib/{rlint → ruby-lint}/helper/scoping.rb +14 -14
- data/lib/{rlint → ruby-lint}/iterator.rb +22 -22
- data/lib/{rlint → ruby-lint}/options.rb +9 -9
- data/lib/{rlint → ruby-lint}/parser.rb +111 -111
- data/lib/{rlint → ruby-lint}/parser_error.rb +3 -3
- data/lib/{rlint → ruby-lint}/report.rb +8 -8
- data/lib/{rlint → ruby-lint}/token/assignment_token.rb +4 -4
- data/lib/{rlint → ruby-lint}/token/begin_rescue_token.rb +7 -7
- data/lib/{rlint → ruby-lint}/token/block_token.rb +12 -3
- data/lib/{rlint → ruby-lint}/token/case_token.rb +5 -5
- data/lib/{rlint → ruby-lint}/token/class_token.rb +3 -3
- data/lib/{rlint → ruby-lint}/token/method_definition_token.rb +8 -8
- data/lib/{rlint → ruby-lint}/token/method_token.rb +9 -7
- data/lib/{rlint → ruby-lint}/token/parameters_token.rb +6 -6
- data/lib/{rlint → ruby-lint}/token/regexp_token.rb +2 -2
- data/lib/{rlint → ruby-lint}/token/statement_token.rb +6 -6
- data/lib/{rlint → ruby-lint}/token/token.rb +8 -6
- data/lib/{rlint → ruby-lint}/token/variable_token.rb +3 -3
- data/lib/ruby-lint/version.rb +3 -0
- data/ruby-lint.gemspec +5 -5
- data/spec/benchmarks/memory.rb +7 -7
- data/spec/benchmarks/parse_parser.rb +5 -5
- data/spec/fixtures/stdlib/un.rb +348 -0
- data/spec/helper.rb +3 -1
- data/spec/{rlint → ruby-lint}/analyze/coding_style.rb +30 -30
- data/spec/ruby-lint/analyze/complex/un.rb +29 -0
- data/spec/{rlint → ruby-lint}/analyze/definitions/classes.rb +25 -25
- data/spec/{rlint → ruby-lint}/analyze/definitions/methods.rb +22 -22
- data/spec/{rlint → ruby-lint}/analyze/definitions/modules.rb +42 -42
- data/spec/{rlint → ruby-lint}/analyze/definitions/variables.rb +27 -27
- data/spec/{rlint → ruby-lint}/analyze/method_validation.rb +31 -31
- data/spec/{rlint → ruby-lint}/analyze/shadowing_variables.rb +6 -6
- data/spec/{rlint → ruby-lint}/analyze/undefined_variables.rb +37 -37
- data/spec/{rlint → ruby-lint}/analyze/unused_variables.rb +21 -21
- data/spec/{rlint → ruby-lint}/callback.rb +7 -7
- data/spec/{rlint → ruby-lint}/constant_importer.rb +6 -6
- data/spec/{rlint → ruby-lint}/definition.rb +25 -25
- data/spec/{rlint → ruby-lint}/formatter/text.rb +4 -4
- data/spec/{rlint → ruby-lint}/iterator.rb +38 -38
- data/spec/{rlint → ruby-lint}/parser/arrays.rb +28 -28
- data/spec/{rlint → ruby-lint}/parser/classes.rb +23 -23
- data/spec/{rlint → ruby-lint}/parser/errors.rb +4 -4
- data/spec/{rlint → ruby-lint}/parser/hashes.rb +24 -24
- data/spec/{rlint → ruby-lint}/parser/methods.rb +50 -50
- data/spec/{rlint → ruby-lint}/parser/modules.rb +8 -8
- data/spec/{rlint → ruby-lint}/parser/objects.rb +8 -8
- data/spec/{rlint → ruby-lint}/parser/operators.rb +14 -14
- data/spec/{rlint → ruby-lint}/parser/procs.rb +26 -26
- data/spec/{rlint → ruby-lint}/parser/ranges.rb +9 -9
- data/spec/{rlint → ruby-lint}/parser/regexp.rb +5 -5
- data/spec/{rlint → ruby-lint}/parser/scalars.rb +17 -17
- data/spec/{rlint → ruby-lint}/parser/statements.rb +94 -94
- data/spec/{rlint → ruby-lint}/parser/variables.rb +37 -37
- data/spec/{rlint → ruby-lint}/report.rb +4 -4
- data/task/manifest.rake +8 -0
- data/task/test.rake +1 -1
- metadata +69 -66
- data/bin/rlint +0 -6
- data/lib/rlint.rb +0 -36
- data/lib/rlint/version.rb +0 -3
@@ -1,10 +1,10 @@
|
|
1
1
|
require File.expand_path('../../../helper', __FILE__)
|
2
2
|
|
3
|
-
describe '
|
3
|
+
describe 'RubyLint::Parser' do
|
4
4
|
it 'Parse a return statement' do
|
5
|
-
token =
|
5
|
+
token = RubyLint::Parser.new('return 10').parse[0]
|
6
6
|
|
7
|
-
token.class.should ==
|
7
|
+
token.class.should == RubyLint::Token::StatementToken
|
8
8
|
token.type.should == :return
|
9
9
|
token.line.should == 1
|
10
10
|
token.column.should == 0
|
@@ -14,7 +14,7 @@ describe 'Rlint::Parser' do
|
|
14
14
|
|
15
15
|
val = token.value[0]
|
16
16
|
|
17
|
-
val.class.should ==
|
17
|
+
val.class.should == RubyLint::Token::Token
|
18
18
|
val.type.should == :integer
|
19
19
|
val.line.should == 1
|
20
20
|
val.column.should == 7
|
@@ -22,9 +22,9 @@ describe 'Rlint::Parser' do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'Parse a return statement with multiple return values' do
|
25
|
-
token =
|
25
|
+
token = RubyLint::Parser.new('return 10, 20').parse[0]
|
26
26
|
|
27
|
-
token.class.should ==
|
27
|
+
token.class.should == RubyLint::Token::StatementToken
|
28
28
|
token.type.should == :return
|
29
29
|
token.line.should == 1
|
30
30
|
token.column.should == 0
|
@@ -34,7 +34,7 @@ describe 'Rlint::Parser' do
|
|
34
34
|
|
35
35
|
val = token.value[0]
|
36
36
|
|
37
|
-
val.class.should ==
|
37
|
+
val.class.should == RubyLint::Token::Token
|
38
38
|
val.type.should == :integer
|
39
39
|
val.line.should == 1
|
40
40
|
val.column.should == 7
|
@@ -42,7 +42,7 @@ describe 'Rlint::Parser' do
|
|
42
42
|
|
43
43
|
val = token.value[1]
|
44
44
|
|
45
|
-
val.class.should ==
|
45
|
+
val.class.should == RubyLint::Token::Token
|
46
46
|
val.type.should == :integer
|
47
47
|
val.line.should == 1
|
48
48
|
val.column.should == 11
|
@@ -50,9 +50,9 @@ describe 'Rlint::Parser' do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'Parse a return statement with parenthesis' do
|
53
|
-
token =
|
53
|
+
token = RubyLint::Parser.new('return ( 10 )').parse[0]
|
54
54
|
|
55
|
-
token.class.should ==
|
55
|
+
token.class.should == RubyLint::Token::StatementToken
|
56
56
|
token.type.should == :return
|
57
57
|
token.line.should == 1
|
58
58
|
token.column.should == 0
|
@@ -63,14 +63,14 @@ describe 'Rlint::Parser' do
|
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'Parse a while loop' do
|
66
|
-
token =
|
66
|
+
token = RubyLint::Parser.new('while true; return 10; end').parse[0]
|
67
67
|
|
68
|
-
token.class.should ==
|
68
|
+
token.class.should == RubyLint::Token::StatementToken
|
69
69
|
token.type.should == :while
|
70
70
|
token.line.should == 1
|
71
71
|
token.column.should == 0
|
72
72
|
|
73
|
-
token.statement.class.should ==
|
73
|
+
token.statement.class.should == RubyLint::Token::VariableToken
|
74
74
|
token.statement.type.should == :keyword
|
75
75
|
token.statement.name.should == 'true'
|
76
76
|
|
@@ -79,37 +79,37 @@ describe 'Rlint::Parser' do
|
|
79
79
|
|
80
80
|
val = token.value[0]
|
81
81
|
|
82
|
-
val.class.should ==
|
82
|
+
val.class.should == RubyLint::Token::StatementToken
|
83
83
|
val.type.should == :return
|
84
84
|
|
85
85
|
val.value.class.should == Array
|
86
86
|
val.value.length.should == 1
|
87
87
|
|
88
|
-
val.value[0].class.should ==
|
88
|
+
val.value[0].class.should == RubyLint::Token::Token
|
89
89
|
val.value[0].type.should == :integer
|
90
90
|
val.value[0].value.should == '10'
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'Parse a single line while loop' do
|
94
|
-
token =
|
94
|
+
token = RubyLint::Parser.new('foo while bar').parse[0]
|
95
95
|
|
96
|
-
token.class.should ==
|
96
|
+
token.class.should == RubyLint::Token::StatementToken
|
97
97
|
token.type.should == :while
|
98
98
|
|
99
|
-
token.statement.class.should ==
|
99
|
+
token.statement.class.should == RubyLint::Token::MethodToken
|
100
100
|
token.statement.name.should == 'bar'
|
101
101
|
|
102
102
|
token.value.class.should == Array
|
103
103
|
token.value.length.should == 1
|
104
104
|
|
105
|
-
token.value[0].class.should ==
|
105
|
+
token.value[0].class.should == RubyLint::Token::MethodToken
|
106
106
|
token.value[0].name.should == 'foo'
|
107
107
|
end
|
108
108
|
|
109
109
|
it 'Parse a while loop using parenthesis' do
|
110
|
-
token =
|
110
|
+
token = RubyLint::Parser.new('while ( true ); return 10; end').parse[0]
|
111
111
|
|
112
|
-
token.class.should ==
|
112
|
+
token.class.should == RubyLint::Token::StatementToken
|
113
113
|
token.type.should == :while
|
114
114
|
token.line.should == 1
|
115
115
|
token.column.should == 0
|
@@ -126,9 +126,9 @@ for key, value in {:name => 'Ruby'}
|
|
126
126
|
end
|
127
127
|
CODE
|
128
128
|
|
129
|
-
token =
|
129
|
+
token = RubyLint::Parser.new(code).parse[0]
|
130
130
|
|
131
|
-
token.class.should ==
|
131
|
+
token.class.should == RubyLint::Token::StatementToken
|
132
132
|
token.type.should == :for
|
133
133
|
|
134
134
|
token.statement.class.should == Array
|
@@ -140,15 +140,15 @@ end
|
|
140
140
|
vars.class.should == Array
|
141
141
|
vars.length.should == 2
|
142
142
|
|
143
|
-
vars[0].class.should ==
|
143
|
+
vars[0].class.should == RubyLint::Token::Token
|
144
144
|
vars[0].type.should == :identifier
|
145
145
|
vars[0].value.should == 'key'
|
146
146
|
|
147
|
-
vars[1].class.should ==
|
147
|
+
vars[1].class.should == RubyLint::Token::Token
|
148
148
|
vars[1].type.should == :identifier
|
149
149
|
vars[1].value.should == 'value'
|
150
150
|
|
151
|
-
enum.class.should ==
|
151
|
+
enum.class.should == RubyLint::Token::Token
|
152
152
|
enum.type.should == :hash
|
153
153
|
|
154
154
|
enum.value.class.should == Array
|
@@ -156,11 +156,11 @@ end
|
|
156
156
|
|
157
157
|
val = enum.value[0]
|
158
158
|
|
159
|
-
val.class.should ==
|
159
|
+
val.class.should == RubyLint::Token::Token
|
160
160
|
val.type.should == :symbol
|
161
161
|
val.name.should == 'name'
|
162
162
|
|
163
|
-
val.value.class.should ==
|
163
|
+
val.value.class.should == RubyLint::Token::Token
|
164
164
|
val.value.type.should == :string
|
165
165
|
val.value.value.should == 'Ruby'
|
166
166
|
|
@@ -169,24 +169,24 @@ end
|
|
169
169
|
end
|
170
170
|
|
171
171
|
it 'Parse a simple if statement' do
|
172
|
-
token =
|
172
|
+
token = RubyLint::Parser.new('if 10 == 20; return 10; end').parse[0]
|
173
173
|
|
174
|
-
token.class.should ==
|
174
|
+
token.class.should == RubyLint::Token::StatementToken
|
175
175
|
token.else.nil?.should == true
|
176
176
|
token.elsif.class.should == Array
|
177
177
|
token.elsif.length.should == 0
|
178
178
|
|
179
|
-
token.statement.class.should ==
|
179
|
+
token.statement.class.should == RubyLint::Token::Token
|
180
180
|
token.statement.value.class.should == Array
|
181
181
|
token.statement.value.length.should == 3
|
182
182
|
|
183
|
-
token.statement.value[0].class.should ==
|
183
|
+
token.statement.value[0].class.should == RubyLint::Token::Token
|
184
184
|
token.statement.value[0].type.should == :integer
|
185
185
|
token.statement.value[0].value.should == '10'
|
186
186
|
|
187
187
|
token.statement.value[1].should == :==
|
188
188
|
|
189
|
-
token.statement.value[2].class.should ==
|
189
|
+
token.statement.value[2].class.should == RubyLint::Token::Token
|
190
190
|
token.statement.value[2].type.should == :integer
|
191
191
|
token.statement.value[2].value.should == '20'
|
192
192
|
end
|
@@ -204,9 +204,9 @@ else
|
|
204
204
|
end
|
205
205
|
CODE
|
206
206
|
|
207
|
-
token =
|
207
|
+
token = RubyLint::Parser.new(code).parse[0]
|
208
208
|
|
209
|
-
token.class.should ==
|
209
|
+
token.class.should == RubyLint::Token::StatementToken
|
210
210
|
token.type.should == :if
|
211
211
|
|
212
212
|
token.elsif.class.should == Array
|
@@ -215,21 +215,21 @@ end
|
|
215
215
|
first = token.elsif[0]
|
216
216
|
last = token.elsif[1]
|
217
217
|
|
218
|
-
first.class.should ==
|
218
|
+
first.class.should == RubyLint::Token::StatementToken
|
219
219
|
first.type.should == :elsif
|
220
220
|
|
221
|
-
first.statement.class.should ==
|
221
|
+
first.statement.class.should == RubyLint::Token::Token
|
222
222
|
first.statement.value.class.should == Array
|
223
223
|
first.statement.value.length.should == 3
|
224
224
|
|
225
|
-
last.class.should ==
|
225
|
+
last.class.should == RubyLint::Token::StatementToken
|
226
226
|
last.type.should == :elsif
|
227
227
|
|
228
|
-
last.statement.class.should ==
|
228
|
+
last.statement.class.should == RubyLint::Token::Token
|
229
229
|
last.statement.value.class.should == Array
|
230
230
|
last.statement.value.length.should == 3
|
231
231
|
|
232
|
-
token.else.class.should ==
|
232
|
+
token.else.class.should == RubyLint::Token::StatementToken
|
233
233
|
token.else.statement.nil?.should == true
|
234
234
|
|
235
235
|
token.else.value.class.should == Array
|
@@ -251,16 +251,16 @@ ensure
|
|
251
251
|
end
|
252
252
|
CODE
|
253
253
|
|
254
|
-
token =
|
254
|
+
token = RubyLint::Parser.new(code).parse[0]
|
255
255
|
|
256
|
-
token.class.should ==
|
256
|
+
token.class.should == RubyLint::Token::BeginRescueToken
|
257
257
|
|
258
|
-
token.else.class.should ==
|
258
|
+
token.else.class.should == RubyLint::Token::StatementToken
|
259
259
|
token.else.type.should == :else
|
260
260
|
token.else.value.class.should == Array
|
261
261
|
token.else.value.length.should == 1
|
262
262
|
|
263
|
-
token.ensure.class.should ==
|
263
|
+
token.ensure.class.should == RubyLint::Token::StatementToken
|
264
264
|
token.ensure.type.should == :ensure
|
265
265
|
token.ensure.value.class.should == Array
|
266
266
|
token.ensure.value.length.should == 1
|
@@ -283,17 +283,17 @@ end
|
|
283
283
|
constants.class.should == Array
|
284
284
|
constants.length.should == 2
|
285
285
|
|
286
|
-
constants[0].class.should ==
|
286
|
+
constants[0].class.should == RubyLint::Token::VariableToken
|
287
287
|
constants[0].type.should == :constant
|
288
288
|
constants[0].name.should == 'RuntimeError'
|
289
289
|
constants[0].line.should == 3
|
290
290
|
|
291
|
-
constants[1].class.should ==
|
291
|
+
constants[1].class.should == RubyLint::Token::VariableToken
|
292
292
|
constants[1].type.should == :constant
|
293
293
|
constants[1].name.should == 'StandardError'
|
294
294
|
constants[1].line.should == 3
|
295
295
|
|
296
|
-
var.class.should ==
|
296
|
+
var.class.should == RubyLint::Token::Token
|
297
297
|
var.type.should == :identifier
|
298
298
|
var.value.should == 'e'
|
299
299
|
var.line.should == 3
|
@@ -308,12 +308,12 @@ end
|
|
308
308
|
constants.class.should == Array
|
309
309
|
constants.length.should == 1
|
310
310
|
|
311
|
-
constants[0].class.should ==
|
311
|
+
constants[0].class.should == RubyLint::Token::VariableToken
|
312
312
|
constants[0].type.should == :constant
|
313
313
|
constants[0].name.should == 'StandardError'
|
314
314
|
constants[0].line.should == 5
|
315
315
|
|
316
|
-
var.class.should ==
|
316
|
+
var.class.should == RubyLint::Token::Token
|
317
317
|
var.type.should == :identifier
|
318
318
|
var.value.should == 'e'
|
319
319
|
var.line.should == 5
|
@@ -331,12 +331,12 @@ else
|
|
331
331
|
end
|
332
332
|
CODE
|
333
333
|
|
334
|
-
token =
|
334
|
+
token = RubyLint::Parser.new(code).parse[0]
|
335
335
|
|
336
|
-
token.class.should ==
|
336
|
+
token.class.should == RubyLint::Token::CaseToken
|
337
337
|
token.type.should == :case
|
338
338
|
|
339
|
-
token.statement.class.should ==
|
339
|
+
token.statement.class.should == RubyLint::Token::MethodToken
|
340
340
|
token.statement.name.should == 'number'
|
341
341
|
|
342
342
|
token.when.class.should == Array
|
@@ -345,50 +345,50 @@ end
|
|
345
345
|
first, second = token.when
|
346
346
|
|
347
347
|
# Check the first when statement.
|
348
|
-
first.class.should ==
|
348
|
+
first.class.should == RubyLint::Token::StatementToken
|
349
349
|
first.statement.class == Array
|
350
350
|
first.statement.length.should == 2
|
351
351
|
|
352
|
-
first.statement[0].class.should ==
|
352
|
+
first.statement[0].class.should == RubyLint::Token::Token
|
353
353
|
first.statement[0].type.should == :integer
|
354
354
|
first.statement[0].value.should == '10'
|
355
355
|
|
356
|
-
first.statement[1].class.should ==
|
356
|
+
first.statement[1].class.should == RubyLint::Token::Token
|
357
357
|
first.statement[1].type.should == :integer
|
358
358
|
first.statement[1].value.should == '20'
|
359
359
|
|
360
360
|
first.value.class.should == Array
|
361
361
|
first.value.length.should == 1
|
362
362
|
|
363
|
-
first.value[0].class.should ==
|
363
|
+
first.value[0].class.should == RubyLint::Token::MethodToken
|
364
364
|
first.value[0].name.should == 'puts'
|
365
365
|
first.value[0].parameters.class.should == Array
|
366
366
|
first.value[0].parameters.length.should == 1
|
367
367
|
|
368
368
|
# Check the second when statement.
|
369
|
-
second.class.should ==
|
369
|
+
second.class.should == RubyLint::Token::StatementToken
|
370
370
|
second.statement.class.should == Array
|
371
371
|
second.statement.length.should == 1
|
372
372
|
|
373
|
-
second.statement[0].class.should ==
|
373
|
+
second.statement[0].class.should == RubyLint::Token::Token
|
374
374
|
second.statement[0].type.should == :integer
|
375
375
|
second.statement[0].value.should == '30'
|
376
376
|
|
377
377
|
second.value.class.should == Array
|
378
378
|
second.value.length.should == 1
|
379
379
|
|
380
|
-
second.value[0].class.should ==
|
380
|
+
second.value[0].class.should == RubyLint::Token::MethodToken
|
381
381
|
second.value[0].name.should == 'puts'
|
382
382
|
second.value[0].parameters.class.should == Array
|
383
383
|
second.value[0].parameters.length.should == 1
|
384
384
|
|
385
385
|
# Check the else statement.
|
386
|
-
token.else.class.should ==
|
386
|
+
token.else.class.should == RubyLint::Token::StatementToken
|
387
387
|
|
388
388
|
token.else.value.class.should == Array
|
389
389
|
token.else.value.length.should == 1
|
390
390
|
|
391
|
-
token.else.value[0].class.should ==
|
391
|
+
token.else.value[0].class.should == RubyLint::Token::MethodToken
|
392
392
|
token.else.value[0].name.should == 'puts'
|
393
393
|
|
394
394
|
token.else.value[0].parameters.class.should == Array
|
@@ -396,76 +396,76 @@ end
|
|
396
396
|
end
|
397
397
|
|
398
398
|
it 'Parse a single line if statement' do
|
399
|
-
token =
|
399
|
+
token = RubyLint::Parser.new('foo if bar').parse[0]
|
400
400
|
|
401
|
-
token.class.should ==
|
401
|
+
token.class.should == RubyLint::Token::StatementToken
|
402
402
|
token.type.should == :if
|
403
403
|
|
404
|
-
token.statement.class.should ==
|
404
|
+
token.statement.class.should == RubyLint::Token::MethodToken
|
405
405
|
token.statement.name.should == 'bar'
|
406
406
|
|
407
407
|
token.value.class.should == Array
|
408
408
|
token.value.length.should == 1
|
409
409
|
|
410
|
-
token.value[0].class.should ==
|
410
|
+
token.value[0].class.should == RubyLint::Token::MethodToken
|
411
411
|
token.value[0].name.should == 'foo'
|
412
412
|
end
|
413
413
|
|
414
414
|
it 'Parse a single line begin/rescue statement' do
|
415
|
-
token =
|
415
|
+
token = RubyLint::Parser.new('foo rescue bar').parse[0]
|
416
416
|
|
417
|
-
token.class.should ==
|
417
|
+
token.class.should == RubyLint::Token::BeginRescueToken
|
418
418
|
token.type.should == :rescue
|
419
419
|
|
420
420
|
token.rescue.class.should == Array
|
421
421
|
token.rescue.length.should == 1
|
422
422
|
|
423
|
-
token.rescue[0].class.should ==
|
423
|
+
token.rescue[0].class.should == RubyLint::Token::MethodToken
|
424
424
|
token.rescue[0].name.should == 'bar'
|
425
425
|
|
426
426
|
token.value.class.should == Array
|
427
427
|
token.value.length.should == 1
|
428
428
|
|
429
|
-
token.value[0].class.should ==
|
429
|
+
token.value[0].class.should == RubyLint::Token::MethodToken
|
430
430
|
token.value[0].name.should == 'foo'
|
431
431
|
end
|
432
432
|
|
433
433
|
it 'Parse an unless statement' do
|
434
|
-
token =
|
434
|
+
token = RubyLint::Parser.new('unless foo; bar; else; baz; end').parse[0]
|
435
435
|
|
436
|
-
token.class.should ==
|
436
|
+
token.class.should == RubyLint::Token::StatementToken
|
437
437
|
token.type.should == :unless
|
438
438
|
|
439
|
-
token.statement.class.should ==
|
439
|
+
token.statement.class.should == RubyLint::Token::MethodToken
|
440
440
|
token.statement.name.should == 'foo'
|
441
441
|
|
442
|
-
token.else.class.should ==
|
442
|
+
token.else.class.should == RubyLint::Token::StatementToken
|
443
443
|
token.else.type.should == :else
|
444
444
|
|
445
445
|
token.else.value.class.should == Array
|
446
|
-
token.else.value[0].class.should ==
|
446
|
+
token.else.value[0].class.should == RubyLint::Token::MethodToken
|
447
447
|
token.else.value[0].name.should == 'baz'
|
448
448
|
|
449
449
|
token.value.class.should == Array
|
450
450
|
token.value.length.should == 1
|
451
451
|
|
452
|
-
token.value[0].class.should ==
|
452
|
+
token.value[0].class.should == RubyLint::Token::MethodToken
|
453
453
|
token.value[0].name.should == 'bar'
|
454
454
|
end
|
455
455
|
|
456
456
|
it 'Parse a single line unless statement' do
|
457
|
-
token =
|
457
|
+
token = RubyLint::Parser.new('foo unless bar').parse[0]
|
458
458
|
|
459
|
-
token.class.should ==
|
459
|
+
token.class.should == RubyLint::Token::StatementToken
|
460
460
|
token.type.should == :unless
|
461
461
|
|
462
|
-
token.statement.class.should ==
|
462
|
+
token.statement.class.should == RubyLint::Token::MethodToken
|
463
463
|
token.statement.name.should == 'bar'
|
464
464
|
|
465
465
|
token.value.class.should == Array
|
466
466
|
token.value.length.should == 1
|
467
467
|
|
468
|
-
token.value[0].class.should ==
|
468
|
+
token.value[0].class.should == RubyLint::Token::MethodToken
|
469
469
|
token.value[0].name.should == 'foo'
|
470
470
|
end
|
471
471
|
|
@@ -476,12 +476,12 @@ until foo == bar
|
|
476
476
|
end
|
477
477
|
CODE
|
478
478
|
|
479
|
-
token =
|
479
|
+
token = RubyLint::Parser.new(code).parse[0]
|
480
480
|
|
481
|
-
token.class.should ==
|
481
|
+
token.class.should == RubyLint::Token::StatementToken
|
482
482
|
token.type.should == :until
|
483
483
|
|
484
|
-
token.statement.class.should ==
|
484
|
+
token.statement.class.should == RubyLint::Token::Token
|
485
485
|
token.statement.type.should == :binary
|
486
486
|
|
487
487
|
token.statement.value.class.should == Array
|
@@ -489,12 +489,12 @@ end
|
|
489
489
|
|
490
490
|
left, op, right = token.statement.value
|
491
491
|
|
492
|
-
left.class.should ==
|
492
|
+
left.class.should == RubyLint::Token::MethodToken
|
493
493
|
left.name.should == 'foo'
|
494
494
|
|
495
495
|
op.should == :==
|
496
496
|
|
497
|
-
right.class.should ==
|
497
|
+
right.class.should == RubyLint::Token::MethodToken
|
498
498
|
right.name.should == 'bar'
|
499
499
|
|
500
500
|
token.value.class.should == Array
|
@@ -502,28 +502,28 @@ end
|
|
502
502
|
end
|
503
503
|
|
504
504
|
it 'Parse a single line until statement' do
|
505
|
-
token =
|
505
|
+
token = RubyLint::Parser.new('foo until bar').parse[0]
|
506
506
|
|
507
|
-
token.class.should ==
|
507
|
+
token.class.should == RubyLint::Token::StatementToken
|
508
508
|
token.type.should == :until
|
509
509
|
|
510
|
-
token.statement.class.should ==
|
510
|
+
token.statement.class.should == RubyLint::Token::MethodToken
|
511
511
|
token.statement.name.should == 'bar'
|
512
512
|
|
513
513
|
token.value.class.should == Array
|
514
514
|
token.value.length.should == 1
|
515
515
|
|
516
|
-
token.value[0].class.should ==
|
516
|
+
token.value[0].class.should == RubyLint::Token::MethodToken
|
517
517
|
token.value[0].name.should == 'foo'
|
518
518
|
end
|
519
519
|
|
520
520
|
it 'Parse a tenary operator' do
|
521
|
-
token =
|
521
|
+
token = RubyLint::Parser.new('statement ? true : false').parse[0]
|
522
522
|
|
523
|
-
token.class.should ==
|
523
|
+
token.class.should == RubyLint::Token::StatementToken
|
524
524
|
token.type.should == :if
|
525
525
|
|
526
|
-
token.statement.class.should ==
|
526
|
+
token.statement.class.should == RubyLint::Token::MethodToken
|
527
527
|
token.statement.name.should == 'statement'
|
528
528
|
token.statement.column.should == 0
|
529
529
|
token.statement.line.should == 1
|
@@ -531,12 +531,12 @@ end
|
|
531
531
|
token.value.class.should == Array
|
532
532
|
token.value.length.should == 1
|
533
533
|
|
534
|
-
token.value[0].class.should ==
|
534
|
+
token.value[0].class.should == RubyLint::Token::VariableToken
|
535
535
|
token.value[0].name.should == 'true'
|
536
536
|
token.value[0].line.should == 1
|
537
537
|
token.value[0].column.should == 12
|
538
538
|
|
539
|
-
token.else.class.should ==
|
539
|
+
token.else.class.should == RubyLint::Token::StatementToken
|
540
540
|
token.else.statement.nil?.should == true
|
541
541
|
token.else.line.should == 1
|
542
542
|
token.else.column.should == 19
|
@@ -544,7 +544,7 @@ end
|
|
544
544
|
token.else.value.class.should == Array
|
545
545
|
token.else.value.length.should == 1
|
546
546
|
|
547
|
-
token.else.value[0].class.should ==
|
547
|
+
token.else.value[0].class.should == RubyLint::Token::VariableToken
|
548
548
|
token.else.value[0].name.should == 'false'
|
549
549
|
end
|
550
550
|
end
|