ruby-lint 0.0.1a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/.gitignore +5 -0
  2. data/.rbenv-version +1 -0
  3. data/.yardopts +10 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +19 -0
  6. data/MANIFEST +79 -0
  7. data/README.md +48 -0
  8. data/Rakefile +14 -0
  9. data/bin/rlint +6 -0
  10. data/doc/.gitkeep +0 -0
  11. data/doc/build/.gitkeep +0 -0
  12. data/doc/css/.gitkeep +0 -0
  13. data/doc/css/common.css +68 -0
  14. data/lib/rlint/analyze/coding_style.rb +407 -0
  15. data/lib/rlint/analyze/definitions.rb +244 -0
  16. data/lib/rlint/analyze/method_validation.rb +104 -0
  17. data/lib/rlint/analyze/shadowing_variables.rb +37 -0
  18. data/lib/rlint/analyze/undefined_variables.rb +99 -0
  19. data/lib/rlint/analyze/unused_variables.rb +103 -0
  20. data/lib/rlint/callback.rb +67 -0
  21. data/lib/rlint/cli.rb +167 -0
  22. data/lib/rlint/constant_importer.rb +102 -0
  23. data/lib/rlint/definition.rb +230 -0
  24. data/lib/rlint/formatter/text.rb +54 -0
  25. data/lib/rlint/helper/definition_resolver.rb +143 -0
  26. data/lib/rlint/helper/scoping.rb +138 -0
  27. data/lib/rlint/iterator.rb +193 -0
  28. data/lib/rlint/options.rb +58 -0
  29. data/lib/rlint/parser.rb +1252 -0
  30. data/lib/rlint/parser_error.rb +42 -0
  31. data/lib/rlint/report.rb +98 -0
  32. data/lib/rlint/token/assignment_token.rb +46 -0
  33. data/lib/rlint/token/begin_rescue_token.rb +57 -0
  34. data/lib/rlint/token/block_token.rb +17 -0
  35. data/lib/rlint/token/case_token.rb +44 -0
  36. data/lib/rlint/token/class_token.rb +24 -0
  37. data/lib/rlint/token/method_definition_token.rb +64 -0
  38. data/lib/rlint/token/method_token.rb +58 -0
  39. data/lib/rlint/token/parameters_token.rb +99 -0
  40. data/lib/rlint/token/regexp_token.rb +15 -0
  41. data/lib/rlint/token/statement_token.rb +69 -0
  42. data/lib/rlint/token/token.rb +162 -0
  43. data/lib/rlint/token/variable_token.rb +18 -0
  44. data/lib/rlint/version.rb +3 -0
  45. data/lib/rlint.rb +36 -0
  46. data/ruby-lint.gemspec +23 -0
  47. data/spec/benchmarks/memory.rb +52 -0
  48. data/spec/benchmarks/parse_parser.rb +16 -0
  49. data/spec/helper.rb +4 -0
  50. data/spec/rlint/analyze/coding_style.rb +224 -0
  51. data/spec/rlint/analyze/definitions/classes.rb +114 -0
  52. data/spec/rlint/analyze/definitions/methods.rb +91 -0
  53. data/spec/rlint/analyze/definitions/modules.rb +207 -0
  54. data/spec/rlint/analyze/definitions/variables.rb +103 -0
  55. data/spec/rlint/analyze/method_validation.rb +177 -0
  56. data/spec/rlint/analyze/shadowing_variables.rb +30 -0
  57. data/spec/rlint/analyze/undefined_variables.rb +230 -0
  58. data/spec/rlint/analyze/unused_variables.rb +225 -0
  59. data/spec/rlint/callback.rb +28 -0
  60. data/spec/rlint/constant_importer.rb +27 -0
  61. data/spec/rlint/definition.rb +96 -0
  62. data/spec/rlint/formatter/text.rb +21 -0
  63. data/spec/rlint/iterator.rb +452 -0
  64. data/spec/rlint/parser/arrays.rb +147 -0
  65. data/spec/rlint/parser/classes.rb +152 -0
  66. data/spec/rlint/parser/errors.rb +19 -0
  67. data/spec/rlint/parser/hashes.rb +136 -0
  68. data/spec/rlint/parser/methods.rb +249 -0
  69. data/spec/rlint/parser/modules.rb +49 -0
  70. data/spec/rlint/parser/objects.rb +39 -0
  71. data/spec/rlint/parser/operators.rb +75 -0
  72. data/spec/rlint/parser/procs.rb +113 -0
  73. data/spec/rlint/parser/ranges.rb +49 -0
  74. data/spec/rlint/parser/regexp.rb +31 -0
  75. data/spec/rlint/parser/scalars.rb +93 -0
  76. data/spec/rlint/parser/statements.rb +550 -0
  77. data/spec/rlint/parser/variables.rb +181 -0
  78. data/spec/rlint/report.rb +30 -0
  79. data/task/test.rake +6 -0
  80. metadata +188 -0
@@ -0,0 +1,49 @@
1
+ require File.expand_path('../../../helper', __FILE__)
2
+
3
+ describe 'Rlint::Parser' do
4
+ it 'Parse a Range' do
5
+ token = Rlint::Parser.new('0..10').parse[0]
6
+
7
+ token.class.should == Rlint::Token::Token
8
+ token.type.should == :range
9
+ token.line.should == 1
10
+ token.column.should == 1
11
+
12
+ token.value.class.should == Array
13
+ token.value.length.should == 2
14
+
15
+ start = token.value[0]
16
+ stop = token.value[1]
17
+
18
+ start.class.should == Rlint::Token::Token
19
+ start.type.should == :integer
20
+ start.value.should == '0'
21
+
22
+ stop.class.should == Rlint::Token::Token
23
+ stop.type.should == :integer
24
+ stop.value.should == '10'
25
+ end
26
+
27
+ it 'Parse a Range of Strings' do
28
+ token = Rlint::Parser.new('"a".."z"').parse[0]
29
+
30
+ token.class.should == Rlint::Token::Token
31
+ token.type.should == :range
32
+ token.line.should == 1
33
+ token.column.should == 1
34
+
35
+ token.value.class.should == Array
36
+ token.value.length.should == 2
37
+
38
+ start = token.value[0]
39
+ stop = token.value[1]
40
+
41
+ start.class.should == Rlint::Token::Token
42
+ start.type.should == :string
43
+ start.value.should == 'a'
44
+
45
+ stop.class.should == Rlint::Token::Token
46
+ stop.type.should == :string
47
+ stop.value.should == 'z'
48
+ end
49
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../../../helper', __FILE__)
2
+
3
+ describe 'Rlint::Parser' do
4
+ it 'Parse a regular expression' do
5
+ token = Rlint::Parser.new('/foo/im').parse[0]
6
+
7
+ token.class.should == Rlint::Token::RegexpToken
8
+ token.type.should == :regexp
9
+ token.value.should == 'foo'
10
+
11
+ token.modes.class.should == Array
12
+ token.modes.length.should == 2
13
+
14
+ token.modes.include?('i').should == true
15
+ token.modes.include?('m').should == true
16
+ end
17
+
18
+ it 'Parse a regular expression using %r{}' do
19
+ token = Rlint::Parser.new('%r{foo}im').parse[0]
20
+
21
+ token.class.should == Rlint::Token::RegexpToken
22
+ token.type.should == :regexp
23
+ token.value.should == 'foo'
24
+
25
+ token.modes.class.should == Array
26
+ token.modes.length.should == 2
27
+
28
+ token.modes.include?('i').should == true
29
+ token.modes.include?('m').should == true
30
+ end
31
+ end
@@ -0,0 +1,93 @@
1
+ require File.expand_path('../../../helper', __FILE__)
2
+
3
+ describe 'Rlint::Parser' do
4
+ it 'Parse a String' do
5
+ ['"hello"', "'hello'"].each do |string|
6
+ token = Rlint::Parser.new(string).parse[0]
7
+
8
+ token.class.should == Rlint::Token::Token
9
+ token.type.should == :string
10
+ token.value.should == 'hello'
11
+ token.line.should == 1
12
+ token.column.should == 1
13
+ token.code.should == string
14
+ end
15
+ end
16
+
17
+ it 'Parse a Symbol' do
18
+ token = Rlint::Parser.new(':hello').parse[0]
19
+
20
+ token.class.should == Rlint::Token::Token
21
+ token.type.should == :symbol
22
+ token.value.should == 'hello'
23
+ token.line.should == 1
24
+ token.column.should == 1
25
+ token.code.should == ':hello'
26
+
27
+ token = Rlint::Parser.new(':"hello"').parse[0]
28
+
29
+ token.class.should == Rlint::Token::Token
30
+ token.type.should == :symbol
31
+ token.value.should == 'hello'
32
+ token.line.should == 1
33
+ token.column.should == 2
34
+ token.code.should == ':"hello"'
35
+ end
36
+
37
+ it 'Parse a string using %q{} and %Q{}' do
38
+ ['%q{hello}', '%Q{hello}'].each do |string|
39
+ token = Rlint::Parser.new(string).parse[0]
40
+
41
+ token.class.should == Rlint::Token::Token
42
+ token.type.should == :string
43
+ token.value.should == 'hello'
44
+ token.line.should == 1
45
+ token.column.should == 3
46
+ token.code.should == string
47
+ end
48
+ end
49
+
50
+ it 'Parse a Fixnum' do
51
+ token = Rlint::Parser.new('10').parse[0]
52
+
53
+ token.class.should == Rlint::Token::Token
54
+ token.type.should == :integer
55
+ token.value.should == '10'
56
+ token.line.should == 1
57
+ token.column.should == 0
58
+ token.code.should == '10'
59
+ end
60
+
61
+ it 'Parse a Float' do
62
+ token = Rlint::Parser.new('10.2').parse[0]
63
+
64
+ token.class.should == Rlint::Token::Token
65
+ token.type.should == :float
66
+ token.value.should == '10.2'
67
+ token.line.should == 1
68
+ token.column.should == 0
69
+ token.code.should == '10.2'
70
+ end
71
+
72
+ it 'Parse a boolean' do
73
+ token = Rlint::Parser.new('true').parse[0]
74
+
75
+ token.class.should == Rlint::Token::VariableToken
76
+ token.type.should == :keyword
77
+ token.name.should == 'true'
78
+ token.line.should == 1
79
+ token.column.should == 0
80
+ token.code.should == 'true'
81
+ end
82
+
83
+ it 'Parse a nil value' do
84
+ token = Rlint::Parser.new('nil').parse[0]
85
+
86
+ token.class.should == Rlint::Token::VariableToken
87
+ token.type.should == :keyword
88
+ token.name.should == 'nil'
89
+ token.line.should == 1
90
+ token.column.should == 0
91
+ token.code.should == 'nil'
92
+ end
93
+ end
@@ -0,0 +1,550 @@
1
+ require File.expand_path('../../../helper', __FILE__)
2
+
3
+ describe 'Rlint::Parser' do
4
+ it 'Parse a return statement' do
5
+ token = Rlint::Parser.new('return 10').parse[0]
6
+
7
+ token.class.should == Rlint::Token::StatementToken
8
+ token.type.should == :return
9
+ token.line.should == 1
10
+ token.column.should == 0
11
+
12
+ token.value.class.should == Array
13
+ token.value.length.should == 1
14
+
15
+ val = token.value[0]
16
+
17
+ val.class.should == Rlint::Token::Token
18
+ val.type.should == :integer
19
+ val.line.should == 1
20
+ val.column.should == 7
21
+ val.value.should == '10'
22
+ end
23
+
24
+ it 'Parse a return statement with multiple return values' do
25
+ token = Rlint::Parser.new('return 10, 20').parse[0]
26
+
27
+ token.class.should == Rlint::Token::StatementToken
28
+ token.type.should == :return
29
+ token.line.should == 1
30
+ token.column.should == 0
31
+
32
+ token.value.class.should == Array
33
+ token.value.length.should == 2
34
+
35
+ val = token.value[0]
36
+
37
+ val.class.should == Rlint::Token::Token
38
+ val.type.should == :integer
39
+ val.line.should == 1
40
+ val.column.should == 7
41
+ val.value.should == '10'
42
+
43
+ val = token.value[1]
44
+
45
+ val.class.should == Rlint::Token::Token
46
+ val.type.should == :integer
47
+ val.line.should == 1
48
+ val.column.should == 11
49
+ val.value.should == '20'
50
+ end
51
+
52
+ it 'Parse a return statement with parenthesis' do
53
+ token = Rlint::Parser.new('return ( 10 )').parse[0]
54
+
55
+ token.class.should == Rlint::Token::StatementToken
56
+ token.type.should == :return
57
+ token.line.should == 1
58
+ token.column.should == 0
59
+ token.code.should == 'return ( 10 )'
60
+
61
+ token.value.class.should == Array
62
+ token.value.length.should == 1
63
+ end
64
+
65
+ it 'Parse a while loop' do
66
+ token = Rlint::Parser.new('while true; return 10; end').parse[0]
67
+
68
+ token.class.should == Rlint::Token::StatementToken
69
+ token.type.should == :while
70
+ token.line.should == 1
71
+ token.column.should == 0
72
+
73
+ token.statement.class.should == Rlint::Token::VariableToken
74
+ token.statement.type.should == :keyword
75
+ token.statement.name.should == 'true'
76
+
77
+ token.value.class.should == Array
78
+ token.value.length.should == 1
79
+
80
+ val = token.value[0]
81
+
82
+ val.class.should == Rlint::Token::StatementToken
83
+ val.type.should == :return
84
+
85
+ val.value.class.should == Array
86
+ val.value.length.should == 1
87
+
88
+ val.value[0].class.should == Rlint::Token::Token
89
+ val.value[0].type.should == :integer
90
+ val.value[0].value.should == '10'
91
+ end
92
+
93
+ it 'Parse a single line while loop' do
94
+ token = Rlint::Parser.new('foo while bar').parse[0]
95
+
96
+ token.class.should == Rlint::Token::StatementToken
97
+ token.type.should == :while
98
+
99
+ token.statement.class.should == Rlint::Token::MethodToken
100
+ token.statement.name.should == 'bar'
101
+
102
+ token.value.class.should == Array
103
+ token.value.length.should == 1
104
+
105
+ token.value[0].class.should == Rlint::Token::MethodToken
106
+ token.value[0].name.should == 'foo'
107
+ end
108
+
109
+ it 'Parse a while loop using parenthesis' do
110
+ token = Rlint::Parser.new('while ( true ); return 10; end').parse[0]
111
+
112
+ token.class.should == Rlint::Token::StatementToken
113
+ token.type.should == :while
114
+ token.line.should == 1
115
+ token.column.should == 0
116
+ token.code.should == 'while ( true ); return 10; end'
117
+
118
+ token.value.class.should == Array
119
+ token.value.length.should == 1
120
+ end
121
+
122
+ it 'Parse a for loop' do
123
+ code = <<-CODE
124
+ for key, value in {:name => 'Ruby'}
125
+ return key, value
126
+ end
127
+ CODE
128
+
129
+ token = Rlint::Parser.new(code).parse[0]
130
+
131
+ token.class.should == Rlint::Token::StatementToken
132
+ token.type.should == :for
133
+
134
+ token.statement.class.should == Array
135
+ token.statement.length.should == 2
136
+
137
+ vars = token.statement[0]
138
+ enum = token.statement[1]
139
+
140
+ vars.class.should == Array
141
+ vars.length.should == 2
142
+
143
+ vars[0].class.should == Rlint::Token::Token
144
+ vars[0].type.should == :identifier
145
+ vars[0].value.should == 'key'
146
+
147
+ vars[1].class.should == Rlint::Token::Token
148
+ vars[1].type.should == :identifier
149
+ vars[1].value.should == 'value'
150
+
151
+ enum.class.should == Rlint::Token::Token
152
+ enum.type.should == :hash
153
+
154
+ enum.value.class.should == Array
155
+ enum.value.length.should == 1
156
+
157
+ val = enum.value[0]
158
+
159
+ val.class.should == Rlint::Token::Token
160
+ val.type.should == :symbol
161
+ val.name.should == 'name'
162
+
163
+ val.value.class.should == Rlint::Token::Token
164
+ val.value.type.should == :string
165
+ val.value.value.should == 'Ruby'
166
+
167
+ token.value.class.should == Array
168
+ token.value.length.should == 1
169
+ end
170
+
171
+ it 'Parse a simple if statement' do
172
+ token = Rlint::Parser.new('if 10 == 20; return 10; end').parse[0]
173
+
174
+ token.class.should == Rlint::Token::StatementToken
175
+ token.else.nil?.should == true
176
+ token.elsif.class.should == Array
177
+ token.elsif.length.should == 0
178
+
179
+ token.statement.class.should == Rlint::Token::Token
180
+ token.statement.value.class.should == Array
181
+ token.statement.value.length.should == 3
182
+
183
+ token.statement.value[0].class.should == Rlint::Token::Token
184
+ token.statement.value[0].type.should == :integer
185
+ token.statement.value[0].value.should == '10'
186
+
187
+ token.statement.value[1].should == :==
188
+
189
+ token.statement.value[2].class.should == Rlint::Token::Token
190
+ token.statement.value[2].type.should == :integer
191
+ token.statement.value[2].value.should == '20'
192
+ end
193
+
194
+ it 'Parse an if, elsif and else statement' do
195
+ code = <<-CODE
196
+ if 10 == 20
197
+ return 10
198
+ elsif 10 == 15
199
+ return 20
200
+ elsif 10 == 10
201
+ return 30
202
+ else
203
+ return 40
204
+ end
205
+ CODE
206
+
207
+ token = Rlint::Parser.new(code).parse[0]
208
+
209
+ token.class.should == Rlint::Token::StatementToken
210
+ token.type.should == :if
211
+
212
+ token.elsif.class.should == Array
213
+ token.elsif.length.should == 2
214
+
215
+ first = token.elsif[0]
216
+ last = token.elsif[1]
217
+
218
+ first.class.should == Rlint::Token::StatementToken
219
+ first.type.should == :elsif
220
+
221
+ first.statement.class.should == Rlint::Token::Token
222
+ first.statement.value.class.should == Array
223
+ first.statement.value.length.should == 3
224
+
225
+ last.class.should == Rlint::Token::StatementToken
226
+ last.type.should == :elsif
227
+
228
+ last.statement.class.should == Rlint::Token::Token
229
+ last.statement.value.class.should == Array
230
+ last.statement.value.length.should == 3
231
+
232
+ token.else.class.should == Rlint::Token::StatementToken
233
+ token.else.statement.nil?.should == true
234
+
235
+ token.else.value.class.should == Array
236
+ token.else.value.length.should == 1
237
+ end
238
+
239
+ it 'Parse a begin/rescue statement' do
240
+ code = <<-CODE
241
+ begin
242
+ return 10
243
+ rescue RuntimeError, StandardError => e
244
+ return 20
245
+ rescue StandardError => e
246
+ return 30
247
+ else
248
+ return 40
249
+ ensure
250
+ return 50
251
+ end
252
+ CODE
253
+
254
+ token = Rlint::Parser.new(code).parse[0]
255
+
256
+ token.class.should == Rlint::Token::BeginRescueToken
257
+
258
+ token.else.class.should == Rlint::Token::StatementToken
259
+ token.else.type.should == :else
260
+ token.else.value.class.should == Array
261
+ token.else.value.length.should == 1
262
+
263
+ token.ensure.class.should == Rlint::Token::StatementToken
264
+ token.ensure.type.should == :ensure
265
+ token.ensure.value.class.should == Array
266
+ token.ensure.value.length.should == 1
267
+
268
+ token.rescue.class.should == Array
269
+ token.rescue.length.should == 2
270
+
271
+ first, second = token.rescue
272
+
273
+ first.type.should == :rescue
274
+ first.value.class.should == Array
275
+ first.value.length.should == 1
276
+
277
+ first.statement.class.should == Array
278
+ first.statement.length.should == 2
279
+
280
+ constants = first.statement[0]
281
+ var = first.statement[1]
282
+
283
+ constants.class.should == Array
284
+ constants.length.should == 2
285
+
286
+ constants[0].class.should == Rlint::Token::VariableToken
287
+ constants[0].type.should == :constant
288
+ constants[0].name.should == 'RuntimeError'
289
+ constants[0].line.should == 3
290
+
291
+ constants[1].class.should == Rlint::Token::VariableToken
292
+ constants[1].type.should == :constant
293
+ constants[1].name.should == 'StandardError'
294
+ constants[1].line.should == 3
295
+
296
+ var.class.should == Rlint::Token::Token
297
+ var.type.should == :identifier
298
+ var.value.should == 'e'
299
+ var.line.should == 3
300
+
301
+ second.type.should == :rescue
302
+ second.value.class.should == Array
303
+ second.value.length.should == 1
304
+
305
+ constants = second.statement[0]
306
+ var = second.statement[1]
307
+
308
+ constants.class.should == Array
309
+ constants.length.should == 1
310
+
311
+ constants[0].class.should == Rlint::Token::VariableToken
312
+ constants[0].type.should == :constant
313
+ constants[0].name.should == 'StandardError'
314
+ constants[0].line.should == 5
315
+
316
+ var.class.should == Rlint::Token::Token
317
+ var.type.should == :identifier
318
+ var.value.should == 'e'
319
+ var.line.should == 5
320
+ end
321
+
322
+ it 'Parse a case statement' do
323
+ code = <<-CODE
324
+ case number
325
+ when 10, 20
326
+ puts '10 or 20'
327
+ when 30
328
+ puts '30'
329
+ else
330
+ puts 'something else'
331
+ end
332
+ CODE
333
+
334
+ token = Rlint::Parser.new(code).parse[0]
335
+
336
+ token.class.should == Rlint::Token::CaseToken
337
+ token.type.should == :case
338
+
339
+ token.statement.class.should == Rlint::Token::MethodToken
340
+ token.statement.name.should == 'number'
341
+
342
+ token.when.class.should == Array
343
+ token.when.length.should == 2
344
+
345
+ first, second = token.when
346
+
347
+ # Check the first when statement.
348
+ first.class.should == Rlint::Token::StatementToken
349
+ first.statement.class == Array
350
+ first.statement.length.should == 2
351
+
352
+ first.statement[0].class.should == Rlint::Token::Token
353
+ first.statement[0].type.should == :integer
354
+ first.statement[0].value.should == '10'
355
+
356
+ first.statement[1].class.should == Rlint::Token::Token
357
+ first.statement[1].type.should == :integer
358
+ first.statement[1].value.should == '20'
359
+
360
+ first.value.class.should == Array
361
+ first.value.length.should == 1
362
+
363
+ first.value[0].class.should == Rlint::Token::MethodToken
364
+ first.value[0].name.should == 'puts'
365
+ first.value[0].parameters.class.should == Array
366
+ first.value[0].parameters.length.should == 1
367
+
368
+ # Check the second when statement.
369
+ second.class.should == Rlint::Token::StatementToken
370
+ second.statement.class.should == Array
371
+ second.statement.length.should == 1
372
+
373
+ second.statement[0].class.should == Rlint::Token::Token
374
+ second.statement[0].type.should == :integer
375
+ second.statement[0].value.should == '30'
376
+
377
+ second.value.class.should == Array
378
+ second.value.length.should == 1
379
+
380
+ second.value[0].class.should == Rlint::Token::MethodToken
381
+ second.value[0].name.should == 'puts'
382
+ second.value[0].parameters.class.should == Array
383
+ second.value[0].parameters.length.should == 1
384
+
385
+ # Check the else statement.
386
+ token.else.class.should == Rlint::Token::StatementToken
387
+
388
+ token.else.value.class.should == Array
389
+ token.else.value.length.should == 1
390
+
391
+ token.else.value[0].class.should == Rlint::Token::MethodToken
392
+ token.else.value[0].name.should == 'puts'
393
+
394
+ token.else.value[0].parameters.class.should == Array
395
+ token.else.value[0].parameters.length.should == 1
396
+ end
397
+
398
+ it 'Parse a single line if statement' do
399
+ token = Rlint::Parser.new('foo if bar').parse[0]
400
+
401
+ token.class.should == Rlint::Token::StatementToken
402
+ token.type.should == :if
403
+
404
+ token.statement.class.should == Rlint::Token::MethodToken
405
+ token.statement.name.should == 'bar'
406
+
407
+ token.value.class.should == Array
408
+ token.value.length.should == 1
409
+
410
+ token.value[0].class.should == Rlint::Token::MethodToken
411
+ token.value[0].name.should == 'foo'
412
+ end
413
+
414
+ it 'Parse a single line begin/rescue statement' do
415
+ token = Rlint::Parser.new('foo rescue bar').parse[0]
416
+
417
+ token.class.should == Rlint::Token::BeginRescueToken
418
+ token.type.should == :rescue
419
+
420
+ token.rescue.class.should == Array
421
+ token.rescue.length.should == 1
422
+
423
+ token.rescue[0].class.should == Rlint::Token::MethodToken
424
+ token.rescue[0].name.should == 'bar'
425
+
426
+ token.value.class.should == Array
427
+ token.value.length.should == 1
428
+
429
+ token.value[0].class.should == Rlint::Token::MethodToken
430
+ token.value[0].name.should == 'foo'
431
+ end
432
+
433
+ it 'Parse an unless statement' do
434
+ token = Rlint::Parser.new('unless foo; bar; else; baz; end').parse[0]
435
+
436
+ token.class.should == Rlint::Token::StatementToken
437
+ token.type.should == :unless
438
+
439
+ token.statement.class.should == Rlint::Token::MethodToken
440
+ token.statement.name.should == 'foo'
441
+
442
+ token.else.class.should == Rlint::Token::StatementToken
443
+ token.else.type.should == :else
444
+
445
+ token.else.value.class.should == Array
446
+ token.else.value[0].class.should == Rlint::Token::MethodToken
447
+ token.else.value[0].name.should == 'baz'
448
+
449
+ token.value.class.should == Array
450
+ token.value.length.should == 1
451
+
452
+ token.value[0].class.should == Rlint::Token::MethodToken
453
+ token.value[0].name.should == 'bar'
454
+ end
455
+
456
+ it 'Parse a single line unless statement' do
457
+ token = Rlint::Parser.new('foo unless bar').parse[0]
458
+
459
+ token.class.should == Rlint::Token::StatementToken
460
+ token.type.should == :unless
461
+
462
+ token.statement.class.should == Rlint::Token::MethodToken
463
+ token.statement.name.should == 'bar'
464
+
465
+ token.value.class.should == Array
466
+ token.value.length.should == 1
467
+
468
+ token.value[0].class.should == Rlint::Token::MethodToken
469
+ token.value[0].name.should == 'foo'
470
+ end
471
+
472
+ it 'Parse a until statement' do
473
+ code = <<-CODE
474
+ until foo == bar
475
+ puts 'foo'
476
+ end
477
+ CODE
478
+
479
+ token = Rlint::Parser.new(code).parse[0]
480
+
481
+ token.class.should == Rlint::Token::StatementToken
482
+ token.type.should == :until
483
+
484
+ token.statement.class.should == Rlint::Token::Token
485
+ token.statement.type.should == :binary
486
+
487
+ token.statement.value.class.should == Array
488
+ token.statement.value.length.should == 3
489
+
490
+ left, op, right = token.statement.value
491
+
492
+ left.class.should == Rlint::Token::MethodToken
493
+ left.name.should == 'foo'
494
+
495
+ op.should == :==
496
+
497
+ right.class.should == Rlint::Token::MethodToken
498
+ right.name.should == 'bar'
499
+
500
+ token.value.class.should == Array
501
+ token.value.length.should == 1
502
+ end
503
+
504
+ it 'Parse a single line until statement' do
505
+ token = Rlint::Parser.new('foo until bar').parse[0]
506
+
507
+ token.class.should == Rlint::Token::StatementToken
508
+ token.type.should == :until
509
+
510
+ token.statement.class.should == Rlint::Token::MethodToken
511
+ token.statement.name.should == 'bar'
512
+
513
+ token.value.class.should == Array
514
+ token.value.length.should == 1
515
+
516
+ token.value[0].class.should == Rlint::Token::MethodToken
517
+ token.value[0].name.should == 'foo'
518
+ end
519
+
520
+ it 'Parse a tenary operator' do
521
+ token = Rlint::Parser.new('statement ? true : false').parse[0]
522
+
523
+ token.class.should == Rlint::Token::StatementToken
524
+ token.type.should == :if
525
+
526
+ token.statement.class.should == Rlint::Token::MethodToken
527
+ token.statement.name.should == 'statement'
528
+ token.statement.column.should == 0
529
+ token.statement.line.should == 1
530
+
531
+ token.value.class.should == Array
532
+ token.value.length.should == 1
533
+
534
+ token.value[0].class.should == Rlint::Token::VariableToken
535
+ token.value[0].name.should == 'true'
536
+ token.value[0].line.should == 1
537
+ token.value[0].column.should == 12
538
+
539
+ token.else.class.should == Rlint::Token::StatementToken
540
+ token.else.statement.nil?.should == true
541
+ token.else.line.should == 1
542
+ token.else.column.should == 19
543
+
544
+ token.else.value.class.should == Array
545
+ token.else.value.length.should == 1
546
+
547
+ token.else.value[0].class.should == Rlint::Token::VariableToken
548
+ token.else.value[0].name.should == 'false'
549
+ end
550
+ end