tailor 0.1.5 → 1.0.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -1
- data/.rspec +2 -1
- data/.tailor +6 -0
- data/Gemfile.lock +47 -78
- data/{ChangeLog.rdoc → History.rdoc} +0 -0
- data/README.rdoc +157 -24
- data/Rakefile +0 -9
- data/bin/tailor +16 -69
- data/features/configurable.feature +78 -0
- data/features/horizontal_spacing.feature +262 -0
- data/features/indentation.feature +17 -21
- data/features/indentation/bad_files_with_no_trailing_newline.feature +90 -0
- data/features/indentation/good_files_with_no_trailing_newline.feature +206 -0
- data/features/name_detection.feature +72 -0
- data/features/step_definitions/indentation_steps.rb +10 -133
- data/features/support/env.rb +7 -15
- data/features/support/file_cases/horizontal_spacing_cases.rb +265 -0
- data/features/support/file_cases/indentation_cases.rb +972 -0
- data/features/support/file_cases/naming_cases.rb +52 -0
- data/features/support/file_cases/vertical_spacing_cases.rb +70 -0
- data/features/support/hooks.rb +8 -0
- data/features/support/{1_file_with_bad_operator_spacing → legacy}/bad_op_spacing.rb +0 -0
- data/features/support/{1_file_with_bad_ternary_colon_spacing → legacy}/bad_ternary_colon_spacing.rb +0 -0
- data/features/support/{1_long_file_with_indentation/my_project.rb → legacy/long_file_with_indentation.rb} +1 -1
- data/features/support/world.rb +14 -0
- data/features/vertical_spacing.feature +114 -0
- data/lib/ext/string_ext.rb +5 -0
- data/lib/tailor.rb +6 -252
- data/lib/tailor/cli.rb +49 -0
- data/lib/tailor/cli/options.rb +251 -0
- data/lib/tailor/composite_observable.rb +56 -0
- data/lib/tailor/configuration.rb +263 -0
- data/lib/tailor/critic.rb +162 -0
- data/lib/tailor/formatters/text.rb +126 -0
- data/lib/tailor/lexed_line.rb +246 -0
- data/lib/tailor/lexer.rb +428 -0
- data/lib/tailor/lexer/token.rb +103 -0
- data/lib/tailor/lexer_constants.rb +75 -0
- data/lib/tailor/logger.rb +28 -0
- data/lib/tailor/problem.rb +100 -0
- data/lib/tailor/reporter.rb +48 -0
- data/lib/tailor/ruler.rb +39 -0
- data/lib/tailor/rulers.rb +7 -0
- data/lib/tailor/rulers/allow_camel_case_methods_ruler.rb +30 -0
- data/lib/tailor/rulers/allow_hard_tabs_ruler.rb +22 -0
- data/lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb +32 -0
- data/lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb +33 -0
- data/lib/tailor/rulers/indentation_spaces_ruler.rb +199 -0
- data/lib/tailor/rulers/indentation_spaces_ruler/indentation_manager.rb +362 -0
- data/lib/tailor/rulers/max_code_lines_in_class_ruler.rb +84 -0
- data/lib/tailor/rulers/max_code_lines_in_method_ruler.rb +84 -0
- data/lib/tailor/rulers/max_line_length_ruler.rb +31 -0
- data/lib/tailor/rulers/spaces_after_comma_ruler.rb +83 -0
- data/lib/tailor/rulers/spaces_after_lbrace_ruler.rb +114 -0
- data/lib/tailor/rulers/spaces_after_lbracket_ruler.rb +123 -0
- data/lib/tailor/rulers/spaces_after_lparen_ruler.rb +116 -0
- data/lib/tailor/rulers/spaces_before_comma_ruler.rb +67 -0
- data/lib/tailor/rulers/spaces_before_lbrace_ruler.rb +93 -0
- data/lib/tailor/rulers/spaces_before_rbrace_ruler.rb +98 -0
- data/lib/tailor/rulers/spaces_before_rbracket_ruler.rb +70 -0
- data/lib/tailor/rulers/spaces_before_rparen_ruler.rb +70 -0
- data/lib/tailor/rulers/spaces_in_empty_braces_ruler.rb +94 -0
- data/lib/tailor/rulers/trailing_newlines_ruler.rb +36 -0
- data/lib/tailor/runtime_error.rb +3 -0
- data/lib/tailor/tailorrc.erb +88 -0
- data/lib/tailor/version.rb +2 -2
- data/spec/spec_helper.rb +7 -5
- data/spec/tailor/cli_spec.rb +94 -0
- data/spec/tailor/configuration_spec.rb +147 -0
- data/spec/tailor/critic_spec.rb +63 -0
- data/spec/tailor/lexed_line_spec.rb +569 -0
- data/spec/tailor/lexer/token_spec.rb +46 -0
- data/spec/tailor/lexer_spec.rb +181 -0
- data/spec/tailor/options_spec.rb +6 -0
- data/spec/tailor/problem_spec.rb +74 -0
- data/spec/tailor/reporter_spec.rb +53 -0
- data/spec/tailor/ruler_spec.rb +56 -0
- data/spec/tailor/rulers/indentation_spaces_ruler/indentation_manager_spec.rb +454 -0
- data/spec/tailor/rulers/indentation_spaces_ruler_spec.rb +128 -0
- data/spec/tailor/rulers/spaces_after_comma_spec.rb +31 -0
- data/spec/tailor/rulers/spaces_after_lbrace_ruler_spec.rb +145 -0
- data/spec/tailor/rulers/spaces_before_lbrace_ruler_spec.rb +63 -0
- data/spec/tailor/rulers/spaces_before_rbrace_ruler_spec.rb +63 -0
- data/spec/tailor/rulers_spec.rb +9 -0
- data/spec/tailor/version_spec.rb +6 -0
- data/spec/tailor_spec.rb +9 -21
- data/tailor.gemspec +22 -35
- data/tasks/features.rake +7 -0
- data/tasks/roodi.rake +9 -0
- data/tasks/roodi_config.yaml +14 -0
- data/tasks/spec.rake +16 -0
- data/tasks/yard.rake +14 -0
- metadata +224 -77
- data/features/case_checking.feature +0 -38
- data/features/spacing.feature +0 -97
- data/features/spacing/commas.feature +0 -44
- data/features/step_definitions/case_checking_steps.rb +0 -42
- data/features/step_definitions/spacing_steps.rb +0 -156
- data/features/support/1_file_with_bad_comma_spacing/bad_comma_spacing.rb +0 -43
- data/features/support/1_file_with_bad_curly_brace_spacing/bad_curly_brace_spacing.rb +0 -60
- data/features/support/1_file_with_bad_parenthesis/bad_parenthesis.rb +0 -4
- data/features/support/1_file_with_bad_square_brackets/bad_square_brackets.rb +0 -62
- data/features/support/1_file_with_camel_case_class/camel_case_class.rb +0 -5
- data/features/support/1_file_with_camel_case_method/camel_case_method.rb +0 -3
- data/features/support/1_file_with_hard_tabs/hard_tab.rb +0 -3
- data/features/support/1_file_with_long_lines/long_lines.rb +0 -5
- data/features/support/1_file_with_snake_case_class/snake_case_class.rb +0 -5
- data/features/support/1_file_with_snake_case_method/snake_case_method.rb +0 -3
- data/features/support/1_file_with_trailing_whitespace/trailing_whitespace.rb +0 -5
- data/features/support/1_good_simple_file/simple_project.rb +0 -5
- data/features/support/common.rb +0 -102
- data/features/support/matchers.rb +0 -11
- data/lib/tailor/file_line.rb +0 -220
- data/lib/tailor/indentation.rb +0 -245
- data/lib/tailor/spacing.rb +0 -237
- data/spec/file_line_spec.rb +0 -70
- data/spec/indentation_spec.rb +0 -259
- data/spec/spacing/colon_spacing_spec.rb +0 -71
- data/spec/spacing/comma_spacing_spec.rb +0 -159
- data/spec/spacing/curly_brace_spacing_spec.rb +0 -257
- data/spec/spacing/parentheses_spacing_spec.rb +0 -28
- data/spec/spacing/square_bracket_spacing_spec.rb +0 -116
- data/spec/spacing_spec.rb +0 -167
- data/tasks/metrics.rake +0 -23
@@ -0,0 +1,569 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require 'tailor/lexed_line'
|
3
|
+
|
4
|
+
describe Tailor::LexedLine do
|
5
|
+
before do
|
6
|
+
Tailor::Logger.stub(:log)
|
7
|
+
end
|
8
|
+
|
9
|
+
subject { Tailor::LexedLine.new(lexed_output, 1) }
|
10
|
+
|
11
|
+
describe "#initialize" do
|
12
|
+
let(:lexed_output) do
|
13
|
+
[
|
14
|
+
[[1, 0], :on_ident, "require"],
|
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
|
+
]
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns all lexed output from line 1 when self.lineno is 1" do
|
30
|
+
line = Tailor::LexedLine.new(lexed_output, 1)
|
31
|
+
|
32
|
+
line.should == [
|
33
|
+
[[1, 0], :on_ident, "require"],
|
34
|
+
[[1, 7], :on_sp, " "],
|
35
|
+
[[1, 8], :on_tstring_beg, "'"],
|
36
|
+
[[1, 9], :on_tstring_content, "log_switch"],
|
37
|
+
[[1, 19], :on_tstring_end, "'"],
|
38
|
+
[[1, 20], :on_nl, "\n"]
|
39
|
+
]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#only_spaces?" do
|
44
|
+
context '0 length line, no \n ending' do
|
45
|
+
let(:lexed_output) { [[[1, 0], :on_sp, " "]] }
|
46
|
+
|
47
|
+
it "should return true" do
|
48
|
+
subject.only_spaces?.should be_true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context '0 length line, with \n ending' do
|
53
|
+
let(:lexed_output) { [[[1, 0], :on_nl, "\n"]] }
|
54
|
+
|
55
|
+
it "should return true" do
|
56
|
+
subject.only_spaces?.should be_true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'comment line, starting at column 0' do
|
61
|
+
let(:lexed_output) { [[[1, 0], :on_comment, "# comment"]] }
|
62
|
+
|
63
|
+
it "should return false" do
|
64
|
+
subject.only_spaces?.should be_false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'comment line, starting at column 2' do
|
69
|
+
let(:lexed_output) do
|
70
|
+
[
|
71
|
+
[[1, 0], :on_sp, " "],
|
72
|
+
[[1, 2], :on_comment, "# comment"]
|
73
|
+
]
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should return false" do
|
77
|
+
subject.only_spaces?.should be_false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'code line, starting at column 2' do
|
82
|
+
let(:lexed_output) do
|
83
|
+
[
|
84
|
+
[[1, 0], :on_ident, "puts"],
|
85
|
+
[[1, 4], :on_sp, " "],
|
86
|
+
[[1, 5], :on_tstring_beg, "'"],
|
87
|
+
[[1, 6], :on_tstring_content, "thing"],
|
88
|
+
[[1, 11], :on_tstring_end, "'"],
|
89
|
+
[[1, 12], :on_nl, "\n"]
|
90
|
+
]
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should return false" do
|
94
|
+
subject.only_spaces?.should be_false
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "#ends_with_op?" do
|
100
|
+
context "line ends with a +, then \\n" do
|
101
|
+
let(:lexed_output) do
|
102
|
+
[
|
103
|
+
[[1, 0], :on_ident, "thing"],
|
104
|
+
[[1, 5], :on_sp, " "],
|
105
|
+
[[1, 6], :on_op, "="],
|
106
|
+
[[1, 7], :on_sp, " "],
|
107
|
+
[[1, 8], :on_int, "1"],
|
108
|
+
[[1, 9], :on_sp, " "],
|
109
|
+
[[1, 10], :on_op, "+"],
|
110
|
+
[[1, 11], :on_ignored_nl, "\n"],
|
111
|
+
[[1, 11], :on_ignored_nl, "\n"]
|
112
|
+
]
|
113
|
+
end
|
114
|
+
|
115
|
+
it "returns true" do
|
116
|
+
subject.ends_with_op?.should be_true
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "line ends with not an operator, then \\n" do
|
121
|
+
let(:lexed_output) do
|
122
|
+
[
|
123
|
+
[[1, 0], :on_ident, "thing"],
|
124
|
+
[[1, 5], :on_sp, " "],
|
125
|
+
[[1, 6], :on_op, "="],
|
126
|
+
[[1, 7], :on_sp, " "],
|
127
|
+
[[1, 8], :on_int, "1"],
|
128
|
+
[[1, 11], :on_nl, "\n"]
|
129
|
+
]
|
130
|
+
end
|
131
|
+
|
132
|
+
it "returns false" do
|
133
|
+
subject.ends_with_op?.should be_false
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "#ends_with_modifier_kw?" do
|
139
|
+
context "ends_with_kw? is false" do
|
140
|
+
let(:lexed_output) do
|
141
|
+
[
|
142
|
+
[[1, 0], :on_ident, "thing"],
|
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
|
+
]
|
149
|
+
end
|
150
|
+
|
151
|
+
before { subject.stub(:ends_with_kw?).and_return true }
|
152
|
+
|
153
|
+
it "returns false" do
|
154
|
+
subject.ends_with_modifier_kw?.should be_false
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context "#ends_with_kw? is true" do
|
159
|
+
let(:lexed_output) do
|
160
|
+
[
|
161
|
+
[[1, 0], :on_ident, "thing"],
|
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
|
+
]
|
170
|
+
end
|
171
|
+
|
172
|
+
let(:token) { double "Token" }
|
173
|
+
|
174
|
+
context "the keyword is a modifier" do
|
175
|
+
before do
|
176
|
+
token.stub(:modifier_keyword?).and_return true
|
177
|
+
Tailor::Lexer::Token.stub(:new).and_return token
|
178
|
+
subject.stub(:ends_with_kw?).and_return true
|
179
|
+
end
|
180
|
+
|
181
|
+
after { Tailor::Lexer::Token.unstub(:new) }
|
182
|
+
|
183
|
+
it "returns true" do
|
184
|
+
subject.ends_with_modifier_kw?.should be_true
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context "the keyword is not a modifier" do
|
189
|
+
before do
|
190
|
+
token.stub(:modifier_keyword?).and_return false
|
191
|
+
Tailor::Lexer::Token.stub(:new).and_return token
|
192
|
+
subject.stub(:ends_with_kw?).and_return true
|
193
|
+
end
|
194
|
+
|
195
|
+
after { Tailor::Lexer::Token.unstub(:new) }
|
196
|
+
|
197
|
+
it "returns true" do
|
198
|
+
subject.ends_with_modifier_kw?.should be_false
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe "#does_line_end_with" do
|
205
|
+
let(:lexed_output) do
|
206
|
+
[
|
207
|
+
[[1, 0], :on_kw, "def"],
|
208
|
+
[[1, 3], :on_sp, " "],
|
209
|
+
[[1, 4], :on_ident, "thing"],
|
210
|
+
[[1, 9], :on_sp, " "],
|
211
|
+
[[1, 10], :on_nl, "\n"]
|
212
|
+
]
|
213
|
+
end
|
214
|
+
|
215
|
+
context "line ends with the event" do
|
216
|
+
it "returns true" do
|
217
|
+
subject.does_line_end_with(:on_sp).should be_true
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
context "line does not even with event" do
|
222
|
+
it "returns false" do
|
223
|
+
subject.does_line_end_with(:on_kw).should be_false
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
describe "#loop_with_do?" do
|
229
|
+
context "line is 'while true do\\n'" do
|
230
|
+
let(:lexed_output) do
|
231
|
+
[[[1, 0], :on_kw, "while"], [[1, 5], :on_sp, " "], [[1, 6], :on_kw, "true"], [[1, 10], :on_sp, " "], [[1, 11], :on_kw, "do"], [[1, 13], :on_ignored_nl, "\n"]]
|
232
|
+
end
|
233
|
+
|
234
|
+
it "returns true" do
|
235
|
+
subject.loop_with_do?.should be_true
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
context "line is 'while true\\n'" do
|
240
|
+
let(:lexed_output) do
|
241
|
+
[[[1, 0], :on_kw, "while"], [[1, 5], :on_sp, " "], [[1, 6], :on_kw, "true"], [[1, 10], :on_sp, " "], [[1, 11], :on_ignored_nl, "\n"]]
|
242
|
+
end
|
243
|
+
|
244
|
+
it "returns false" do
|
245
|
+
subject.loop_with_do?.should be_false
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
context "line is 'until true do\\n'" do
|
250
|
+
let(:lexed_output) do
|
251
|
+
[[[1, 0], :on_kw, "until"], [[1, 5], :on_sp, " "], [[1, 6], :on_kw, "true"], [[1, 10], :on_sp, " "], [[1, 11], :on_kw, "do"], [[1, 13], :on_ignored_nl, "\n"]]
|
252
|
+
end
|
253
|
+
|
254
|
+
it "returns true" do
|
255
|
+
subject.loop_with_do?.should be_true
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
context "line is 'until true\\n'" do
|
260
|
+
let(:lexed_output) do
|
261
|
+
[[[1, 0], :on_kw, "until"], [[1, 5], :on_sp, " "], [[1, 6], :on_kw, "true"], [[1, 10], :on_sp, " "], [[1, 11], :on_ignored_nl, "\n"]]
|
262
|
+
end
|
263
|
+
|
264
|
+
it "returns false" do
|
265
|
+
subject.loop_with_do?.should be_false
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
context "line is 'for i in 1..5 do\\n'" do
|
270
|
+
let(:lexed_output) do
|
271
|
+
[[[1, 0], :on_kw, "for"], [[1, 3], :on_sp, " "], [[1, 4], :on_ident, "i"], [[1, 5], :on_sp, " "], [[1, 6], :on_kw, "in"], [[1, 8], :on_sp, " "], [[1, 9], :on_int, "1"], [[1, 10], :on_op, ".."], [[1, 12], :on_int, "5"], [[1, 13], :on_sp, " "], [[1, 14], :on_kw, "do"], [[1, 16], :on_ignored_nl, "\n"]]
|
272
|
+
end
|
273
|
+
|
274
|
+
it "returns true" do
|
275
|
+
subject.loop_with_do?.should be_true
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
context "line is 'for i in 1..5\\n'" do
|
280
|
+
let(:lexed_output) do
|
281
|
+
[[[1, 0], :on_kw, "for"], [[1, 3], :on_sp, " "], [[1, 4], :on_ident, "i"], [[1, 5], :on_sp, " "], [[1, 6], :on_kw, "in"], [[1, 8], :on_sp, " "], [[1, 9], :on_int, "1"], [[1, 10], :on_op, ".."], [[1, 12], :on_int, "5"], [[1, 13], :on_sp, " "], [[1, 14], :on_ignored_nl, "\n"]]
|
282
|
+
end
|
283
|
+
|
284
|
+
it "returns false" do
|
285
|
+
subject.loop_with_do?.should be_false
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
describe "#first_non_space_element" do
|
291
|
+
context "lexed line contains only spaces" do
|
292
|
+
let(:lexed_output) { [[[1, 0], :on_sp, " "]] }
|
293
|
+
|
294
|
+
it "returns nil" do
|
295
|
+
subject.first_non_space_element.should be_nil
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
context "lexed line contains only \\n" do
|
300
|
+
let(:lexed_output) { [[[1, 0], :on_ignored_nl, "\n"]] }
|
301
|
+
|
302
|
+
it "returns nil" do
|
303
|
+
subject.first_non_space_element.should be_nil
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
context "lexed line contains ' }\\n'" do
|
308
|
+
let(:lexed_output) { [[[1, 0], :on_sp, " "], [[1, 2], :on_rbrace, "}"], [[1, 3], :on_nl, "\n"]] }
|
309
|
+
|
310
|
+
it "returns nil" do
|
311
|
+
subject.first_non_space_element.should == [[1, 2], :on_rbrace, "}"]
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
describe "#event_at" do
|
317
|
+
let(:lexed_output) { [[[1, 0], :on_sp, " "]] }
|
318
|
+
|
319
|
+
context "self contains an event at the given column" do
|
320
|
+
it "returns that event" do
|
321
|
+
subject.event_at(0).should == lexed_output.first
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
context "self does not contain an event at the given column" do
|
326
|
+
it "returns nil" do
|
327
|
+
subject.event_at(1234).should be_nil
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
describe "#event_index" do
|
333
|
+
let(:lexed_output) { [[[1, 0], :on_sp, " "]] }
|
334
|
+
|
335
|
+
context "#event_at returns nil" do
|
336
|
+
before { subject.stub(:event_at).and_return nil }
|
337
|
+
specify { subject.event_index(1234).should be_nil }
|
338
|
+
end
|
339
|
+
|
340
|
+
context "#event_at returns a valid column" do
|
341
|
+
it "returns the event" do
|
342
|
+
subject.event_index(0).should be_zero
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
describe "#to_s" do
|
348
|
+
let(:lexed_output) do
|
349
|
+
[
|
350
|
+
[[1, 0], :on_kw, "def"],
|
351
|
+
[[1, 3], :on_sp, " "],
|
352
|
+
[[1, 4], :on_ident, "thing"],
|
353
|
+
[[1, 9], :on_sp, " "],
|
354
|
+
[[1, 10], :on_nl, "\n"]
|
355
|
+
]
|
356
|
+
end
|
357
|
+
|
358
|
+
it "returns the String made up of self's tokens" do
|
359
|
+
subject.to_s.should == "def thing \n"
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
describe "#remove_comment_at" do
|
364
|
+
context "stuff before comment is an incomplete statement" do
|
365
|
+
context "spaces before comment" do
|
366
|
+
let(:lexed_output) do
|
367
|
+
[
|
368
|
+
[[1, 0], :on_kw, "def"],
|
369
|
+
[[1, 3], :on_sp, " "],
|
370
|
+
[[1, 4], :on_ident, "thing"],
|
371
|
+
[[1, 9], :on_sp, " "],
|
372
|
+
[[1, 10], :on_ident, "one"],
|
373
|
+
[[1, 13], :on_comma, ","],
|
374
|
+
[[1, 14], :on_sp, " "],
|
375
|
+
[[1, 16], :on_comment, "# comment\n"]
|
376
|
+
]
|
377
|
+
end
|
378
|
+
|
379
|
+
let(:file_text) do
|
380
|
+
"def thing one, # comment\n two\nend\n"
|
381
|
+
end
|
382
|
+
|
383
|
+
it "replaces the comment with an :on_ignored_nl" do
|
384
|
+
subject.remove_trailing_comment(file_text).should == [
|
385
|
+
[[1, 0], :on_kw, "def"],
|
386
|
+
[[1, 3], :on_sp, " "],
|
387
|
+
[[1, 4], :on_ident, "thing"],
|
388
|
+
[[1, 9], :on_sp, " "],
|
389
|
+
[[1, 10], :on_ident, "one"],
|
390
|
+
[[1, 13], :on_comma, ","],
|
391
|
+
[[1, 14], :on_ignored_nl, "\n"]
|
392
|
+
]
|
393
|
+
end
|
394
|
+
end
|
395
|
+
|
396
|
+
context "no spaces before comment" do
|
397
|
+
let(:lexed_output) do
|
398
|
+
[
|
399
|
+
[[1, 0], :on_kw, "def"],
|
400
|
+
[[1, 3], :on_sp, " "],
|
401
|
+
[[1, 4], :on_ident, "thing"],
|
402
|
+
[[1, 9], :on_sp, " "],
|
403
|
+
[[1, 10], :on_ident, "one"],
|
404
|
+
[[1, 13], :on_comma, ","],
|
405
|
+
[[1, 14], :on_comment, "# comment\n"]
|
406
|
+
]
|
407
|
+
end
|
408
|
+
|
409
|
+
let(:file_text) do
|
410
|
+
"def thing one,# comment\n two\nend\n"
|
411
|
+
end
|
412
|
+
|
413
|
+
it "replaces the comment with an :on_ignored_nl" do
|
414
|
+
subject.remove_trailing_comment(file_text).should == [
|
415
|
+
[[1, 0], :on_kw, "def"],
|
416
|
+
[[1, 3], :on_sp, " "],
|
417
|
+
[[1, 4], :on_ident, "thing"],
|
418
|
+
[[1, 9], :on_sp, " "],
|
419
|
+
[[1, 10], :on_ident, "one"],
|
420
|
+
[[1, 13], :on_comma, ","],
|
421
|
+
[[1, 14], :on_ignored_nl, "\n"]
|
422
|
+
]
|
423
|
+
end
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
context "stuff before comment is a complete statement" do
|
428
|
+
context "spaces before comment" do
|
429
|
+
let(:lexed_output) do
|
430
|
+
[
|
431
|
+
[[1, 0], :on_kw, "def"],
|
432
|
+
[[1, 3], :on_sp, " "],
|
433
|
+
[[1, 4], :on_ident, "thing"],
|
434
|
+
[[1, 9], :on_sp, " "],
|
435
|
+
[[1, 10], :on_ident, "one"],
|
436
|
+
[[1, 13], :on_sp, " "],
|
437
|
+
[[1, 15], :on_comment, "# comment\n"]
|
438
|
+
]
|
439
|
+
end
|
440
|
+
|
441
|
+
let(:file_text) do
|
442
|
+
"def thing one # comment\n\nend\n"
|
443
|
+
end
|
444
|
+
|
445
|
+
it "replaces the comment with an :on_nl" do
|
446
|
+
subject.remove_trailing_comment(file_text).should == [
|
447
|
+
[[1, 0], :on_kw, "def"],
|
448
|
+
[[1, 3], :on_sp, " "],
|
449
|
+
[[1, 4], :on_ident, "thing"],
|
450
|
+
[[1, 9], :on_sp, " "],
|
451
|
+
[[1, 10], :on_ident, "one"],
|
452
|
+
[[1, 13], :on_nl, "\n"]
|
453
|
+
]
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
context "no spaces before comment" do
|
458
|
+
let(:lexed_output) do
|
459
|
+
[
|
460
|
+
[[1, 0], :on_kw, "def"],
|
461
|
+
[[1, 3], :on_sp, " "],
|
462
|
+
[[1, 4], :on_ident, "thing"],
|
463
|
+
[[1, 9], :on_sp, " "],
|
464
|
+
[[1, 10], :on_ident, "one"],
|
465
|
+
[[1, 13], :on_comment, "# comment\n"]
|
466
|
+
]
|
467
|
+
end
|
468
|
+
|
469
|
+
let(:file_text) do
|
470
|
+
"def thing one# comment\n \nend\n"
|
471
|
+
end
|
472
|
+
|
473
|
+
it "replaces the comment with an :on_nl" do
|
474
|
+
subject.remove_trailing_comment(file_text).should == [
|
475
|
+
[[1, 0], :on_kw, "def"],
|
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_nl, "\n"]
|
481
|
+
]
|
482
|
+
end
|
483
|
+
|
484
|
+
it "returns a LexedLine" do
|
485
|
+
subject.remove_trailing_comment(file_text).should be_a Tailor::LexedLine
|
486
|
+
end
|
487
|
+
end
|
488
|
+
end
|
489
|
+
end
|
490
|
+
|
491
|
+
describe "#end_of_multi-line_string?" do
|
492
|
+
context "lexed output is from the end of a multi-line % statement" do
|
493
|
+
let(:lexed_output) do
|
494
|
+
[[[1, 11], :on_tstring_end, "}"], [[1, 12], :on_nl, "\n"]]
|
495
|
+
end
|
496
|
+
|
497
|
+
it "returns true" do
|
498
|
+
subject.end_of_multi_line_string?.should be_true
|
499
|
+
end
|
500
|
+
end
|
501
|
+
|
502
|
+
context "lexed output is not from the end of a multi-line % statement" do
|
503
|
+
let(:lexed_output) do
|
504
|
+
[[[1, 11], :on_comma, ","], [[1, 12], :on_nl, "\n"]]
|
505
|
+
end
|
506
|
+
|
507
|
+
it "returns true" do
|
508
|
+
subject.end_of_multi_line_string?.should be_false
|
509
|
+
end
|
510
|
+
end
|
511
|
+
|
512
|
+
context "lexed output contains start AND end of a multi-line % statement" do
|
513
|
+
let(:lexed_output) do
|
514
|
+
[
|
515
|
+
[[1, 0], :on_tstring_beg, "%Q{"],
|
516
|
+
[[1, 3], :on_tstring_content, "this is a t string! suckaaaaaa!"],
|
517
|
+
[[1, 32], :on_tstring_end, "}"]
|
518
|
+
]
|
519
|
+
end
|
520
|
+
|
521
|
+
it "returns true" do
|
522
|
+
subject.end_of_multi_line_string?.should be_false
|
523
|
+
end
|
524
|
+
end
|
525
|
+
end
|
526
|
+
|
527
|
+
describe "#is_line_only_a" do
|
528
|
+
let(:lexed_output) do
|
529
|
+
[[[1, 11], :on_comma, ","], [[1, 12], :on_nl, "\n"]]
|
530
|
+
end
|
531
|
+
|
532
|
+
context "last event is not the event passed in" do
|
533
|
+
let(:last_event) do
|
534
|
+
[[[1, 11], :on_comma, ","]]
|
535
|
+
end
|
536
|
+
|
537
|
+
before do
|
538
|
+
subject.stub(:last_non_line_feed_event).and_return last_event
|
539
|
+
end
|
540
|
+
|
541
|
+
specify { subject.is_line_only_a(:on_period).should be_false }
|
542
|
+
end
|
543
|
+
|
544
|
+
context "last event is the last event passed in" do
|
545
|
+
context "there is only space before the last event" do
|
546
|
+
let(:lexed_output) do
|
547
|
+
[
|
548
|
+
[[1, 0], :on_sp, ' '],
|
549
|
+
[[1, 11], :on_comma, ","],
|
550
|
+
[[1, 12], :on_nl, "\n"]]
|
551
|
+
end
|
552
|
+
|
553
|
+
specify { subject.is_line_only_a(:on_comma).should be_true }
|
554
|
+
end
|
555
|
+
|
556
|
+
context "there is non-spaces before the last event" do
|
557
|
+
let(:lexed_output) do
|
558
|
+
[
|
559
|
+
[[1, 0], :on_sp, " "],
|
560
|
+
[[1, 8], :on_ident, "one"],
|
561
|
+
[[1, 11], :on_comma, ","],
|
562
|
+
[[1, 12], :on_nl, "\n"]]
|
563
|
+
end
|
564
|
+
|
565
|
+
specify { subject.is_line_only_a(:on_comma).should be_false }
|
566
|
+
end
|
567
|
+
end
|
568
|
+
end
|
569
|
+
end
|