tailor 1.0.0.alpha2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.tailor +10 -2
- data/Gemfile.lock +2 -2
- data/History.rdoc +20 -0
- data/README.rdoc +176 -26
- data/features/configurable.feature +19 -39
- data/features/horizontal_spacing.feature +3 -2
- data/features/indentation.feature +2 -2
- data/features/indentation/bad_files_with_no_trailing_newline.feature +9 -8
- data/features/indentation/good_files_with_no_trailing_newline.feature +19 -6
- data/features/name_detection.feature +2 -2
- data/features/support/env.rb +0 -2
- data/features/support/file_cases/horizontal_spacing_cases.rb +5 -4
- data/features/support/file_cases/indentation_cases.rb +105 -54
- data/features/support/file_cases/naming_cases.rb +0 -1
- data/features/support/file_cases/vertical_spacing_cases.rb +0 -1
- data/features/support/legacy/bad_ternary_colon_spacing.rb +1 -1
- data/features/valid_ruby.feature +17 -0
- data/features/vertical_spacing.feature +40 -19
- data/lib/ext/string_ext.rb +12 -0
- data/lib/tailor/cli.rb +7 -5
- data/lib/tailor/cli/options.rb +13 -3
- data/lib/tailor/composite_observable.rb +17 -2
- data/lib/tailor/configuration.rb +83 -72
- data/lib/tailor/configuration/style.rb +85 -0
- data/lib/tailor/critic.rb +67 -117
- data/lib/tailor/formatter.rb +38 -0
- data/lib/tailor/formatters/text.rb +35 -10
- data/lib/tailor/lexed_line.rb +38 -5
- data/lib/tailor/lexer.rb +150 -14
- data/lib/tailor/{lexer_constants.rb → lexer/lexer_constants.rb} +9 -7
- data/lib/tailor/lexer/token.rb +6 -2
- data/lib/tailor/logger.rb +4 -0
- data/lib/tailor/problem.rb +8 -73
- data/lib/tailor/reporter.rb +1 -1
- data/lib/tailor/ruler.rb +67 -6
- data/lib/tailor/rulers/allow_camel_case_methods_ruler.rb +9 -1
- data/lib/tailor/rulers/allow_hard_tabs_ruler.rb +9 -1
- data/lib/tailor/rulers/allow_invalid_ruby_ruler.rb +38 -0
- data/lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb +9 -2
- data/lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb +10 -5
- data/lib/tailor/rulers/indentation_spaces_ruler.rb +93 -26
- data/lib/tailor/rulers/indentation_spaces_ruler/indentation_manager.rb +128 -84
- data/lib/tailor/rulers/max_code_lines_in_class_ruler.rb +9 -5
- data/lib/tailor/rulers/max_code_lines_in_method_ruler.rb +9 -5
- data/lib/tailor/rulers/max_line_length_ruler.rb +10 -5
- data/lib/tailor/rulers/spaces_after_comma_ruler.rb +13 -4
- data/lib/tailor/rulers/spaces_after_lbrace_ruler.rb +8 -4
- data/lib/tailor/rulers/spaces_after_lbracket_ruler.rb +8 -4
- data/lib/tailor/rulers/spaces_after_lparen_ruler.rb +8 -4
- data/lib/tailor/rulers/spaces_before_comma_ruler.rb +8 -4
- data/lib/tailor/rulers/spaces_before_lbrace_ruler.rb +13 -6
- data/lib/tailor/rulers/spaces_before_rbrace_ruler.rb +12 -8
- data/lib/tailor/rulers/spaces_before_rbracket_ruler.rb +12 -5
- data/lib/tailor/rulers/spaces_before_rparen_ruler.rb +13 -6
- data/lib/tailor/rulers/spaces_in_empty_braces_ruler.rb +13 -9
- data/lib/tailor/rulers/trailing_newlines_ruler.rb +10 -5
- data/lib/tailor/tailorrc.erb +3 -3
- data/lib/tailor/version.rb +1 -1
- data/m.rb +15 -0
- data/spec/spec_helper.rb +0 -1
- data/spec/tailor/cli_spec.rb +8 -9
- data/spec/tailor/composite_observable_spec.rb +41 -0
- data/spec/tailor/configuration/style_spec.rb +197 -0
- data/spec/tailor/configuration_spec.rb +52 -33
- data/spec/tailor/critic_spec.rb +7 -8
- data/spec/tailor/formatter_spec.rb +52 -0
- data/spec/tailor/lexed_line_spec.rb +236 -88
- data/spec/tailor/lexer_spec.rb +8 -63
- data/spec/tailor/problem_spec.rb +14 -46
- data/spec/tailor/reporter_spec.rb +8 -8
- data/spec/tailor/ruler_spec.rb +1 -1
- data/spec/tailor/rulers/indentation_spaces_ruler/indentation_manager_spec.rb +132 -176
- data/spec/tailor/rulers/indentation_spaces_ruler_spec.rb +41 -33
- data/spec/tailor/rulers/{spaces_after_comma_spec.rb → spaces_after_comma_ruler_spec.rb} +5 -5
- data/spec/tailor/rulers/spaces_after_lbrace_ruler_spec.rb +14 -14
- data/spec/tailor/rulers/spaces_before_lbrace_ruler_spec.rb +1 -1
- data/spec/tailor/rulers/spaces_before_rbrace_ruler_spec.rb +1 -1
- data/spec/tailor/version_spec.rb +1 -1
- data/spec/tailor_spec.rb +3 -1
- data/tailor.gemspec +11 -3
- data/uest.rb +9 -0
- metadata +66 -41
- data/features/step_definitions/spacing/commas_steps.rb +0 -14
data/spec/tailor/critic_spec.rb
CHANGED
@@ -2,13 +2,12 @@ require_relative '../spec_helper'
|
|
2
2
|
require 'tailor/critic'
|
3
3
|
|
4
4
|
describe Tailor::Critic do
|
5
|
-
|
6
|
-
before { subject.stub(:log) }
|
7
|
-
subject { Tailor::Critic.new(configuration) }
|
5
|
+
before { Tailor::Logger.stub(:log) }
|
8
6
|
|
9
7
|
describe "#check_file" do
|
10
8
|
let(:lexer) { double "Lexer" }
|
11
9
|
let(:ruler) { double "Ruler" }
|
10
|
+
let(:style) { double "Style", each: nil }
|
12
11
|
let(:file_name) { "this_file.rb" }
|
13
12
|
|
14
13
|
before do
|
@@ -22,7 +21,7 @@ describe Tailor::Critic do
|
|
22
21
|
subject.stub_chain(:problems, :[]=)
|
23
22
|
subject.stub_chain(:problems, :[])
|
24
23
|
|
25
|
-
subject.check_file(file_name,
|
24
|
+
subject.check_file(file_name, style)
|
26
25
|
end
|
27
26
|
|
28
27
|
it "adds problems for the file to the main list of problems" do
|
@@ -31,7 +30,7 @@ describe Tailor::Critic do
|
|
31
30
|
Tailor::Lexer.stub(:new).and_return lexer
|
32
31
|
subject.problems.should_receive(:[]=).with(file_name, [])
|
33
32
|
|
34
|
-
subject.check_file(file_name,
|
33
|
+
subject.check_file(file_name, style)
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
@@ -51,9 +50,9 @@ describe Tailor::Critic do
|
|
51
50
|
context "#problems contains valid values" do
|
52
51
|
it "adds the number of each problem together" do
|
53
52
|
probs = {
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
one: { type: :indentation, line: 1, message: "" },
|
54
|
+
two: { type: :indentation, line: 2, message: "" },
|
55
|
+
thre: { type: :indentation, line: 27, message: "" }
|
57
56
|
}
|
58
57
|
subject.instance_variable_set(:@problems, probs)
|
59
58
|
subject.problem_count.should == 3
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require 'tailor/formatter'
|
3
|
+
|
4
|
+
describe Tailor::Formatter do
|
5
|
+
describe "#problems_at_level" do
|
6
|
+
let(:problems) do
|
7
|
+
msg = "File contains invalid Ruby; "
|
8
|
+
msg << "run `ruby -c [your_file.rb]` for more details."
|
9
|
+
|
10
|
+
{
|
11
|
+
"some_file.rb" => [
|
12
|
+
{
|
13
|
+
:type => "allow_invalid_ruby",
|
14
|
+
:line => 0,
|
15
|
+
:column => 0,
|
16
|
+
:message => msg,
|
17
|
+
:level => :warn
|
18
|
+
}
|
19
|
+
]
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
context "problems are empty" do
|
24
|
+
it "returns an empty Array" do
|
25
|
+
subject.problems_at_level({}, :error).should == []
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "the level asked for exists in the problems" do
|
30
|
+
it "returns the problem" do
|
31
|
+
msg = "File contains invalid Ruby; "
|
32
|
+
msg << "run `ruby -c [your_file.rb]` for more details."
|
33
|
+
|
34
|
+
subject.problems_at_level(problems, :warn).should == [
|
35
|
+
{
|
36
|
+
:type => "allow_invalid_ruby",
|
37
|
+
:line => 0,
|
38
|
+
:column => 0,
|
39
|
+
:message => msg,
|
40
|
+
:level => :warn
|
41
|
+
}
|
42
|
+
]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "the level asked for does not exist in the problems" do
|
47
|
+
it "returns an empty Array" do
|
48
|
+
subject.problems_at_level(problems, :error).should == []
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -12,17 +12,17 @@ describe Tailor::LexedLine do
|
|
12
12
|
let(:lexed_output) do
|
13
13
|
[
|
14
14
|
[[1, 0], :on_ident, "require"],
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
15
|
+
[[1, 7], :on_sp, " "],
|
16
|
+
[[1, 8], :on_tstring_beg, "'"],
|
17
|
+
[[1, 9], :on_tstring_content, "log_switch"],
|
18
|
+
[[1, 19], :on_tstring_end, "'"],
|
19
|
+
[[1, 20], :on_nl, "\n"],
|
20
|
+
[[2, 0], :on_ident, "require_relative"],
|
21
|
+
[[2, 16], :on_sp, " "],
|
22
|
+
[[2, 17], :on_tstring_beg, "'"],
|
23
|
+
[[2, 18], :on_tstring_content, "tailor/runtime_error"],
|
24
|
+
[[2, 38], :on_tstring_end, "'"],
|
25
|
+
[[2, 39], :on_nl, "\n"]
|
26
26
|
]
|
27
27
|
end
|
28
28
|
|
@@ -140,11 +140,11 @@ describe Tailor::LexedLine do
|
|
140
140
|
let(:lexed_output) do
|
141
141
|
[
|
142
142
|
[[1, 0], :on_ident, "thing"],
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
143
|
+
[[1, 5], :on_sp, " "],
|
144
|
+
[[1, 6], :on_op, "="],
|
145
|
+
[[1, 7], :on_sp, " "],
|
146
|
+
[[1, 8], :on_int, "1"],
|
147
|
+
[[1, 9], :on_ignored_nl, "\n"]
|
148
148
|
]
|
149
149
|
end
|
150
150
|
|
@@ -159,13 +159,13 @@ describe Tailor::LexedLine do
|
|
159
159
|
let(:lexed_output) do
|
160
160
|
[
|
161
161
|
[[1, 0], :on_ident, "thing"],
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
162
|
+
[[1, 5], :on_sp, " "],
|
163
|
+
[[1, 6], :on_op, "="],
|
164
|
+
[[1, 7], :on_sp, " "],
|
165
|
+
[[1, 8], :on_int, "1"],
|
166
|
+
[[1, 9], :on_sp, " "],
|
167
|
+
[[1, 10], :on_kw, "if"],
|
168
|
+
[[1, 12], :on_ignored_nl, "\n"]
|
169
169
|
]
|
170
170
|
end
|
171
171
|
|
@@ -205,10 +205,10 @@ describe Tailor::LexedLine do
|
|
205
205
|
let(:lexed_output) do
|
206
206
|
[
|
207
207
|
[[1, 0], :on_kw, "def"],
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
208
|
+
[[1, 3], :on_sp, " "],
|
209
|
+
[[1, 4], :on_ident, "thing"],
|
210
|
+
[[1, 9], :on_sp, " "],
|
211
|
+
[[1, 10], :on_nl, "\n"]
|
212
212
|
]
|
213
213
|
end
|
214
214
|
|
@@ -225,10 +225,50 @@ describe Tailor::LexedLine do
|
|
225
225
|
end
|
226
226
|
end
|
227
227
|
|
228
|
+
describe "#last_non_line_feed_event" do
|
229
|
+
context "line ends with a space" do
|
230
|
+
let(:lexed_output) do
|
231
|
+
[
|
232
|
+
[[1, 0], :on_kw, "def"],
|
233
|
+
[[1, 3], :on_sp, " "],
|
234
|
+
[[1, 4], :on_ident, "thing"],
|
235
|
+
[[1, 9], :on_sp, " "],
|
236
|
+
[[1, 10], :on_nl, "\n"]
|
237
|
+
]
|
238
|
+
end
|
239
|
+
|
240
|
+
it "returns the space" do
|
241
|
+
subject.last_non_line_feed_event.should == [[1, 9], :on_sp, " "]
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
context "line ends with a backslash" do
|
246
|
+
let(:lexed_output) do
|
247
|
+
[
|
248
|
+
[[1, 0], :on_kw, "def"],
|
249
|
+
[[1, 3], :on_sp, " "],
|
250
|
+
[[1, 4], :on_ident, "thing"],
|
251
|
+
[[1, 9], :on_sp, "\\\n"]
|
252
|
+
]
|
253
|
+
end
|
254
|
+
|
255
|
+
it "returns the event before it" do
|
256
|
+
subject.last_non_line_feed_event.should == [[1, 4], :on_ident, "thing"]
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
228
261
|
describe "#loop_with_do?" do
|
229
262
|
context "line is 'while true do\\n'" do
|
230
263
|
let(:lexed_output) do
|
231
|
-
[
|
264
|
+
[
|
265
|
+
[[1, 0], :on_kw, "while"],
|
266
|
+
[[1, 5], :on_sp, " "],
|
267
|
+
[[1, 6], :on_kw, "true"],
|
268
|
+
[[1, 10], :on_sp, " "],
|
269
|
+
[[1, 11], :on_kw, "do"],
|
270
|
+
[[1, 13], :on_ignored_nl, "\n"]
|
271
|
+
]
|
232
272
|
end
|
233
273
|
|
234
274
|
it "returns true" do
|
@@ -238,7 +278,13 @@ describe Tailor::LexedLine do
|
|
238
278
|
|
239
279
|
context "line is 'while true\\n'" do
|
240
280
|
let(:lexed_output) do
|
241
|
-
[
|
281
|
+
[
|
282
|
+
[[1, 0], :on_kw, "while"],
|
283
|
+
[[1, 5], :on_sp, " "],
|
284
|
+
[[1, 6], :on_kw, "true"],
|
285
|
+
[[1, 10], :on_sp, " "],
|
286
|
+
[[1, 11], :on_ignored_nl, "\n"]
|
287
|
+
]
|
242
288
|
end
|
243
289
|
|
244
290
|
it "returns false" do
|
@@ -248,7 +294,14 @@ describe Tailor::LexedLine do
|
|
248
294
|
|
249
295
|
context "line is 'until true do\\n'" do
|
250
296
|
let(:lexed_output) do
|
251
|
-
[
|
297
|
+
[
|
298
|
+
[[1, 0], :on_kw, "until"],
|
299
|
+
[[1, 5], :on_sp, " "],
|
300
|
+
[[1, 6], :on_kw, "true"],
|
301
|
+
[[1, 10], :on_sp, " "],
|
302
|
+
[[1, 11], :on_kw, "do"],
|
303
|
+
[[1, 13], :on_ignored_nl, "\n"]
|
304
|
+
]
|
252
305
|
end
|
253
306
|
|
254
307
|
it "returns true" do
|
@@ -258,7 +311,13 @@ describe Tailor::LexedLine do
|
|
258
311
|
|
259
312
|
context "line is 'until true\\n'" do
|
260
313
|
let(:lexed_output) do
|
261
|
-
[
|
314
|
+
[
|
315
|
+
[[1, 0], :on_kw, "until"],
|
316
|
+
[[1, 5], :on_sp, " "],
|
317
|
+
[[1, 6], :on_kw, "true"],
|
318
|
+
[[1, 10], :on_sp, " "],
|
319
|
+
[[1, 11], :on_ignored_nl, "\n"]
|
320
|
+
]
|
262
321
|
end
|
263
322
|
|
264
323
|
it "returns false" do
|
@@ -268,7 +327,20 @@ describe Tailor::LexedLine do
|
|
268
327
|
|
269
328
|
context "line is 'for i in 1..5 do\\n'" do
|
270
329
|
let(:lexed_output) do
|
271
|
-
[
|
330
|
+
[
|
331
|
+
[[1, 0], :on_kw, "for"],
|
332
|
+
[[1, 3], :on_sp, " "],
|
333
|
+
[[1, 4], :on_ident, "i"],
|
334
|
+
[[1, 5], :on_sp, " "],
|
335
|
+
[[1, 6], :on_kw, "in"],
|
336
|
+
[[1, 8], :on_sp, " "],
|
337
|
+
[[1, 9], :on_int, "1"],
|
338
|
+
[[1, 10], :on_op, ".."],
|
339
|
+
[[1, 12], :on_int, "5"],
|
340
|
+
[[1, 13], :on_sp, " "],
|
341
|
+
[[1, 14], :on_kw, "do"],
|
342
|
+
[[1, 16], :on_ignored_nl, "\n"]
|
343
|
+
]
|
272
344
|
end
|
273
345
|
|
274
346
|
it "returns true" do
|
@@ -278,7 +350,19 @@ describe Tailor::LexedLine do
|
|
278
350
|
|
279
351
|
context "line is 'for i in 1..5\\n'" do
|
280
352
|
let(:lexed_output) do
|
281
|
-
[
|
353
|
+
[
|
354
|
+
[[1, 0], :on_kw, "for"],
|
355
|
+
[[1, 3], :on_sp, " "],
|
356
|
+
[[1, 4], :on_ident, "i"],
|
357
|
+
[[1, 5], :on_sp, " "],
|
358
|
+
[[1, 6], :on_kw, "in"],
|
359
|
+
[[1, 8], :on_sp, " "],
|
360
|
+
[[1, 9], :on_int, "1"],
|
361
|
+
[[1, 10], :on_op, ".."],
|
362
|
+
[[1, 12], :on_int, "5"],
|
363
|
+
[[1, 13], :on_sp, " "],
|
364
|
+
[[1, 14], :on_ignored_nl, "\n"]
|
365
|
+
]
|
282
366
|
end
|
283
367
|
|
284
368
|
it "returns false" do
|
@@ -305,7 +389,13 @@ describe Tailor::LexedLine do
|
|
305
389
|
end
|
306
390
|
|
307
391
|
context "lexed line contains ' }\\n'" do
|
308
|
-
let(:lexed_output)
|
392
|
+
let(:lexed_output) do
|
393
|
+
[
|
394
|
+
[[1, 0], :on_sp, " "],
|
395
|
+
[[1, 2], :on_rbrace, "}"],
|
396
|
+
[[1, 3], :on_nl, "\n"]
|
397
|
+
]
|
398
|
+
end
|
309
399
|
|
310
400
|
it "returns nil" do
|
311
401
|
subject.first_non_space_element.should == [[1, 2], :on_rbrace, "}"]
|
@@ -348,10 +438,10 @@ describe Tailor::LexedLine do
|
|
348
438
|
let(:lexed_output) do
|
349
439
|
[
|
350
440
|
[[1, 0], :on_kw, "def"],
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
441
|
+
[[1, 3], :on_sp, " "],
|
442
|
+
[[1, 4], :on_ident, "thing"],
|
443
|
+
[[1, 9], :on_sp, " "],
|
444
|
+
[[1, 10], :on_nl, "\n"]
|
355
445
|
]
|
356
446
|
end
|
357
447
|
|
@@ -366,13 +456,13 @@ describe Tailor::LexedLine do
|
|
366
456
|
let(:lexed_output) do
|
367
457
|
[
|
368
458
|
[[1, 0], :on_kw, "def"],
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
459
|
+
[[1, 3], :on_sp, " "],
|
460
|
+
[[1, 4], :on_ident, "thing"],
|
461
|
+
[[1, 9], :on_sp, " "],
|
462
|
+
[[1, 10], :on_ident, "one"],
|
463
|
+
[[1, 13], :on_comma, ","],
|
464
|
+
[[1, 14], :on_sp, " "],
|
465
|
+
[[1, 16], :on_comment, "# comment\n"]
|
376
466
|
]
|
377
467
|
end
|
378
468
|
|
@@ -383,26 +473,26 @@ describe Tailor::LexedLine do
|
|
383
473
|
it "replaces the comment with an :on_ignored_nl" do
|
384
474
|
subject.remove_trailing_comment(file_text).should == [
|
385
475
|
[[1, 0], :on_kw, "def"],
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
476
|
+
[[1, 3], :on_sp, " "],
|
477
|
+
[[1, 4], :on_ident, "thing"],
|
478
|
+
[[1, 9], :on_sp, " "],
|
479
|
+
[[1, 10], :on_ident, "one"],
|
480
|
+
[[1, 13], :on_comma, ","],
|
481
|
+
[[1, 14], :on_ignored_nl, "\n"]
|
392
482
|
]
|
393
483
|
end
|
394
484
|
end
|
395
|
-
|
485
|
+
|
396
486
|
context "no spaces before comment" do
|
397
487
|
let(:lexed_output) do
|
398
488
|
[
|
399
489
|
[[1, 0], :on_kw, "def"],
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
490
|
+
[[1, 3], :on_sp, " "],
|
491
|
+
[[1, 4], :on_ident, "thing"],
|
492
|
+
[[1, 9], :on_sp, " "],
|
493
|
+
[[1, 10], :on_ident, "one"],
|
494
|
+
[[1, 13], :on_comma, ","],
|
495
|
+
[[1, 14], :on_comment, "# comment\n"]
|
406
496
|
]
|
407
497
|
end
|
408
498
|
|
@@ -413,28 +503,28 @@ describe Tailor::LexedLine do
|
|
413
503
|
it "replaces the comment with an :on_ignored_nl" do
|
414
504
|
subject.remove_trailing_comment(file_text).should == [
|
415
505
|
[[1, 0], :on_kw, "def"],
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
506
|
+
[[1, 3], :on_sp, " "],
|
507
|
+
[[1, 4], :on_ident, "thing"],
|
508
|
+
[[1, 9], :on_sp, " "],
|
509
|
+
[[1, 10], :on_ident, "one"],
|
510
|
+
[[1, 13], :on_comma, ","],
|
511
|
+
[[1, 14], :on_ignored_nl, "\n"]
|
422
512
|
]
|
423
513
|
end
|
424
514
|
end
|
425
515
|
end
|
426
|
-
|
516
|
+
|
427
517
|
context "stuff before comment is a complete statement" do
|
428
518
|
context "spaces before comment" do
|
429
519
|
let(:lexed_output) do
|
430
520
|
[
|
431
521
|
[[1, 0], :on_kw, "def"],
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
522
|
+
[[1, 3], :on_sp, " "],
|
523
|
+
[[1, 4], :on_ident, "thing"],
|
524
|
+
[[1, 9], :on_sp, " "],
|
525
|
+
[[1, 10], :on_ident, "one"],
|
526
|
+
[[1, 13], :on_sp, " "],
|
527
|
+
[[1, 15], :on_comment, "# comment\n"]
|
438
528
|
]
|
439
529
|
end
|
440
530
|
|
@@ -445,11 +535,11 @@ describe Tailor::LexedLine do
|
|
445
535
|
it "replaces the comment with an :on_nl" do
|
446
536
|
subject.remove_trailing_comment(file_text).should == [
|
447
537
|
[[1, 0], :on_kw, "def"],
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
538
|
+
[[1, 3], :on_sp, " "],
|
539
|
+
[[1, 4], :on_ident, "thing"],
|
540
|
+
[[1, 9], :on_sp, " "],
|
541
|
+
[[1, 10], :on_ident, "one"],
|
542
|
+
[[1, 13], :on_nl, "\n"]
|
453
543
|
]
|
454
544
|
end
|
455
545
|
end
|
@@ -458,11 +548,11 @@ describe Tailor::LexedLine do
|
|
458
548
|
let(:lexed_output) do
|
459
549
|
[
|
460
550
|
[[1, 0], :on_kw, "def"],
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
551
|
+
[[1, 3], :on_sp, " "],
|
552
|
+
[[1, 4], :on_ident, "thing"],
|
553
|
+
[[1, 9], :on_sp, " "],
|
554
|
+
[[1, 10], :on_ident, "one"],
|
555
|
+
[[1, 13], :on_comment, "# comment\n"]
|
466
556
|
]
|
467
557
|
end
|
468
558
|
|
@@ -473,16 +563,17 @@ describe Tailor::LexedLine do
|
|
473
563
|
it "replaces the comment with an :on_nl" do
|
474
564
|
subject.remove_trailing_comment(file_text).should == [
|
475
565
|
[[1, 0], :on_kw, "def"],
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
566
|
+
[[1, 3], :on_sp, " "],
|
567
|
+
[[1, 4], :on_ident, "thing"],
|
568
|
+
[[1, 9], :on_sp, " "],
|
569
|
+
[[1, 10], :on_ident, "one"],
|
570
|
+
[[1, 13], :on_nl, "\n"]
|
481
571
|
]
|
482
572
|
end
|
483
|
-
|
573
|
+
|
484
574
|
it "returns a LexedLine" do
|
485
|
-
subject.remove_trailing_comment(file_text).
|
575
|
+
subject.remove_trailing_comment(file_text).
|
576
|
+
should be_a Tailor::LexedLine
|
486
577
|
end
|
487
578
|
end
|
488
579
|
end
|
@@ -566,4 +657,61 @@ describe Tailor::LexedLine do
|
|
566
657
|
end
|
567
658
|
end
|
568
659
|
end
|
660
|
+
|
661
|
+
describe "#keyword_is_symbol?" do
|
662
|
+
context "last event in line is not a keyword" do
|
663
|
+
let(:lexed_output) do
|
664
|
+
[
|
665
|
+
[[1, 0], :on_sp, " "],
|
666
|
+
[[1, 8], :on_ident, "one"],
|
667
|
+
[[1, 11], :on_comma, ","],
|
668
|
+
[[1, 12], :on_nl, "\n"]]
|
669
|
+
end
|
670
|
+
|
671
|
+
it "returns false" do
|
672
|
+
subject.keyword_is_symbol?.should be_false
|
673
|
+
end
|
674
|
+
end
|
675
|
+
|
676
|
+
context "last event in line is a keyword" do
|
677
|
+
context "previous event is nil" do
|
678
|
+
let(:lexed_output) do
|
679
|
+
[
|
680
|
+
[[1, 0], :on_kw, "class"]
|
681
|
+
]
|
682
|
+
end
|
683
|
+
|
684
|
+
it "returns false" do
|
685
|
+
subject.keyword_is_symbol?.should be_false
|
686
|
+
end
|
687
|
+
end
|
688
|
+
|
689
|
+
context "previous event is not :on_symbeg" do
|
690
|
+
let(:lexed_output) do
|
691
|
+
[
|
692
|
+
[[1, 0], :on_sp, " "],
|
693
|
+
[[1, 2], :on_kw, "class"]
|
694
|
+
]
|
695
|
+
end
|
696
|
+
|
697
|
+
it "returns false" do
|
698
|
+
subject.keyword_is_symbol?.should be_false
|
699
|
+
end
|
700
|
+
end
|
701
|
+
|
702
|
+
context "previous event is :on_symbeg" do
|
703
|
+
let(:lexed_output) do
|
704
|
+
[
|
705
|
+
[[1, 0], :on_const, "INDENT_OK"],
|
706
|
+
[[1, 9], :on_lbracket, "["],
|
707
|
+
[[1, 10], :on_symbeg, ":"],
|
708
|
+
[[1, 11], :on_kw, "class"]]
|
709
|
+
end
|
710
|
+
|
711
|
+
it "returns true" do
|
712
|
+
subject.keyword_is_symbol?.should be_true
|
713
|
+
end
|
714
|
+
end
|
715
|
+
end
|
716
|
+
end
|
569
717
|
end
|