tailor 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +30 -28
- data/History.md +257 -0
- data/README.md +486 -0
- data/Rakefile +1 -9
- data/lib/ext/string_ext.rb +1 -1
- data/lib/tailor/cli.rb +3 -1
- data/lib/tailor/cli/options.rb +59 -39
- data/lib/tailor/configuration.rb +8 -5
- data/lib/tailor/configuration/file_set.rb +1 -3
- data/lib/tailor/configuration/style.rb +2 -0
- data/lib/tailor/critic.rb +2 -2
- data/lib/tailor/formatters/text.rb +17 -16
- data/lib/tailor/lexed_line.rb +2 -4
- data/lib/tailor/lexer.rb +9 -9
- data/lib/tailor/lexer/lexer_constants.rb +32 -32
- data/lib/tailor/lexer/token.rb +8 -10
- data/lib/tailor/logger.rb +1 -1
- data/lib/tailor/problem.rb +4 -1
- data/lib/tailor/rake_task.rb +4 -1
- data/lib/tailor/reporter.rb +3 -3
- data/lib/tailor/ruler.rb +2 -2
- data/lib/tailor/rulers/allow_camel_case_methods_ruler.rb +2 -2
- data/lib/tailor/rulers/allow_hard_tabs_ruler.rb +1 -1
- data/lib/tailor/rulers/allow_invalid_ruby_ruler.rb +1 -1
- data/lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb +2 -2
- data/lib/tailor/rulers/indentation_spaces_ruler.rb +24 -22
- data/lib/tailor/rulers/indentation_spaces_ruler/indentation_manager.rb +13 -13
- data/lib/tailor/rulers/max_code_lines_in_class_ruler.rb +2 -2
- data/lib/tailor/rulers/max_code_lines_in_method_ruler.rb +2 -2
- data/lib/tailor/rulers/spaces_after_comma_ruler.rb +6 -6
- data/lib/tailor/rulers/spaces_after_conditional_ruler.rb +48 -0
- data/lib/tailor/rulers/spaces_after_lbrace_ruler.rb +8 -8
- data/lib/tailor/rulers/spaces_after_lbracket_ruler.rb +6 -6
- data/lib/tailor/rulers/spaces_after_lparen_ruler.rb +6 -6
- data/lib/tailor/rulers/spaces_before_comma_ruler.rb +2 -2
- data/lib/tailor/rulers/spaces_before_lbrace_ruler.rb +4 -4
- data/lib/tailor/rulers/spaces_before_rbrace_ruler.rb +9 -9
- data/lib/tailor/rulers/spaces_before_rbracket_ruler.rb +6 -6
- data/lib/tailor/rulers/spaces_before_rparen_ruler.rb +6 -6
- data/lib/tailor/rulers/spaces_in_empty_braces_ruler.rb +1 -1
- data/lib/tailor/rulers/trailing_newlines_ruler.rb +2 -2
- data/lib/tailor/tailorrc.erb +1 -1
- data/lib/tailor/version.rb +1 -1
- data/spec/functional/conditional_spacing_spec.rb +149 -0
- data/spec/functional/configuration_spec.rb +36 -26
- data/spec/functional/horizontal_spacing/braces_spec.rb +1 -1
- data/spec/functional/horizontal_spacing/brackets_spec.rb +14 -14
- data/spec/functional/horizontal_spacing/comma_spacing_spec.rb +8 -8
- data/spec/functional/horizontal_spacing/hard_tabs_spec.rb +13 -13
- data/spec/functional/horizontal_spacing/long_lines_spec.rb +6 -6
- data/spec/functional/horizontal_spacing/long_methods_spec.rb +55 -0
- data/spec/functional/horizontal_spacing/parens_spec.rb +17 -17
- data/spec/functional/horizontal_spacing/trailing_whitespace_spec.rb +8 -8
- data/spec/functional/horizontal_spacing_spec.rb +11 -11
- data/spec/functional/indentation_spacing/bad_indentation_spec.rb +83 -83
- data/spec/functional/indentation_spacing_spec.rb +10 -10
- data/spec/functional/naming/camel_case_methods_spec.rb +6 -6
- data/spec/functional/naming/screaming_snake_case_classes_spec.rb +10 -10
- data/spec/functional/naming_spec.rb +3 -3
- data/spec/functional/vertical_spacing/class_length_spec.rb +6 -6
- data/spec/functional/vertical_spacing/method_length_spec.rb +6 -6
- data/spec/functional/vertical_spacing_spec.rb +3 -3
- data/spec/support/conditional_spacing_cases.rb +37 -0
- data/spec/support/good_indentation_cases.rb +1 -1
- data/spec/unit/tailor/cli/options_spec.rb +50 -0
- data/spec/unit/tailor/cli_spec.rb +3 -3
- data/spec/unit/tailor/composite_observable_spec.rb +8 -8
- data/spec/unit/tailor/configuration/file_set_spec.rb +2 -2
- data/spec/unit/tailor/configuration/style_spec.rb +30 -29
- data/spec/unit/tailor/configuration_spec.rb +39 -24
- data/spec/unit/tailor/critic_spec.rb +18 -17
- data/spec/unit/tailor/formatter_spec.rb +15 -15
- data/spec/unit/tailor/formatters/yaml_spec.rb +1 -1
- data/spec/unit/tailor/lexed_line_spec.rb +258 -258
- data/spec/unit/tailor/lexer/token_spec.rb +11 -11
- data/spec/unit/tailor/lexer_spec.rb +35 -35
- data/spec/unit/tailor/problem_spec.rb +13 -13
- data/spec/unit/tailor/reporter_spec.rb +19 -18
- data/spec/unit/tailor/ruler_spec.rb +15 -15
- data/spec/unit/tailor/rulers/indentation_spaces_ruler/indentation_manager_spec.rb +72 -72
- data/spec/unit/tailor/rulers/indentation_spaces_ruler_spec.rb +32 -32
- data/spec/unit/tailor/rulers/spaces_after_comma_ruler_spec.rb +8 -8
- data/spec/unit/tailor/rulers/spaces_after_lbrace_ruler_spec.rb +36 -36
- data/spec/unit/tailor/rulers/spaces_before_lbrace_ruler_spec.rb +14 -14
- data/spec/unit/tailor/rulers/spaces_before_rbrace_ruler_spec.rb +14 -14
- data/spec/unit/tailor/rulers_spec.rb +2 -2
- data/spec/unit/tailor/version_spec.rb +1 -1
- data/spec/unit/tailor_spec.rb +4 -4
- data/tailor.gemspec +1 -1
- metadata +16 -9
- data/History.rdoc +0 -189
- data/README.rdoc +0 -422
- data/spec/unit/tailor/options_spec.rb +0 -6
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'tailor/configuration'
|
3
3
|
require 'tailor/cli'
|
4
4
|
|
@@ -9,28 +9,28 @@ describe Tailor::Configuration do
|
|
9
9
|
Tailor::Configuration.new('.')
|
10
10
|
end
|
11
11
|
|
12
|
-
describe
|
13
|
-
context
|
14
|
-
it
|
12
|
+
describe '#formatters' do
|
13
|
+
context 'param is nil' do
|
14
|
+
it 'returns the pre-exisiting @formatters' do
|
15
15
|
subject.instance_variable_set(:@formatters, [:blah])
|
16
16
|
subject.formatters.should == [:blah]
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
context
|
21
|
-
it
|
22
|
-
subject.formatters
|
23
|
-
subject.instance_variable_get(:@formatters).should == [
|
20
|
+
context 'param is some value' do
|
21
|
+
it 'sets @formatters to that value' do
|
22
|
+
subject.formatters 'blah'
|
23
|
+
subject.instance_variable_get(:@formatters).should == ['blah']
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
describe
|
28
|
+
describe '#file_set' do
|
29
29
|
before do
|
30
30
|
subject.instance_variable_set(:@file_sets, {})
|
31
31
|
end
|
32
32
|
|
33
|
-
it
|
33
|
+
it 'adds the set of stuff to @file_sets' do
|
34
34
|
subject.file_set('some_files', :bobo) do |style|
|
35
35
|
style.trailing_newlines 2
|
36
36
|
end
|
@@ -49,6 +49,7 @@ describe Tailor::Configuration do
|
|
49
49
|
max_code_lines_in_method: [30, { level: :error }],
|
50
50
|
max_line_length: [80, { level: :error }],
|
51
51
|
spaces_after_comma: [1, { level: :error }],
|
52
|
+
spaces_after_conditional: [1, { :level=>:error }],
|
52
53
|
spaces_after_lbrace: [1, { level: :error }],
|
53
54
|
spaces_after_lbracket: [0, { level: :error }],
|
54
55
|
spaces_after_lparen: [0, { level: :error }],
|
@@ -64,25 +65,25 @@ describe Tailor::Configuration do
|
|
64
65
|
}
|
65
66
|
end
|
66
67
|
|
67
|
-
context
|
68
|
-
it
|
68
|
+
context 'first param is nil' do
|
69
|
+
it 'uses :default as the label' do
|
69
70
|
subject.file_set
|
70
71
|
subject.instance_variable_get(:@file_sets).should include(:default)
|
71
72
|
end
|
72
73
|
end
|
73
74
|
end
|
74
75
|
|
75
|
-
describe
|
76
|
-
context
|
77
|
-
it
|
76
|
+
describe '#confg_file' do
|
77
|
+
context '@config_file is already set' do
|
78
|
+
it 'returns @config_file' do
|
78
79
|
subject.instance_variable_set(:@config_file, 'pants')
|
79
80
|
subject.config_file
|
80
81
|
subject.instance_variable_get(:@config_file).should == 'pants'
|
81
82
|
end
|
82
83
|
end
|
83
84
|
|
84
|
-
context
|
85
|
-
context
|
85
|
+
context '@config_file is nil' do
|
86
|
+
context 'DEFAULT_PROJECT_CONFIG exists' do
|
86
87
|
before do
|
87
88
|
File.should_receive(:exists?).with(/\.tailor/).and_return true
|
88
89
|
end
|
@@ -92,13 +93,13 @@ describe Tailor::Configuration do
|
|
92
93
|
end
|
93
94
|
end
|
94
95
|
|
95
|
-
context
|
96
|
+
context 'DEFAULT_PROJECT_CONFIG does not exist' do
|
96
97
|
before do
|
97
98
|
File.should_receive(:exists?).with(/\.tailor/).and_return false
|
98
99
|
File.should_receive(:exists?).with(/\.tailorrc/).and_return true
|
99
100
|
end
|
100
101
|
|
101
|
-
it
|
102
|
+
it 'returns DEFAULT_RC_FILE' do
|
102
103
|
subject.config_file
|
103
104
|
subject.instance_variable_get(:@config_file).should ==
|
104
105
|
Tailor::Configuration::DEFAULT_RC_FILE
|
@@ -107,8 +108,22 @@ describe Tailor::Configuration do
|
|
107
108
|
end
|
108
109
|
end
|
109
110
|
|
110
|
-
describe
|
111
|
-
|
111
|
+
describe '#recursive_file_set' do
|
112
|
+
before do
|
113
|
+
subject.instance_variable_set(:@file_sets, {})
|
114
|
+
end
|
115
|
+
it 'yields if a block is provided' do
|
116
|
+
expect do |config|
|
117
|
+
subject.recursive_file_set('*.rb', &config)
|
118
|
+
end.to yield_control
|
119
|
+
end
|
120
|
+
it 'does not raise if a block is not provided' do
|
121
|
+
expect { subject.recursive_file_set('*.rb') }.not_to raise_error
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe 'output file' do
|
126
|
+
context 'defined' do
|
112
127
|
subject do
|
113
128
|
parser = Tailor::CLI::Options
|
114
129
|
args = %w(--output-file=tailor-result.yaml)
|
@@ -116,11 +131,11 @@ describe Tailor::Configuration do
|
|
116
131
|
end
|
117
132
|
|
118
133
|
before { subject.load! }
|
119
|
-
its(:output_file) { should eq
|
134
|
+
its(:output_file) { should eq 'tailor-result.yaml' }
|
120
135
|
end
|
121
136
|
|
122
|
-
context
|
123
|
-
its(:output_file) { should eq
|
137
|
+
context 'not defined' do
|
138
|
+
its(:output_file) { should eq '' }
|
124
139
|
end
|
125
140
|
end
|
126
141
|
end
|
@@ -1,20 +1,21 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'tailor/critic'
|
3
3
|
|
4
|
+
|
4
5
|
describe Tailor::Critic do
|
5
6
|
before { Tailor::Logger.stub(:log) }
|
6
7
|
|
7
|
-
describe
|
8
|
-
let(:lexer) { double
|
9
|
-
let(:ruler) { double
|
10
|
-
let(:style) { double
|
11
|
-
let(:file_name) {
|
8
|
+
describe '#check_file' do
|
9
|
+
let(:lexer) { double 'Lexer' }
|
10
|
+
let(:ruler) { double 'Ruler' }
|
11
|
+
let(:style) { double 'Style', each: nil }
|
12
|
+
let(:file_name) { 'this_file.rb' }
|
12
13
|
|
13
14
|
before do
|
14
15
|
subject.stub(:init_rulers)
|
15
16
|
end
|
16
17
|
|
17
|
-
it
|
18
|
+
it 'lexes the file' do
|
18
19
|
lexer.should_receive(:lex)
|
19
20
|
lexer.stub(:check_added_newline)
|
20
21
|
Tailor::Lexer.should_receive(:new).with(file_name).and_return lexer
|
@@ -24,7 +25,7 @@ describe Tailor::Critic do
|
|
24
25
|
subject.check_file(file_name, style)
|
25
26
|
end
|
26
27
|
|
27
|
-
it
|
28
|
+
it 'adds problems for the file to the main list of problems' do
|
28
29
|
lexer.stub(:lex)
|
29
30
|
lexer.stub(:check_added_newline)
|
30
31
|
Tailor::Lexer.stub(:new).and_return lexer
|
@@ -34,25 +35,25 @@ describe Tailor::Critic do
|
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
37
|
-
describe
|
38
|
+
describe '#problems' do
|
38
39
|
specify { subject.problems.should be_a Hash }
|
39
40
|
specify { subject.problems.should be_empty }
|
40
41
|
end
|
41
42
|
|
42
|
-
describe
|
43
|
-
context
|
44
|
-
it
|
43
|
+
describe '#problem_count' do
|
44
|
+
context '#problems is empty' do
|
45
|
+
it 'returns 0' do
|
45
46
|
subject.instance_variable_set(:@problems, {})
|
46
47
|
subject.problem_count.should == 0
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
50
|
-
context
|
51
|
-
it
|
51
|
+
context '#problems contains valid values' do
|
52
|
+
it 'adds the number of each problem together' do
|
52
53
|
probs = {
|
53
|
-
one: { type: :indentation, line: 1, message:
|
54
|
-
two: { type: :indentation, line: 2, message:
|
55
|
-
thre: { type: :indentation, line: 27, message:
|
54
|
+
one: { type: :indentation, line: 1, message: '' },
|
55
|
+
two: { type: :indentation, line: 2, message: '' },
|
56
|
+
thre: { type: :indentation, line: 27, message: '' }
|
56
57
|
}
|
57
58
|
subject.instance_variable_set(:@problems, probs)
|
58
59
|
subject.problem_count.should == 3
|
@@ -1,16 +1,16 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'tailor/formatter'
|
3
3
|
|
4
4
|
describe Tailor::Formatter do
|
5
|
-
describe
|
5
|
+
describe '#problems_at_level' do
|
6
6
|
let(:problems) do
|
7
|
-
msg =
|
8
|
-
msg <<
|
7
|
+
msg = 'File contains invalid Ruby; '
|
8
|
+
msg << 'run `ruby -c [your_file.rb]` for more details.'
|
9
9
|
|
10
10
|
{
|
11
|
-
|
11
|
+
'some_file.rb' => [
|
12
12
|
{
|
13
|
-
:type =>
|
13
|
+
:type => 'allow_invalid_ruby',
|
14
14
|
:line => 0,
|
15
15
|
:column => 0,
|
16
16
|
:message => msg,
|
@@ -20,20 +20,20 @@ describe Tailor::Formatter do
|
|
20
20
|
}
|
21
21
|
end
|
22
22
|
|
23
|
-
context
|
24
|
-
it
|
23
|
+
context 'problems are empty' do
|
24
|
+
it 'returns an empty Array' do
|
25
25
|
subject.problems_at_level({}, :error).should == []
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
context
|
30
|
-
it
|
31
|
-
msg =
|
32
|
-
msg <<
|
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
33
|
|
34
34
|
subject.problems_at_level(problems, :warn).should == [
|
35
35
|
{
|
36
|
-
:type =>
|
36
|
+
:type => 'allow_invalid_ruby',
|
37
37
|
:line => 0,
|
38
38
|
:column => 0,
|
39
39
|
:message => msg,
|
@@ -43,8 +43,8 @@ describe Tailor::Formatter do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
context
|
47
|
-
it
|
46
|
+
context 'the level asked for does not exist in the problems' do
|
47
|
+
it 'returns an empty Array' do
|
48
48
|
subject.problems_at_level(problems, :error).should == []
|
49
49
|
end
|
50
50
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'tailor/lexed_line'
|
3
3
|
|
4
4
|
describe Tailor::LexedLine do
|
@@ -8,43 +8,43 @@ describe Tailor::LexedLine do
|
|
8
8
|
|
9
9
|
subject { Tailor::LexedLine.new(lexed_output, 1) }
|
10
10
|
|
11
|
-
describe
|
11
|
+
describe '#initialize' do
|
12
12
|
let(:lexed_output) do
|
13
13
|
[
|
14
|
-
[[1, 0], :on_ident,
|
15
|
-
[[1, 7], :on_sp,
|
14
|
+
[[1, 0], :on_ident, 'require'],
|
15
|
+
[[1, 7], :on_sp, ' '],
|
16
16
|
[[1, 8], :on_tstring_beg, "'"],
|
17
|
-
[[1, 9], :on_tstring_content,
|
17
|
+
[[1, 9], :on_tstring_content, 'log_switch'],
|
18
18
|
[[1, 19], :on_tstring_end, "'"],
|
19
19
|
[[1, 20], :on_nl, "\n"],
|
20
|
-
[[2, 0], :on_ident,
|
21
|
-
[[2, 16], :on_sp,
|
20
|
+
[[2, 0], :on_ident, 'require_relative'],
|
21
|
+
[[2, 16], :on_sp, ' '],
|
22
22
|
[[2, 17], :on_tstring_beg, "'"],
|
23
|
-
[[2, 18], :on_tstring_content,
|
23
|
+
[[2, 18], :on_tstring_content, 'tailor/runtime_error'],
|
24
24
|
[[2, 38], :on_tstring_end, "'"],
|
25
25
|
[[2, 39], :on_nl, "\n"]
|
26
26
|
]
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it 'returns all lexed output from line 1 when self.lineno is 1' do
|
30
30
|
line = Tailor::LexedLine.new(lexed_output, 1)
|
31
31
|
|
32
32
|
line.should == [
|
33
|
-
[[1, 0], :on_ident,
|
34
|
-
[[1, 7], :on_sp,
|
33
|
+
[[1, 0], :on_ident, 'require'],
|
34
|
+
[[1, 7], :on_sp, ' '],
|
35
35
|
[[1, 8], :on_tstring_beg, "'"],
|
36
|
-
[[1, 9], :on_tstring_content,
|
36
|
+
[[1, 9], :on_tstring_content, 'log_switch'],
|
37
37
|
[[1, 19], :on_tstring_end, "'"],
|
38
38
|
[[1, 20], :on_nl, "\n"]
|
39
39
|
]
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
describe
|
43
|
+
describe '#only_spaces?' do
|
44
44
|
context '0 length line, no \n ending' do
|
45
|
-
let(:lexed_output) { [[[1, 0], :on_sp,
|
45
|
+
let(:lexed_output) { [[[1, 0], :on_sp, ' ']] }
|
46
46
|
|
47
|
-
it
|
47
|
+
it 'should return true' do
|
48
48
|
subject.only_spaces?.should be_true
|
49
49
|
end
|
50
50
|
end
|
@@ -52,15 +52,15 @@ describe Tailor::LexedLine do
|
|
52
52
|
context '0 length line, with \n ending' do
|
53
53
|
let(:lexed_output) { [[[1, 0], :on_nl, "\n"]] }
|
54
54
|
|
55
|
-
it
|
55
|
+
it 'should return true' do
|
56
56
|
subject.only_spaces?.should be_true
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
context 'comment line, starting at column 0' do
|
61
|
-
let(:lexed_output) { [[[1, 0], :on_comment,
|
61
|
+
let(:lexed_output) { [[[1, 0], :on_comment, '# comment']] }
|
62
62
|
|
63
|
-
it
|
63
|
+
it 'should return false' do
|
64
64
|
subject.only_spaces?.should be_false
|
65
65
|
end
|
66
66
|
end
|
@@ -68,12 +68,12 @@ describe Tailor::LexedLine do
|
|
68
68
|
context 'comment line, starting at column 2' do
|
69
69
|
let(:lexed_output) do
|
70
70
|
[
|
71
|
-
[[1, 0], :on_sp,
|
72
|
-
[[1, 2], :on_comment,
|
71
|
+
[[1, 0], :on_sp, ' '],
|
72
|
+
[[1, 2], :on_comment, '# comment']
|
73
73
|
]
|
74
74
|
end
|
75
75
|
|
76
|
-
it
|
76
|
+
it 'should return false' do
|
77
77
|
subject.only_spaces?.should be_false
|
78
78
|
end
|
79
79
|
end
|
@@ -81,97 +81,97 @@ describe Tailor::LexedLine do
|
|
81
81
|
context 'code line, starting at column 2' do
|
82
82
|
let(:lexed_output) do
|
83
83
|
[
|
84
|
-
[[1, 0], :on_ident,
|
85
|
-
[[1, 4], :on_sp,
|
84
|
+
[[1, 0], :on_ident, 'puts'],
|
85
|
+
[[1, 4], :on_sp, ' '],
|
86
86
|
[[1, 5], :on_tstring_beg, "'"],
|
87
|
-
[[1, 6], :on_tstring_content,
|
87
|
+
[[1, 6], :on_tstring_content, 'thing'],
|
88
88
|
[[1, 11], :on_tstring_end, "'"],
|
89
89
|
[[1, 12], :on_nl, "\n"]
|
90
90
|
]
|
91
91
|
end
|
92
92
|
|
93
|
-
it
|
93
|
+
it 'should return false' do
|
94
94
|
subject.only_spaces?.should be_false
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
describe
|
100
|
-
context
|
99
|
+
describe '#ends_with_op?' do
|
100
|
+
context 'line ends with a +, then \\n' do
|
101
101
|
let(:lexed_output) do
|
102
102
|
[
|
103
|
-
[[1, 0], :on_ident,
|
104
|
-
[[1, 5], :on_sp,
|
105
|
-
[[1, 6], :on_op,
|
106
|
-
[[1, 7], :on_sp,
|
107
|
-
[[1, 8], :on_int,
|
108
|
-
[[1, 9], :on_sp,
|
109
|
-
[[1, 10], :on_op,
|
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
110
|
[[1, 11], :on_ignored_nl, "\n"],
|
111
111
|
[[1, 11], :on_ignored_nl, "\n"]
|
112
112
|
]
|
113
113
|
end
|
114
114
|
|
115
|
-
it
|
115
|
+
it 'returns true' do
|
116
116
|
subject.ends_with_op?.should be_true
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
context
|
120
|
+
context 'line ends with not an operator, then \\n' do
|
121
121
|
let(:lexed_output) do
|
122
122
|
[
|
123
|
-
[[1, 0], :on_ident,
|
124
|
-
[[1, 5], :on_sp,
|
125
|
-
[[1, 6], :on_op,
|
126
|
-
[[1, 7], :on_sp,
|
127
|
-
[[1, 8], :on_int,
|
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
128
|
[[1, 11], :on_nl, "\n"]
|
129
129
|
]
|
130
130
|
end
|
131
131
|
|
132
|
-
it
|
132
|
+
it 'returns false' do
|
133
133
|
subject.ends_with_op?.should be_false
|
134
134
|
end
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
138
|
-
describe
|
139
|
-
context
|
138
|
+
describe '#ends_with_modifier_kw?' do
|
139
|
+
context 'ends_with_kw? is false' do
|
140
140
|
let(:lexed_output) do
|
141
141
|
[
|
142
|
-
[[1, 0], :on_ident,
|
143
|
-
[[1, 5], :on_sp,
|
144
|
-
[[1, 6], :on_op,
|
145
|
-
[[1, 7], :on_sp,
|
146
|
-
[[1, 8], :on_int,
|
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
147
|
[[1, 9], :on_ignored_nl, "\n"]
|
148
148
|
]
|
149
149
|
end
|
150
150
|
|
151
151
|
before { subject.stub(:ends_with_kw?).and_return true }
|
152
152
|
|
153
|
-
it
|
153
|
+
it 'returns false' do
|
154
154
|
subject.ends_with_modifier_kw?.should be_false
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
|
-
context
|
158
|
+
context '#ends_with_kw? is true' do
|
159
159
|
let(:lexed_output) do
|
160
160
|
[
|
161
|
-
[[1, 0], :on_ident,
|
162
|
-
[[1, 5], :on_sp,
|
163
|
-
[[1, 6], :on_op,
|
164
|
-
[[1, 7], :on_sp,
|
165
|
-
[[1, 8], :on_int,
|
166
|
-
[[1, 9], :on_sp,
|
167
|
-
[[1, 10], :on_kw,
|
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
168
|
[[1, 12], :on_ignored_nl, "\n"]
|
169
169
|
]
|
170
170
|
end
|
171
171
|
|
172
|
-
let(:token) { double
|
172
|
+
let(:token) { double 'Token' }
|
173
173
|
|
174
|
-
context
|
174
|
+
context 'the keyword is a modifier' do
|
175
175
|
before do
|
176
176
|
token.stub(:modifier_keyword?).and_return true
|
177
177
|
Tailor::Lexer::Token.stub(:new).and_return token
|
@@ -180,12 +180,12 @@ describe Tailor::LexedLine do
|
|
180
180
|
|
181
181
|
after { Tailor::Lexer::Token.unstub(:new) }
|
182
182
|
|
183
|
-
it
|
183
|
+
it 'returns true' do
|
184
184
|
subject.ends_with_modifier_kw?.should be_true
|
185
185
|
end
|
186
186
|
end
|
187
187
|
|
188
|
-
context
|
188
|
+
context 'the keyword is not a modifier' do
|
189
189
|
before do
|
190
190
|
token.stub(:modifier_keyword?).and_return false
|
191
191
|
Tailor::Lexer::Token.stub(:new).and_return token
|
@@ -194,84 +194,84 @@ describe Tailor::LexedLine do
|
|
194
194
|
|
195
195
|
after { Tailor::Lexer::Token.unstub(:new) }
|
196
196
|
|
197
|
-
it
|
197
|
+
it 'returns true' do
|
198
198
|
subject.ends_with_modifier_kw?.should be_false
|
199
199
|
end
|
200
200
|
end
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
204
|
-
describe
|
204
|
+
describe '#does_line_end_with' do
|
205
205
|
let(:lexed_output) do
|
206
206
|
[
|
207
|
-
[[1, 0], :on_kw,
|
208
|
-
[[1, 3], :on_sp,
|
209
|
-
[[1, 4], :on_ident,
|
210
|
-
[[1, 9], :on_sp,
|
207
|
+
[[1, 0], :on_kw, 'def'],
|
208
|
+
[[1, 3], :on_sp, ' '],
|
209
|
+
[[1, 4], :on_ident, 'thing'],
|
210
|
+
[[1, 9], :on_sp, ' '],
|
211
211
|
[[1, 10], :on_nl, "\n"]
|
212
212
|
]
|
213
213
|
end
|
214
214
|
|
215
|
-
context
|
216
|
-
it
|
215
|
+
context 'line ends with the event' do
|
216
|
+
it 'returns true' do
|
217
217
|
subject.does_line_end_with(:on_sp).should be_true
|
218
218
|
end
|
219
219
|
end
|
220
220
|
|
221
|
-
context
|
222
|
-
it
|
221
|
+
context 'line does not even with event' do
|
222
|
+
it 'returns false' do
|
223
223
|
subject.does_line_end_with(:on_kw).should be_false
|
224
224
|
end
|
225
225
|
end
|
226
226
|
end
|
227
227
|
|
228
|
-
describe
|
229
|
-
context
|
228
|
+
describe '#last_non_line_feed_event' do
|
229
|
+
context 'line ends with a space' do
|
230
230
|
let(:lexed_output) do
|
231
231
|
[
|
232
|
-
[[1, 0], :on_kw,
|
233
|
-
[[1, 3], :on_sp,
|
234
|
-
[[1, 4], :on_ident,
|
235
|
-
[[1, 9], :on_sp,
|
232
|
+
[[1, 0], :on_kw, 'def'],
|
233
|
+
[[1, 3], :on_sp, ' '],
|
234
|
+
[[1, 4], :on_ident, 'thing'],
|
235
|
+
[[1, 9], :on_sp, ' '],
|
236
236
|
[[1, 10], :on_nl, "\n"]
|
237
237
|
]
|
238
238
|
end
|
239
239
|
|
240
|
-
it
|
241
|
-
subject.last_non_line_feed_event.should == [[1, 9], :on_sp,
|
240
|
+
it 'returns the space' do
|
241
|
+
subject.last_non_line_feed_event.should == [[1, 9], :on_sp, ' ']
|
242
242
|
end
|
243
243
|
end
|
244
244
|
|
245
|
-
context
|
245
|
+
context 'line ends with a backslash' do
|
246
246
|
let(:lexed_output) do
|
247
247
|
[
|
248
|
-
[[1, 0], :on_kw,
|
249
|
-
[[1, 3], :on_sp,
|
250
|
-
[[1, 4], :on_ident,
|
248
|
+
[[1, 0], :on_kw, 'def'],
|
249
|
+
[[1, 3], :on_sp, ' '],
|
250
|
+
[[1, 4], :on_ident, 'thing'],
|
251
251
|
[[1, 9], :on_sp, "\\\n"]
|
252
252
|
]
|
253
253
|
end
|
254
254
|
|
255
|
-
it
|
256
|
-
subject.last_non_line_feed_event.should == [[1, 4], :on_ident,
|
255
|
+
it 'returns the event before it' do
|
256
|
+
subject.last_non_line_feed_event.should == [[1, 4], :on_ident, 'thing']
|
257
257
|
end
|
258
258
|
end
|
259
259
|
end
|
260
260
|
|
261
|
-
describe
|
261
|
+
describe '#loop_with_do?' do
|
262
262
|
context "line is 'while true do\\n'" do
|
263
263
|
let(:lexed_output) do
|
264
264
|
[
|
265
|
-
[[1, 0], :on_kw,
|
266
|
-
[[1, 5], :on_sp,
|
267
|
-
[[1, 6], :on_kw,
|
268
|
-
[[1, 10], :on_sp,
|
269
|
-
[[1, 11], :on_kw,
|
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
270
|
[[1, 13], :on_ignored_nl, "\n"]
|
271
271
|
]
|
272
272
|
end
|
273
273
|
|
274
|
-
it
|
274
|
+
it 'returns true' do
|
275
275
|
subject.loop_with_do?.should be_true
|
276
276
|
end
|
277
277
|
end
|
@@ -279,15 +279,15 @@ describe Tailor::LexedLine do
|
|
279
279
|
context "line is 'while true\\n'" do
|
280
280
|
let(:lexed_output) do
|
281
281
|
[
|
282
|
-
[[1, 0], :on_kw,
|
283
|
-
[[1, 5], :on_sp,
|
284
|
-
[[1, 6], :on_kw,
|
285
|
-
[[1, 10], :on_sp,
|
282
|
+
[[1, 0], :on_kw, 'while'],
|
283
|
+
[[1, 5], :on_sp, ' '],
|
284
|
+
[[1, 6], :on_kw, 'true'],
|
285
|
+
[[1, 10], :on_sp, ' '],
|
286
286
|
[[1, 11], :on_ignored_nl, "\n"]
|
287
287
|
]
|
288
288
|
end
|
289
289
|
|
290
|
-
it
|
290
|
+
it 'returns false' do
|
291
291
|
subject.loop_with_do?.should be_false
|
292
292
|
end
|
293
293
|
end
|
@@ -295,16 +295,16 @@ describe Tailor::LexedLine do
|
|
295
295
|
context "line is 'until true do\\n'" do
|
296
296
|
let(:lexed_output) do
|
297
297
|
[
|
298
|
-
[[1, 0], :on_kw,
|
299
|
-
[[1, 5], :on_sp,
|
300
|
-
[[1, 6], :on_kw,
|
301
|
-
[[1, 10], :on_sp,
|
302
|
-
[[1, 11], :on_kw,
|
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
303
|
[[1, 13], :on_ignored_nl, "\n"]
|
304
304
|
]
|
305
305
|
end
|
306
306
|
|
307
|
-
it
|
307
|
+
it 'returns true' do
|
308
308
|
subject.loop_with_do?.should be_true
|
309
309
|
end
|
310
310
|
end
|
@@ -312,15 +312,15 @@ describe Tailor::LexedLine do
|
|
312
312
|
context "line is 'until true\\n'" do
|
313
313
|
let(:lexed_output) do
|
314
314
|
[
|
315
|
-
[[1, 0], :on_kw,
|
316
|
-
[[1, 5], :on_sp,
|
317
|
-
[[1, 6], :on_kw,
|
318
|
-
[[1, 10], :on_sp,
|
315
|
+
[[1, 0], :on_kw, 'until'],
|
316
|
+
[[1, 5], :on_sp, ' '],
|
317
|
+
[[1, 6], :on_kw, 'true'],
|
318
|
+
[[1, 10], :on_sp, ' '],
|
319
319
|
[[1, 11], :on_ignored_nl, "\n"]
|
320
320
|
]
|
321
321
|
end
|
322
322
|
|
323
|
-
it
|
323
|
+
it 'returns false' do
|
324
324
|
subject.loop_with_do?.should be_false
|
325
325
|
end
|
326
326
|
end
|
@@ -328,22 +328,22 @@ describe Tailor::LexedLine do
|
|
328
328
|
context "line is 'for i in 1..5 do\\n'" do
|
329
329
|
let(:lexed_output) do
|
330
330
|
[
|
331
|
-
[[1, 0], :on_kw,
|
332
|
-
[[1, 3], :on_sp,
|
333
|
-
[[1, 4], :on_ident,
|
334
|
-
[[1, 5], :on_sp,
|
335
|
-
[[1, 6], :on_kw,
|
336
|
-
[[1, 8], :on_sp,
|
337
|
-
[[1, 9], :on_int,
|
338
|
-
[[1, 10], :on_op,
|
339
|
-
[[1, 12], :on_int,
|
340
|
-
[[1, 13], :on_sp,
|
341
|
-
[[1, 14], :on_kw,
|
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
342
|
[[1, 16], :on_ignored_nl, "\n"]
|
343
343
|
]
|
344
344
|
end
|
345
345
|
|
346
|
-
it
|
346
|
+
it 'returns true' do
|
347
347
|
subject.loop_with_do?.should be_true
|
348
348
|
end
|
349
349
|
end
|
@@ -351,31 +351,31 @@ describe Tailor::LexedLine do
|
|
351
351
|
context "line is 'for i in 1..5\\n'" do
|
352
352
|
let(:lexed_output) do
|
353
353
|
[
|
354
|
-
[[1, 0], :on_kw,
|
355
|
-
[[1, 3], :on_sp,
|
356
|
-
[[1, 4], :on_ident,
|
357
|
-
[[1, 5], :on_sp,
|
358
|
-
[[1, 6], :on_kw,
|
359
|
-
[[1, 8], :on_sp,
|
360
|
-
[[1, 9], :on_int,
|
361
|
-
[[1, 10], :on_op,
|
362
|
-
[[1, 12], :on_int,
|
363
|
-
[[1, 13], :on_sp,
|
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
364
|
[[1, 14], :on_ignored_nl, "\n"]
|
365
365
|
]
|
366
366
|
end
|
367
367
|
|
368
|
-
it
|
368
|
+
it 'returns false' do
|
369
369
|
subject.loop_with_do?.should be_false
|
370
370
|
end
|
371
371
|
end
|
372
372
|
end
|
373
373
|
|
374
|
-
describe
|
375
|
-
context
|
376
|
-
let(:lexed_output) { [[[1, 0], :on_sp,
|
374
|
+
describe '#first_non_space_element' do
|
375
|
+
context 'lexed line contains only spaces' do
|
376
|
+
let(:lexed_output) { [[[1, 0], :on_sp, ' ']] }
|
377
377
|
|
378
|
-
it
|
378
|
+
it 'returns nil' do
|
379
379
|
subject.first_non_space_element.should be_nil
|
380
380
|
end
|
381
381
|
end
|
@@ -383,7 +383,7 @@ describe Tailor::LexedLine do
|
|
383
383
|
context "lexed line contains only \\n" do
|
384
384
|
let(:lexed_output) { [[[1, 0], :on_ignored_nl, "\n"]] }
|
385
385
|
|
386
|
-
it
|
386
|
+
it 'returns nil' do
|
387
387
|
subject.first_non_space_element.should be_nil
|
388
388
|
end
|
389
389
|
end
|
@@ -391,56 +391,56 @@ describe Tailor::LexedLine do
|
|
391
391
|
context "lexed line contains ' }\\n'" do
|
392
392
|
let(:lexed_output) do
|
393
393
|
[
|
394
|
-
[[1, 0], :on_sp,
|
395
|
-
[[1, 2], :on_rbrace,
|
394
|
+
[[1, 0], :on_sp, ' '],
|
395
|
+
[[1, 2], :on_rbrace, '}'],
|
396
396
|
[[1, 3], :on_nl, "\n"]
|
397
397
|
]
|
398
398
|
end
|
399
399
|
|
400
|
-
it
|
401
|
-
subject.first_non_space_element.should == [[1, 2], :on_rbrace,
|
400
|
+
it 'returns nil' do
|
401
|
+
subject.first_non_space_element.should == [[1, 2], :on_rbrace, '}']
|
402
402
|
end
|
403
403
|
end
|
404
404
|
end
|
405
405
|
|
406
|
-
describe
|
407
|
-
let(:lexed_output) { [[[1, 0], :on_sp,
|
406
|
+
describe '#event_at' do
|
407
|
+
let(:lexed_output) { [[[1, 0], :on_sp, ' ']] }
|
408
408
|
|
409
|
-
context
|
410
|
-
it
|
409
|
+
context 'self contains an event at the given column' do
|
410
|
+
it 'returns that event' do
|
411
411
|
subject.event_at(0).should == lexed_output.first
|
412
412
|
end
|
413
413
|
end
|
414
414
|
|
415
|
-
context
|
416
|
-
it
|
415
|
+
context 'self does not contain an event at the given column' do
|
416
|
+
it 'returns nil' do
|
417
417
|
subject.event_at(1234).should be_nil
|
418
418
|
end
|
419
419
|
end
|
420
420
|
end
|
421
421
|
|
422
|
-
describe
|
423
|
-
let(:lexed_output) { [[[1, 0], :on_sp,
|
422
|
+
describe '#event_index' do
|
423
|
+
let(:lexed_output) { [[[1, 0], :on_sp, ' ']] }
|
424
424
|
|
425
|
-
context
|
425
|
+
context '#event_at returns nil' do
|
426
426
|
before { subject.stub(:event_at).and_return nil }
|
427
427
|
specify { subject.event_index(1234).should be_nil }
|
428
428
|
end
|
429
429
|
|
430
|
-
context
|
431
|
-
it
|
430
|
+
context '#event_at returns a valid column' do
|
431
|
+
it 'returns the event' do
|
432
432
|
subject.event_index(0).should be_zero
|
433
433
|
end
|
434
434
|
end
|
435
435
|
end
|
436
436
|
|
437
|
-
describe
|
437
|
+
describe '#to_s' do
|
438
438
|
let(:lexed_output) do
|
439
439
|
[
|
440
|
-
[[1, 0], :on_kw,
|
441
|
-
[[1, 3], :on_sp,
|
442
|
-
[[1, 4], :on_ident,
|
443
|
-
[[1, 9], :on_sp,
|
440
|
+
[[1, 0], :on_kw, 'def'],
|
441
|
+
[[1, 3], :on_sp, ' '],
|
442
|
+
[[1, 4], :on_ident, 'thing'],
|
443
|
+
[[1, 9], :on_sp, ' '],
|
444
444
|
[[1, 10], :on_nl, "\n"]
|
445
445
|
]
|
446
446
|
end
|
@@ -450,18 +450,18 @@ describe Tailor::LexedLine do
|
|
450
450
|
end
|
451
451
|
end
|
452
452
|
|
453
|
-
describe
|
454
|
-
context
|
455
|
-
context
|
453
|
+
describe '#remove_comment_at' do
|
454
|
+
context 'stuff before comment is an incomplete statement' do
|
455
|
+
context 'spaces before comment' do
|
456
456
|
let(:lexed_output) do
|
457
457
|
[
|
458
|
-
[[1, 0], :on_kw,
|
459
|
-
[[1, 3], :on_sp,
|
460
|
-
[[1, 4], :on_ident,
|
461
|
-
[[1, 9], :on_sp,
|
462
|
-
[[1, 10], :on_ident,
|
463
|
-
[[1, 13], :on_comma,
|
464
|
-
[[1, 14], :on_sp,
|
458
|
+
[[1, 0], :on_kw, 'def'],
|
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
465
|
[[1, 16], :on_comment, "# comment\n"]
|
466
466
|
]
|
467
467
|
end
|
@@ -470,28 +470,28 @@ describe Tailor::LexedLine do
|
|
470
470
|
"def thing one, # comment\n two\nend\n"
|
471
471
|
end
|
472
472
|
|
473
|
-
it
|
473
|
+
it 'replaces the comment with an :on_ignored_nl' do
|
474
474
|
subject.remove_trailing_comment(file_text).should == [
|
475
|
-
[[1, 0], :on_kw,
|
476
|
-
[[1, 3], :on_sp,
|
477
|
-
[[1, 4], :on_ident,
|
478
|
-
[[1, 9], :on_sp,
|
479
|
-
[[1, 10], :on_ident,
|
480
|
-
[[1, 13], :on_comma,
|
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_comma, ','],
|
481
481
|
[[1, 14], :on_ignored_nl, "\n"]
|
482
482
|
]
|
483
483
|
end
|
484
484
|
end
|
485
485
|
|
486
|
-
context
|
486
|
+
context 'no spaces before comment' do
|
487
487
|
let(:lexed_output) do
|
488
488
|
[
|
489
|
-
[[1, 0], :on_kw,
|
490
|
-
[[1, 3], :on_sp,
|
491
|
-
[[1, 4], :on_ident,
|
492
|
-
[[1, 9], :on_sp,
|
493
|
-
[[1, 10], :on_ident,
|
494
|
-
[[1, 13], :on_comma,
|
489
|
+
[[1, 0], :on_kw, 'def'],
|
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
495
|
[[1, 14], :on_comment, "# comment\n"]
|
496
496
|
]
|
497
497
|
end
|
@@ -500,30 +500,30 @@ describe Tailor::LexedLine do
|
|
500
500
|
"def thing one,# comment\n two\nend\n"
|
501
501
|
end
|
502
502
|
|
503
|
-
it
|
503
|
+
it 'replaces the comment with an :on_ignored_nl' do
|
504
504
|
subject.remove_trailing_comment(file_text).should == [
|
505
|
-
[[1, 0], :on_kw,
|
506
|
-
[[1, 3], :on_sp,
|
507
|
-
[[1, 4], :on_ident,
|
508
|
-
[[1, 9], :on_sp,
|
509
|
-
[[1, 10], :on_ident,
|
510
|
-
[[1, 13], :on_comma,
|
505
|
+
[[1, 0], :on_kw, 'def'],
|
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
511
|
[[1, 14], :on_ignored_nl, "\n"]
|
512
512
|
]
|
513
513
|
end
|
514
514
|
end
|
515
515
|
end
|
516
516
|
|
517
|
-
context
|
518
|
-
context
|
517
|
+
context 'stuff before comment is a complete statement' do
|
518
|
+
context 'spaces before comment' do
|
519
519
|
let(:lexed_output) do
|
520
520
|
[
|
521
|
-
[[1, 0], :on_kw,
|
522
|
-
[[1, 3], :on_sp,
|
523
|
-
[[1, 4], :on_ident,
|
524
|
-
[[1, 9], :on_sp,
|
525
|
-
[[1, 10], :on_ident,
|
526
|
-
[[1, 13], :on_sp,
|
521
|
+
[[1, 0], :on_kw, 'def'],
|
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
527
|
[[1, 15], :on_comment, "# comment\n"]
|
528
528
|
]
|
529
529
|
end
|
@@ -532,26 +532,26 @@ describe Tailor::LexedLine do
|
|
532
532
|
"def thing one # comment\n\nend\n"
|
533
533
|
end
|
534
534
|
|
535
|
-
it
|
535
|
+
it 'replaces the comment with an :on_nl' do
|
536
536
|
subject.remove_trailing_comment(file_text).should == [
|
537
|
-
[[1, 0], :on_kw,
|
538
|
-
[[1, 3], :on_sp,
|
539
|
-
[[1, 4], :on_ident,
|
540
|
-
[[1, 9], :on_sp,
|
541
|
-
[[1, 10], :on_ident,
|
537
|
+
[[1, 0], :on_kw, 'def'],
|
538
|
+
[[1, 3], :on_sp, ' '],
|
539
|
+
[[1, 4], :on_ident, 'thing'],
|
540
|
+
[[1, 9], :on_sp, ' '],
|
541
|
+
[[1, 10], :on_ident, 'one'],
|
542
542
|
[[1, 13], :on_nl, "\n"]
|
543
543
|
]
|
544
544
|
end
|
545
545
|
end
|
546
546
|
|
547
|
-
context
|
547
|
+
context 'no spaces before comment' do
|
548
548
|
let(:lexed_output) do
|
549
549
|
[
|
550
|
-
[[1, 0], :on_kw,
|
551
|
-
[[1, 3], :on_sp,
|
552
|
-
[[1, 4], :on_ident,
|
553
|
-
[[1, 9], :on_sp,
|
554
|
-
[[1, 10], :on_ident,
|
550
|
+
[[1, 0], :on_kw, 'def'],
|
551
|
+
[[1, 3], :on_sp, ' '],
|
552
|
+
[[1, 4], :on_ident, 'thing'],
|
553
|
+
[[1, 9], :on_sp, ' '],
|
554
|
+
[[1, 10], :on_ident, 'one'],
|
555
555
|
[[1, 13], :on_comment, "# comment\n"]
|
556
556
|
]
|
557
557
|
end
|
@@ -560,18 +560,18 @@ describe Tailor::LexedLine do
|
|
560
560
|
"def thing one# comment\n \nend\n"
|
561
561
|
end
|
562
562
|
|
563
|
-
it
|
563
|
+
it 'replaces the comment with an :on_nl' do
|
564
564
|
subject.remove_trailing_comment(file_text).should == [
|
565
|
-
[[1, 0], :on_kw,
|
566
|
-
[[1, 3], :on_sp,
|
567
|
-
[[1, 4], :on_ident,
|
568
|
-
[[1, 9], :on_sp,
|
569
|
-
[[1, 10], :on_ident,
|
565
|
+
[[1, 0], :on_kw, 'def'],
|
566
|
+
[[1, 3], :on_sp, ' '],
|
567
|
+
[[1, 4], :on_ident, 'thing'],
|
568
|
+
[[1, 9], :on_sp, ' '],
|
569
|
+
[[1, 10], :on_ident, 'one'],
|
570
570
|
[[1, 13], :on_nl, "\n"]
|
571
571
|
]
|
572
572
|
end
|
573
573
|
|
574
|
-
it
|
574
|
+
it 'returns a LexedLine' do
|
575
575
|
subject.remove_trailing_comment(file_text).
|
576
576
|
should be_a Tailor::LexedLine
|
577
577
|
end
|
@@ -579,50 +579,50 @@ describe Tailor::LexedLine do
|
|
579
579
|
end
|
580
580
|
end
|
581
581
|
|
582
|
-
describe
|
583
|
-
context
|
582
|
+
describe '#end_of_multi-line_string?' do
|
583
|
+
context 'lexed output is from the end of a multi-line % statement' do
|
584
584
|
let(:lexed_output) do
|
585
|
-
[[[1, 11], :on_tstring_end,
|
585
|
+
[[[1, 11], :on_tstring_end, '}'], [[1, 12], :on_nl, "\n"]]
|
586
586
|
end
|
587
587
|
|
588
|
-
it
|
588
|
+
it 'returns true' do
|
589
589
|
subject.end_of_multi_line_string?.should be_true
|
590
590
|
end
|
591
591
|
end
|
592
592
|
|
593
|
-
context
|
593
|
+
context 'lexed output is not from the end of a multi-line % statement' do
|
594
594
|
let(:lexed_output) do
|
595
|
-
[[[1, 11], :on_comma,
|
595
|
+
[[[1, 11], :on_comma, ','], [[1, 12], :on_nl, "\n"]]
|
596
596
|
end
|
597
597
|
|
598
|
-
it
|
598
|
+
it 'returns true' do
|
599
599
|
subject.end_of_multi_line_string?.should be_false
|
600
600
|
end
|
601
601
|
end
|
602
602
|
|
603
|
-
context
|
603
|
+
context 'lexed output contains start AND end of a multi-line % statement' do
|
604
604
|
let(:lexed_output) do
|
605
605
|
[
|
606
|
-
[[1, 0], :on_tstring_beg,
|
607
|
-
[[1, 3], :on_tstring_content,
|
608
|
-
[[1, 32], :on_tstring_end,
|
606
|
+
[[1, 0], :on_tstring_beg, '%Q{'],
|
607
|
+
[[1, 3], :on_tstring_content, 'this is a t string! suckaaaaaa!'],
|
608
|
+
[[1, 32], :on_tstring_end, '}']
|
609
609
|
]
|
610
610
|
end
|
611
611
|
|
612
|
-
it
|
612
|
+
it 'returns true' do
|
613
613
|
subject.end_of_multi_line_string?.should be_false
|
614
614
|
end
|
615
615
|
end
|
616
616
|
end
|
617
617
|
|
618
|
-
describe
|
618
|
+
describe '#is_line_only_a' do
|
619
619
|
let(:lexed_output) do
|
620
|
-
[[[1, 11], :on_comma,
|
620
|
+
[[[1, 11], :on_comma, ','], [[1, 12], :on_nl, "\n"]]
|
621
621
|
end
|
622
622
|
|
623
|
-
context
|
623
|
+
context 'last event is not the event passed in' do
|
624
624
|
let(:last_event) do
|
625
|
-
[[[1, 11], :on_comma,
|
625
|
+
[[[1, 11], :on_comma, ',']]
|
626
626
|
end
|
627
627
|
|
628
628
|
before do
|
@@ -632,24 +632,24 @@ describe Tailor::LexedLine do
|
|
632
632
|
specify { subject.is_line_only_a(:on_period).should be_false }
|
633
633
|
end
|
634
634
|
|
635
|
-
context
|
636
|
-
context
|
635
|
+
context 'last event is the last event passed in' do
|
636
|
+
context 'there is only space before the last event' do
|
637
637
|
let(:lexed_output) do
|
638
638
|
[
|
639
639
|
[[1, 0], :on_sp, ' '],
|
640
|
-
[[1, 11], :on_comma,
|
640
|
+
[[1, 11], :on_comma, ','],
|
641
641
|
[[1, 12], :on_nl, "\n"]]
|
642
642
|
end
|
643
643
|
|
644
644
|
specify { subject.is_line_only_a(:on_comma).should be_true }
|
645
645
|
end
|
646
646
|
|
647
|
-
context
|
647
|
+
context 'there is non-spaces before the last event' do
|
648
648
|
let(:lexed_output) do
|
649
649
|
[
|
650
|
-
[[1, 0], :on_sp,
|
651
|
-
[[1, 8], :on_ident,
|
652
|
-
[[1, 11], :on_comma,
|
650
|
+
[[1, 0], :on_sp, ' '],
|
651
|
+
[[1, 8], :on_ident, 'one'],
|
652
|
+
[[1, 11], :on_comma, ','],
|
653
653
|
[[1, 12], :on_nl, "\n"]]
|
654
654
|
end
|
655
655
|
|
@@ -658,57 +658,57 @@ describe Tailor::LexedLine do
|
|
658
658
|
end
|
659
659
|
end
|
660
660
|
|
661
|
-
describe
|
662
|
-
context
|
661
|
+
describe '#keyword_is_symbol?' do
|
662
|
+
context 'last event in line is not a keyword' do
|
663
663
|
let(:lexed_output) do
|
664
664
|
[
|
665
|
-
[[1, 0], :on_sp,
|
666
|
-
[[1, 8], :on_ident,
|
667
|
-
[[1, 11], :on_comma,
|
665
|
+
[[1, 0], :on_sp, ' '],
|
666
|
+
[[1, 8], :on_ident, 'one'],
|
667
|
+
[[1, 11], :on_comma, ','],
|
668
668
|
[[1, 12], :on_nl, "\n"]]
|
669
669
|
end
|
670
670
|
|
671
|
-
it
|
671
|
+
it 'returns false' do
|
672
672
|
subject.keyword_is_symbol?.should be_false
|
673
673
|
end
|
674
674
|
end
|
675
675
|
|
676
|
-
context
|
677
|
-
context
|
676
|
+
context 'last event in line is a keyword' do
|
677
|
+
context 'previous event is nil' do
|
678
678
|
let(:lexed_output) do
|
679
679
|
[
|
680
|
-
[[1, 0], :on_kw,
|
680
|
+
[[1, 0], :on_kw, 'class']
|
681
681
|
]
|
682
682
|
end
|
683
683
|
|
684
|
-
it
|
684
|
+
it 'returns false' do
|
685
685
|
subject.keyword_is_symbol?.should be_false
|
686
686
|
end
|
687
687
|
end
|
688
688
|
|
689
|
-
context
|
689
|
+
context 'previous event is not :on_symbeg' do
|
690
690
|
let(:lexed_output) do
|
691
691
|
[
|
692
|
-
[[1, 0], :on_sp,
|
693
|
-
[[1, 2], :on_kw,
|
692
|
+
[[1, 0], :on_sp, ' '],
|
693
|
+
[[1, 2], :on_kw, 'class']
|
694
694
|
]
|
695
695
|
end
|
696
696
|
|
697
|
-
it
|
697
|
+
it 'returns false' do
|
698
698
|
subject.keyword_is_symbol?.should be_false
|
699
699
|
end
|
700
700
|
end
|
701
701
|
|
702
|
-
context
|
702
|
+
context 'previous event is :on_symbeg' do
|
703
703
|
let(:lexed_output) do
|
704
704
|
[
|
705
|
-
[[1, 0], :on_const,
|
706
|
-
[[1, 9], :on_lbracket,
|
707
|
-
[[1, 10], :on_symbeg,
|
708
|
-
[[1, 11], :on_kw,
|
705
|
+
[[1, 0], :on_const, 'INDENT_OK'],
|
706
|
+
[[1, 9], :on_lbracket, '['],
|
707
|
+
[[1, 10], :on_symbeg, ':'],
|
708
|
+
[[1, 11], :on_kw, 'class']]
|
709
709
|
end
|
710
710
|
|
711
|
-
it
|
711
|
+
it 'returns true' do
|
712
712
|
subject.keyword_is_symbol?.should be_true
|
713
713
|
end
|
714
714
|
end
|