puppet-lint 0.4.0.pre1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +3 -4
- data/Gemfile +2 -5
- data/README.md +2 -149
- data/Rakefile +0 -5
- data/lib/puppet-lint.rb +74 -20
- data/lib/puppet-lint/bin.rb +20 -85
- data/lib/puppet-lint/checkplugin.rb +158 -12
- data/lib/puppet-lint/checks.rb +39 -222
- data/lib/puppet-lint/configuration.rb +12 -31
- data/lib/puppet-lint/data.rb +329 -0
- data/lib/puppet-lint/lexer.rb +37 -30
- data/lib/puppet-lint/lexer/token.rb +14 -16
- data/lib/puppet-lint/monkeypatches/string_prepend.rb +6 -0
- data/lib/puppet-lint/optparser.rb +105 -0
- data/lib/puppet-lint/plugins.rb +28 -9
- data/lib/puppet-lint/plugins/check_classes.rb +162 -238
- data/lib/puppet-lint/plugins/check_comments.rb +40 -25
- data/lib/puppet-lint/plugins/check_conditionals.rb +16 -20
- data/lib/puppet-lint/plugins/check_documentation.rb +14 -20
- data/lib/puppet-lint/plugins/check_nodes.rb +23 -0
- data/lib/puppet-lint/plugins/check_resources.rb +127 -141
- data/lib/puppet-lint/plugins/check_strings.rb +133 -107
- data/lib/puppet-lint/plugins/check_variables.rb +11 -11
- data/lib/puppet-lint/plugins/check_whitespace.rb +86 -92
- data/lib/puppet-lint/tasks/puppet-lint.rb +17 -1
- data/lib/puppet-lint/version.rb +1 -1
- data/puppet-lint.gemspec +4 -2
- data/spec/fixtures/test/manifests/ignore.pp +1 -0
- data/spec/fixtures/test/manifests/ignore_reason.pp +1 -0
- data/spec/puppet-lint/bin_spec.rb +104 -84
- data/spec/puppet-lint/configuration_spec.rb +19 -19
- data/spec/puppet-lint/ignore_overrides_spec.rb +97 -0
- data/spec/puppet-lint/lexer/token_spec.rb +9 -9
- data/spec/puppet-lint/lexer_spec.rb +352 -325
- data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +77 -23
- data/spec/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +14 -12
- data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +18 -14
- data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +30 -30
- data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +31 -26
- data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +34 -28
- data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +14 -12
- data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +74 -30
- data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +27 -20
- data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +78 -13
- data/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +17 -12
- data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +13 -10
- data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +21 -16
- data/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +69 -0
- data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +42 -38
- data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +22 -10
- data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +81 -18
- data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +69 -112
- data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +27 -20
- data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +177 -171
- data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +165 -88
- data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +97 -22
- data/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +25 -0
- data/spec/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb +97 -111
- data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +10 -9
- data/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +53 -53
- data/spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +26 -14
- data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +10 -9
- data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +31 -15
- data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +340 -322
- data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +30 -23
- data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +42 -41
- data/spec/puppet-lint_spec.rb +3 -3
- data/spec/spec_helper.rb +109 -116
- metadata +109 -50
- data/spec/puppet-lint/plugins/check_classes/class_parameter_defaults_spec.rb +0 -60
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'quoted_booleans', :type => :lint do
|
4
|
+
let(:msg) { 'quoted boolean value found' }
|
5
|
+
|
6
|
+
context 'with a single line ignore' do
|
7
|
+
let(:code) { "
|
8
|
+
'true'
|
9
|
+
'true' # lint:ignore:quoted_booleans
|
10
|
+
'false'
|
11
|
+
" }
|
12
|
+
|
13
|
+
it 'should detect three problems' do
|
14
|
+
expect(problems).to have(3).problems
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have two warnings' do
|
18
|
+
expect(problems).to contain_warning(msg).on_line(2).in_column(7)
|
19
|
+
expect(problems).to contain_warning(msg).on_line(4).in_column(7)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should have one ignored problem' do
|
23
|
+
expect(problems).to contain_ignored(msg).on_line(3).in_column(7)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with a single line ignore and a reason' do
|
28
|
+
let(:code) { "
|
29
|
+
'true'
|
30
|
+
'true' # lint:ignore:quoted_booleans some good reason
|
31
|
+
'false'
|
32
|
+
" }
|
33
|
+
|
34
|
+
it 'should detect three problems' do
|
35
|
+
expect(problems).to have(3).problems
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should have two warnings' do
|
39
|
+
expect(problems).to contain_warning(msg).on_line(2).in_column(7)
|
40
|
+
expect(problems).to contain_warning(msg).on_line(4).in_column(7)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should have one ignored problem with a reason' do
|
44
|
+
expect(problems).to contain_ignored(msg).on_line(3).in_column(7).with_reason('some good reason')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'with a block ignore' do
|
49
|
+
let(:code) { "
|
50
|
+
'true'
|
51
|
+
# lint:ignore:quoted_booleans
|
52
|
+
'false'
|
53
|
+
'true'
|
54
|
+
# lint:endignore
|
55
|
+
'true'
|
56
|
+
" }
|
57
|
+
|
58
|
+
it 'should detect four problems' do
|
59
|
+
expect(problems).to have(4).problems
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should have two warnings' do
|
63
|
+
expect(problems).to contain_warning(msg).on_line(2).in_column(7)
|
64
|
+
expect(problems).to contain_warning(msg).on_line(7).in_column(7)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should have two ignored problems' do
|
68
|
+
expect(problems).to contain_ignored(msg).on_line(4).in_column(7)
|
69
|
+
expect(problems).to contain_ignored(msg).on_line(5).in_column(7)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'with a block ignore and a reason' do
|
74
|
+
let(:code) { "
|
75
|
+
'true'
|
76
|
+
# lint:ignore:quoted_booleans another reason
|
77
|
+
'false'
|
78
|
+
'true'
|
79
|
+
# lint:endignore
|
80
|
+
'true'
|
81
|
+
" }
|
82
|
+
|
83
|
+
it 'should detect four problems' do
|
84
|
+
expect(problems).to have(4).problems
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should have two warnings' do
|
88
|
+
expect(problems).to contain_warning(msg).on_line(2).in_column(7)
|
89
|
+
expect(problems).to contain_warning(msg).on_line(7).in_column(7)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should have two ignored problems with a reason' do
|
93
|
+
expect(problems).to contain_ignored(msg).on_line(4).in_column(7).with_reason('another reason')
|
94
|
+
expect(problems).to contain_ignored(msg).on_line(5).in_column(7).with_reason('another reason')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -5,14 +5,14 @@ describe PuppetLint::Lexer::Token do
|
|
5
5
|
PuppetLint::Lexer::Token.new(:NAME, 'foo', 1, 2)
|
6
6
|
end
|
7
7
|
|
8
|
-
it {
|
9
|
-
it {
|
10
|
-
it {
|
11
|
-
it {
|
8
|
+
it { is_expected.to respond_to(:type) }
|
9
|
+
it { is_expected.to respond_to(:value) }
|
10
|
+
it { is_expected.to respond_to(:line) }
|
11
|
+
it { is_expected.to respond_to(:column) }
|
12
12
|
|
13
|
-
its(:type) {
|
14
|
-
its(:value) {
|
15
|
-
its(:line) {
|
16
|
-
its(:column) {
|
17
|
-
its(:inspect) {
|
13
|
+
its(:type) { is_expected.to eq(:NAME) }
|
14
|
+
its(:value) { is_expected.to eq('foo') }
|
15
|
+
its(:line) { is_expected.to eq(1) }
|
16
|
+
its(:column) { is_expected.to eq(2) }
|
17
|
+
its(:inspect) { is_expected.to eq("<Token :NAME (foo) @1:2>") }
|
18
18
|
end
|
@@ -7,34 +7,34 @@ describe PuppetLint::Lexer do
|
|
7
7
|
|
8
8
|
context 'invalid code' do
|
9
9
|
it 'should bork' do
|
10
|
-
expect { @lexer.tokenise('
|
10
|
+
expect { @lexer.tokenise('^') }.to raise_error(PuppetLint::LexerError)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
context '#new_token' do
|
15
15
|
it 'should calculate the line number for an empty string' do
|
16
16
|
token = @lexer.new_token(:TEST, 'test', :chunk => '')
|
17
|
-
token.line.
|
17
|
+
expect(token.line).to eq(1)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should calculate the line number for a multi line string' do
|
21
21
|
token = @lexer.new_token(:TEST, 'test', :chunk => "foo\nbar")
|
22
|
-
token.line.
|
22
|
+
expect(token.line).to eq(2)
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should calculate the column number for an empty string' do
|
26
26
|
token = @lexer.new_token(:TEST, 'test', :chunk => '')
|
27
|
-
token.column.
|
27
|
+
expect(token.column).to eq(1)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should calculate the column number for a single line string' do
|
31
31
|
token = @lexer.new_token(:TEST, 'test', :chunk => 'this is a test')
|
32
|
-
token.column.
|
32
|
+
expect(token.column).to eq(14)
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'should calculate the column number for a multi line string' do
|
36
36
|
token = @lexer.new_token(:TEST, 'test', :chunk => "foo\nbar\nbaz\ngronk")
|
37
|
-
token.column.
|
37
|
+
expect(token.column).to eq(5)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -42,22 +42,22 @@ describe PuppetLint::Lexer do
|
|
42
42
|
it 'should get a segment with a single terminator' do
|
43
43
|
data = StringScanner.new('foo"bar')
|
44
44
|
value, terminator = @lexer.get_string_segment(data, '"')
|
45
|
-
value.
|
46
|
-
terminator.
|
45
|
+
expect(value).to eq('foo')
|
46
|
+
expect(terminator).to eq('"')
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'should get a segment with multiple terminators' do
|
50
50
|
data = StringScanner.new('foo"bar$baz')
|
51
51
|
value, terminator = @lexer.get_string_segment(data, "'$")
|
52
|
-
value.
|
53
|
-
terminator.
|
52
|
+
expect(value).to eq('foo"bar')
|
53
|
+
expect(terminator).to eq('$')
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'should not get a segment with an escaped terminator' do
|
57
57
|
data = StringScanner.new('foo"bar')
|
58
58
|
value, terminator = @lexer.get_string_segment(data, '$')
|
59
|
-
value.
|
60
|
-
terminator.
|
59
|
+
expect(value).to be_nil
|
60
|
+
expect(terminator).to be_nil
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -66,410 +66,432 @@ describe PuppetLint::Lexer do
|
|
66
66
|
@lexer.interpolate_string('foo bar baz"',1, 1)
|
67
67
|
token = @lexer.tokens.first
|
68
68
|
|
69
|
-
@lexer.tokens.length.
|
70
|
-
token.type.
|
71
|
-
token.value.
|
72
|
-
token.line.
|
73
|
-
token.column.
|
69
|
+
expect(@lexer.tokens.length).to eq(1)
|
70
|
+
expect(token.type).to eq(:STRING)
|
71
|
+
expect(token.value).to eq('foo bar baz')
|
72
|
+
expect(token.line).to eq(1)
|
73
|
+
expect(token.column).to eq(1)
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'should handle a string with a newline' do
|
77
77
|
@lexer.interpolate_string(%{foo\nbar"}, 1, 1)
|
78
78
|
token = @lexer.tokens.first
|
79
79
|
|
80
|
-
@lexer.tokens.length.
|
81
|
-
token.type.
|
82
|
-
token.value.
|
83
|
-
token.line.
|
84
|
-
token.column.
|
80
|
+
expect(@lexer.tokens.length).to eq(1)
|
81
|
+
expect(token.type).to eq(:STRING)
|
82
|
+
expect(token.value).to eq("foo\nbar")
|
83
|
+
expect(token.line).to eq(1)
|
84
|
+
expect(token.column).to eq(1)
|
85
85
|
end
|
86
86
|
|
87
87
|
it 'should handle a string with a single variable and suffix' do
|
88
88
|
@lexer.interpolate_string('${foo}bar"', 1, 1)
|
89
89
|
tokens = @lexer.tokens
|
90
90
|
|
91
|
-
tokens.length.
|
91
|
+
expect(tokens.length).to eq(3)
|
92
92
|
|
93
|
-
tokens[0].type.
|
94
|
-
tokens[0].value.
|
95
|
-
tokens[0].line.
|
96
|
-
tokens[0].column.
|
93
|
+
expect(tokens[0].type).to eq(:DQPRE)
|
94
|
+
expect(tokens[0].value).to eq('')
|
95
|
+
expect(tokens[0].line).to eq(1)
|
96
|
+
expect(tokens[0].column).to eq(1)
|
97
97
|
|
98
|
-
tokens[1].type.
|
99
|
-
tokens[1].value.
|
100
|
-
tokens[1].line.
|
101
|
-
tokens[1].column.
|
98
|
+
expect(tokens[1].type).to eq(:VARIABLE)
|
99
|
+
expect(tokens[1].value).to eq('foo')
|
100
|
+
expect(tokens[1].line).to eq(1)
|
101
|
+
expect(tokens[1].column).to eq(3)
|
102
102
|
|
103
|
-
tokens[2].type.
|
104
|
-
tokens[2].value.
|
105
|
-
tokens[2].line.
|
106
|
-
tokens[2].column.
|
103
|
+
expect(tokens[2].type).to eq(:DQPOST)
|
104
|
+
expect(tokens[2].value).to eq('bar')
|
105
|
+
expect(tokens[2].line).to eq(1)
|
106
|
+
expect(tokens[2].column).to eq(8)
|
107
107
|
end
|
108
108
|
|
109
109
|
it 'should handle a string with a single variable and surrounding text' do
|
110
110
|
@lexer.interpolate_string('foo${bar}baz"', 1, 1)
|
111
111
|
tokens = @lexer.tokens
|
112
112
|
|
113
|
-
tokens.length.
|
113
|
+
expect(tokens.length).to eq(3)
|
114
114
|
|
115
|
-
tokens[0].type.
|
116
|
-
tokens[0].value.
|
117
|
-
tokens[0].line.
|
118
|
-
tokens[0].column.
|
115
|
+
expect(tokens[0].type).to eq(:DQPRE)
|
116
|
+
expect(tokens[0].value).to eq('foo')
|
117
|
+
expect(tokens[0].line).to eq(1)
|
118
|
+
expect(tokens[0].column).to eq(1)
|
119
119
|
|
120
|
-
tokens[1].type.
|
121
|
-
tokens[1].value.
|
122
|
-
tokens[1].line.
|
123
|
-
tokens[1].column.
|
120
|
+
expect(tokens[1].type).to eq(:VARIABLE)
|
121
|
+
expect(tokens[1].value).to eq('bar')
|
122
|
+
expect(tokens[1].line).to eq(1)
|
123
|
+
expect(tokens[1].column).to eq(6)
|
124
124
|
|
125
|
-
tokens[2].type.
|
126
|
-
tokens[2].value.
|
127
|
-
tokens[2].line.
|
128
|
-
tokens[2].column.
|
125
|
+
expect(tokens[2].type).to eq(:DQPOST)
|
126
|
+
expect(tokens[2].value).to eq('baz')
|
127
|
+
expect(tokens[2].line).to eq(1)
|
128
|
+
expect(tokens[2].column).to eq(11)
|
129
129
|
end
|
130
130
|
|
131
131
|
it 'should handle a string with multiple variables and surrounding text' do
|
132
132
|
@lexer.interpolate_string('foo${bar}baz${gronk}meh"', 1, 1)
|
133
133
|
tokens = @lexer.tokens
|
134
134
|
|
135
|
-
tokens.length.
|
135
|
+
expect(tokens.length).to eq(5)
|
136
136
|
|
137
|
-
tokens[0].type.
|
138
|
-
tokens[0].value.
|
139
|
-
tokens[0].line.
|
140
|
-
tokens[0].column.
|
137
|
+
expect(tokens[0].type).to eq(:DQPRE)
|
138
|
+
expect(tokens[0].value).to eq('foo')
|
139
|
+
expect(tokens[0].line).to eq(1)
|
140
|
+
expect(tokens[0].column).to eq(1)
|
141
141
|
|
142
|
-
tokens[1].type.
|
143
|
-
tokens[1].value.
|
144
|
-
tokens[1].line.
|
145
|
-
tokens[1].column.
|
142
|
+
expect(tokens[1].type).to eq(:VARIABLE)
|
143
|
+
expect(tokens[1].value).to eq('bar')
|
144
|
+
expect(tokens[1].line).to eq(1)
|
145
|
+
expect(tokens[1].column).to eq(6)
|
146
146
|
|
147
|
-
tokens[2].type.
|
148
|
-
tokens[2].value.
|
149
|
-
tokens[2].line.
|
150
|
-
tokens[2].column.
|
147
|
+
expect(tokens[2].type).to eq(:DQMID)
|
148
|
+
expect(tokens[2].value).to eq('baz')
|
149
|
+
expect(tokens[2].line).to eq(1)
|
150
|
+
expect(tokens[2].column).to eq(11)
|
151
151
|
|
152
|
-
tokens[3].type.
|
153
|
-
tokens[3].value.
|
154
|
-
tokens[3].line.
|
155
|
-
tokens[3].column.
|
152
|
+
expect(tokens[3].type).to eq(:VARIABLE)
|
153
|
+
expect(tokens[3].value).to eq('gronk')
|
154
|
+
expect(tokens[3].line).to eq(1)
|
155
|
+
expect(tokens[3].column).to eq(15)
|
156
156
|
|
157
|
-
tokens[4].type.
|
158
|
-
tokens[4].value.
|
159
|
-
tokens[4].line.
|
160
|
-
tokens[4].column.
|
157
|
+
expect(tokens[4].type).to eq(:DQPOST)
|
158
|
+
expect(tokens[4].value).to eq('meh')
|
159
|
+
expect(tokens[4].line).to eq(1)
|
160
|
+
expect(tokens[4].column).to eq(22)
|
161
161
|
end
|
162
162
|
|
163
163
|
it 'should handle a string with only a single variable' do
|
164
164
|
@lexer.interpolate_string('${bar}"', 1, 1)
|
165
165
|
tokens = @lexer.tokens
|
166
166
|
|
167
|
-
tokens.length.
|
167
|
+
expect(tokens.length).to eq(3)
|
168
168
|
|
169
|
-
tokens[0].type.
|
170
|
-
tokens[0].value.
|
171
|
-
tokens[0].line.
|
172
|
-
tokens[0].column.
|
169
|
+
expect(tokens[0].type).to eq(:DQPRE)
|
170
|
+
expect(tokens[0].value).to eq('')
|
171
|
+
expect(tokens[0].line).to eq(1)
|
172
|
+
expect(tokens[0].column).to eq(1)
|
173
173
|
|
174
|
-
tokens[1].type.
|
175
|
-
tokens[1].value.
|
176
|
-
tokens[1].line.
|
177
|
-
tokens[1].column.
|
174
|
+
expect(tokens[1].type).to eq(:VARIABLE)
|
175
|
+
expect(tokens[1].value).to eq('bar')
|
176
|
+
expect(tokens[1].line).to eq(1)
|
177
|
+
expect(tokens[1].column).to eq(3)
|
178
178
|
|
179
|
-
tokens[2].type.
|
180
|
-
tokens[2].value.
|
181
|
-
tokens[2].line.
|
182
|
-
tokens[2].column.
|
179
|
+
expect(tokens[2].type).to eq(:DQPOST)
|
180
|
+
expect(tokens[2].value).to eq('')
|
181
|
+
expect(tokens[2].line).to eq(1)
|
182
|
+
expect(tokens[2].column).to eq(8)
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'should handle a variable with an array reference' do
|
186
|
+
@lexer.interpolate_string('${foo[bar][baz]}"', 1, 1)
|
187
|
+
tokens = @lexer.tokens
|
188
|
+
|
189
|
+
expect(tokens.length).to eq(3)
|
190
|
+
|
191
|
+
expect(tokens[0].type).to eq(:DQPRE)
|
192
|
+
expect(tokens[0].value).to eq('')
|
193
|
+
expect(tokens[0].line).to eq(1)
|
194
|
+
expect(tokens[0].column).to eq(1)
|
195
|
+
|
196
|
+
expect(tokens[1].type).to eq(:VARIABLE)
|
197
|
+
expect(tokens[1].value).to eq('foo[bar][baz]')
|
198
|
+
expect(tokens[1].line).to eq(1)
|
199
|
+
expect(tokens[1].column).to eq(3)
|
200
|
+
|
201
|
+
expect(tokens[2].type).to eq(:DQPOST)
|
202
|
+
expect(tokens[2].value).to eq('')
|
203
|
+
expect(tokens[2].line).to eq(1)
|
204
|
+
expect(tokens[2].column).to eq(18)
|
183
205
|
end
|
184
206
|
|
185
207
|
it 'should handle a string with only many variables' do
|
186
208
|
@lexer.interpolate_string('${bar}${gronk}"', 1, 1)
|
187
209
|
tokens = @lexer.tokens
|
188
210
|
|
189
|
-
tokens.length.
|
211
|
+
expect(tokens.length).to eq(5)
|
190
212
|
|
191
|
-
tokens[0].type.
|
192
|
-
tokens[0].value.
|
193
|
-
tokens[0].line.
|
194
|
-
tokens[0].column.
|
213
|
+
expect(tokens[0].type).to eq(:DQPRE)
|
214
|
+
expect(tokens[0].value).to eq('')
|
215
|
+
expect(tokens[0].line).to eq(1)
|
216
|
+
expect(tokens[0].column).to eq(1)
|
195
217
|
|
196
|
-
tokens[1].type.
|
197
|
-
tokens[1].value.
|
198
|
-
tokens[1].line.
|
199
|
-
tokens[1].column.
|
218
|
+
expect(tokens[1].type).to eq(:VARIABLE)
|
219
|
+
expect(tokens[1].value).to eq('bar')
|
220
|
+
expect(tokens[1].line).to eq(1)
|
221
|
+
expect(tokens[1].column).to eq(3)
|
200
222
|
|
201
|
-
tokens[2].type.
|
202
|
-
tokens[2].value.
|
203
|
-
tokens[2].line.
|
204
|
-
tokens[2].column.
|
223
|
+
expect(tokens[2].type).to eq(:DQMID)
|
224
|
+
expect(tokens[2].value).to eq('')
|
225
|
+
expect(tokens[2].line).to eq(1)
|
226
|
+
expect(tokens[2].column).to eq(8)
|
205
227
|
|
206
|
-
tokens[3].type.
|
207
|
-
tokens[3].value.
|
208
|
-
tokens[3].line.
|
209
|
-
tokens[3].column.
|
228
|
+
expect(tokens[3].type).to eq(:VARIABLE)
|
229
|
+
expect(tokens[3].value).to eq('gronk')
|
230
|
+
expect(tokens[3].line).to eq(1)
|
231
|
+
expect(tokens[3].column).to eq(9)
|
210
232
|
|
211
|
-
tokens[4].type.
|
212
|
-
tokens[4].value.
|
213
|
-
tokens[4].line.
|
214
|
-
tokens[4].column.
|
233
|
+
expect(tokens[4].type).to eq(:DQPOST)
|
234
|
+
expect(tokens[4].value).to eq('')
|
235
|
+
expect(tokens[4].line).to eq(1)
|
236
|
+
expect(tokens[4].column).to eq(16)
|
215
237
|
end
|
216
238
|
|
217
239
|
it 'should handle a string with only an unenclosed variable' do
|
218
240
|
@lexer.interpolate_string('$foo"', 1, 1)
|
219
241
|
tokens = @lexer.tokens
|
220
242
|
|
221
|
-
tokens.length.
|
243
|
+
expect(tokens.length).to eq(3)
|
222
244
|
|
223
|
-
tokens[0].type.
|
224
|
-
tokens[0].value.
|
225
|
-
tokens[0].line.
|
226
|
-
tokens[0].column.
|
245
|
+
expect(tokens[0].type).to eq(:DQPRE)
|
246
|
+
expect(tokens[0].value).to eq('')
|
247
|
+
expect(tokens[0].line).to eq(1)
|
248
|
+
expect(tokens[0].column).to eq(1)
|
227
249
|
|
228
|
-
tokens[1].type.
|
229
|
-
tokens[1].value.
|
230
|
-
tokens[1].line.
|
231
|
-
tokens[1].column.
|
250
|
+
expect(tokens[1].type).to eq(:UNENC_VARIABLE)
|
251
|
+
expect(tokens[1].value).to eq('foo')
|
252
|
+
expect(tokens[1].line).to eq(1)
|
253
|
+
expect(tokens[1].column).to eq(2)
|
232
254
|
|
233
|
-
tokens[2].type.
|
234
|
-
tokens[2].value.
|
235
|
-
tokens[2].line.
|
236
|
-
tokens[2].column.
|
255
|
+
expect(tokens[2].type).to eq(:DQPOST)
|
256
|
+
expect(tokens[2].value).to eq('')
|
257
|
+
expect(tokens[2].line).to eq(1)
|
258
|
+
expect(tokens[2].column).to eq(6)
|
237
259
|
end
|
238
260
|
|
239
261
|
it 'should handle a string with a nested string inside it' do
|
240
262
|
@lexer.interpolate_string(%q{string with ${'a nested single quoted string'} inside it"}, 1, 1)
|
241
263
|
tokens = @lexer.tokens
|
242
264
|
|
243
|
-
tokens.length.
|
265
|
+
expect(tokens.length).to eq(3)
|
244
266
|
|
245
|
-
tokens[0].type.
|
246
|
-
tokens[0].value.
|
247
|
-
tokens[0].line.
|
248
|
-
tokens[0].column.
|
267
|
+
expect(tokens[0].type).to eq(:DQPRE)
|
268
|
+
expect(tokens[0].value).to eq('string with ')
|
269
|
+
expect(tokens[0].line).to eq(1)
|
270
|
+
expect(tokens[0].column).to eq(1)
|
249
271
|
|
250
|
-
tokens[1].type.
|
251
|
-
tokens[1].value.
|
252
|
-
tokens[1].line.
|
253
|
-
tokens[1].column.
|
272
|
+
expect(tokens[1].type).to eq(:SSTRING)
|
273
|
+
expect(tokens[1].value).to eq('a nested single quoted string')
|
274
|
+
expect(tokens[1].line).to eq(1)
|
275
|
+
expect(tokens[1].column).to eq(16)
|
254
276
|
|
255
|
-
tokens[2].type.
|
256
|
-
tokens[2].value.
|
257
|
-
tokens[2].line.
|
258
|
-
tokens[2].column.
|
277
|
+
expect(tokens[2].type).to eq(:DQPOST)
|
278
|
+
expect(tokens[2].value).to eq(' inside it')
|
279
|
+
expect(tokens[2].line).to eq(1)
|
280
|
+
expect(tokens[2].column).to eq(48)
|
259
281
|
end
|
260
282
|
|
261
283
|
it 'should handle a string with nested math' do
|
262
284
|
@lexer.interpolate_string(%q{string with ${(3+5)/4} nested math"}, 1, 1)
|
263
285
|
tokens = @lexer.tokens
|
264
286
|
|
265
|
-
tokens.length.
|
287
|
+
expect(tokens.length).to eq(9)
|
266
288
|
|
267
|
-
tokens[0].type.
|
268
|
-
tokens[0].value.
|
269
|
-
tokens[0].line.
|
270
|
-
tokens[0].column.
|
289
|
+
expect(tokens[0].type).to eq(:DQPRE)
|
290
|
+
expect(tokens[0].value).to eq('string with ')
|
291
|
+
expect(tokens[0].line).to eq(1)
|
292
|
+
expect(tokens[0].column).to eq(1)
|
271
293
|
|
272
|
-
tokens[1].type.
|
273
|
-
tokens[1].line.
|
274
|
-
tokens[1].column.
|
294
|
+
expect(tokens[1].type).to eq(:LPAREN)
|
295
|
+
expect(tokens[1].line).to eq(1)
|
296
|
+
expect(tokens[1].column).to eq(16)
|
275
297
|
|
276
|
-
tokens[2].type.
|
277
|
-
tokens[2].value.
|
278
|
-
tokens[2].line.
|
279
|
-
tokens[2].column.
|
298
|
+
expect(tokens[2].type).to eq(:NUMBER)
|
299
|
+
expect(tokens[2].value).to eq('3')
|
300
|
+
expect(tokens[2].line).to eq(1)
|
301
|
+
expect(tokens[2].column).to eq(17)
|
280
302
|
|
281
|
-
tokens[3].type.
|
282
|
-
tokens[3].line.
|
283
|
-
tokens[3].column.
|
303
|
+
expect(tokens[3].type).to eq(:PLUS)
|
304
|
+
expect(tokens[3].line).to eq(1)
|
305
|
+
expect(tokens[3].column).to eq(18)
|
284
306
|
|
285
|
-
tokens[4].type.
|
286
|
-
tokens[4].value.
|
287
|
-
tokens[4].line.
|
288
|
-
tokens[4].column.
|
307
|
+
expect(tokens[4].type).to eq(:NUMBER)
|
308
|
+
expect(tokens[4].value).to eq('5')
|
309
|
+
expect(tokens[4].line).to eq(1)
|
310
|
+
expect(tokens[4].column).to eq(19)
|
289
311
|
|
290
|
-
tokens[5].type.
|
291
|
-
tokens[5].line.
|
292
|
-
tokens[5].column.
|
312
|
+
expect(tokens[5].type).to eq(:RPAREN)
|
313
|
+
expect(tokens[5].line).to eq(1)
|
314
|
+
expect(tokens[5].column).to eq(20)
|
293
315
|
|
294
|
-
tokens[6].type.
|
295
|
-
tokens[6].line.
|
296
|
-
tokens[6].column.
|
316
|
+
expect(tokens[6].type).to eq(:DIV)
|
317
|
+
expect(tokens[6].line).to eq(1)
|
318
|
+
expect(tokens[6].column).to eq(21)
|
297
319
|
|
298
|
-
tokens[7].type.
|
299
|
-
tokens[7].value.
|
300
|
-
tokens[7].line.
|
301
|
-
tokens[7].column.
|
320
|
+
expect(tokens[7].type).to eq(:NUMBER)
|
321
|
+
expect(tokens[7].value).to eq('4')
|
322
|
+
expect(tokens[7].line).to eq(1)
|
323
|
+
expect(tokens[7].column).to eq(22)
|
302
324
|
|
303
|
-
tokens[8].type.
|
304
|
-
tokens[8].value.
|
305
|
-
tokens[8].line.
|
306
|
-
tokens[8].column.
|
325
|
+
expect(tokens[8].type).to eq(:DQPOST)
|
326
|
+
expect(tokens[8].value).to eq(' nested math')
|
327
|
+
expect(tokens[8].line).to eq(1)
|
328
|
+
expect(tokens[8].column).to eq(24)
|
307
329
|
end
|
308
330
|
|
309
331
|
it 'should handle a string with a nested array' do
|
310
332
|
@lexer.interpolate_string(%q{string with ${['an array ', $v2]} in it"}, 1, 1)
|
311
333
|
tokens = @lexer.tokens
|
312
334
|
|
313
|
-
tokens.length.
|
335
|
+
expect(tokens.length).to eq(8)
|
314
336
|
|
315
|
-
tokens[0].type.
|
316
|
-
tokens[0].value.
|
317
|
-
tokens[0].line.
|
318
|
-
tokens[0].column.
|
337
|
+
expect(tokens[0].type).to eq(:DQPRE)
|
338
|
+
expect(tokens[0].value).to eq('string with ')
|
339
|
+
expect(tokens[0].line).to eq(1)
|
340
|
+
expect(tokens[0].column).to eq(1)
|
319
341
|
|
320
|
-
tokens[1].type.
|
321
|
-
tokens[1].line.
|
322
|
-
tokens[1].column.
|
342
|
+
expect(tokens[1].type).to eq(:LBRACK)
|
343
|
+
expect(tokens[1].line).to eq(1)
|
344
|
+
expect(tokens[1].column).to eq(16)
|
323
345
|
|
324
|
-
tokens[2].type.
|
325
|
-
tokens[2].value.
|
326
|
-
tokens[2].line.
|
327
|
-
tokens[2].column.
|
346
|
+
expect(tokens[2].type).to eq(:SSTRING)
|
347
|
+
expect(tokens[2].value).to eq('an array ')
|
348
|
+
expect(tokens[2].line).to eq(1)
|
349
|
+
expect(tokens[2].column).to eq(17)
|
328
350
|
|
329
|
-
tokens[3].type.
|
330
|
-
tokens[3].line.
|
331
|
-
tokens[3].column.
|
351
|
+
expect(tokens[3].type).to eq(:COMMA)
|
352
|
+
expect(tokens[3].line).to eq(1)
|
353
|
+
expect(tokens[3].column).to eq(28)
|
332
354
|
|
333
|
-
tokens[4].type.
|
334
|
-
tokens[4].value.
|
335
|
-
tokens[4].line.
|
336
|
-
tokens[4].column.
|
355
|
+
expect(tokens[4].type).to eq(:WHITESPACE)
|
356
|
+
expect(tokens[4].value).to eq(' ')
|
357
|
+
expect(tokens[4].line).to eq(1)
|
358
|
+
expect(tokens[4].column).to eq(29)
|
337
359
|
|
338
|
-
tokens[5].type.
|
339
|
-
tokens[5].value.
|
340
|
-
tokens[5].line.
|
341
|
-
tokens[5].column.
|
360
|
+
expect(tokens[5].type).to eq(:VARIABLE)
|
361
|
+
expect(tokens[5].value).to eq('v2')
|
362
|
+
expect(tokens[5].line).to eq(1)
|
363
|
+
expect(tokens[5].column).to eq(30)
|
342
364
|
|
343
|
-
tokens[6].type.
|
344
|
-
tokens[6].line.
|
345
|
-
tokens[6].column.
|
365
|
+
expect(tokens[6].type).to eq(:RBRACK)
|
366
|
+
expect(tokens[6].line).to eq(1)
|
367
|
+
expect(tokens[6].column).to eq(33)
|
346
368
|
|
347
|
-
tokens[7].type.
|
348
|
-
tokens[7].value.
|
349
|
-
tokens[7].line.
|
350
|
-
tokens[7].column.
|
369
|
+
expect(tokens[7].type).to eq(:DQPOST)
|
370
|
+
expect(tokens[7].value).to eq(' in it')
|
371
|
+
expect(tokens[7].line).to eq(1)
|
372
|
+
expect(tokens[7].column).to eq(35)
|
351
373
|
end
|
352
374
|
|
353
375
|
it 'should handle a string of $s' do
|
354
376
|
@lexer.interpolate_string(%q{$$$$"}, 1, 1)
|
355
377
|
tokens = @lexer.tokens
|
356
378
|
|
357
|
-
tokens.length.
|
379
|
+
expect(tokens.length).to eq(1)
|
358
380
|
|
359
|
-
tokens[0].type.
|
360
|
-
tokens[0].value.
|
361
|
-
tokens[0].line.
|
362
|
-
tokens[0].column.
|
381
|
+
expect(tokens[0].type).to eq(:STRING)
|
382
|
+
expect(tokens[0].value).to eq('$$$$')
|
383
|
+
expect(tokens[0].line).to eq(1)
|
384
|
+
expect(tokens[0].column).to eq(1)
|
363
385
|
end
|
364
386
|
|
365
387
|
it 'should handle "$foo$bar"' do
|
366
388
|
@lexer.interpolate_string(%q{$foo$bar"}, 1, 1)
|
367
389
|
tokens = @lexer.tokens
|
368
390
|
|
369
|
-
tokens.length.
|
391
|
+
expect(tokens.length).to eq(5)
|
370
392
|
|
371
|
-
tokens[0].type.
|
372
|
-
tokens[0].value.
|
373
|
-
tokens[0].line.
|
374
|
-
tokens[0].column.
|
393
|
+
expect(tokens[0].type).to eq(:DQPRE)
|
394
|
+
expect(tokens[0].value).to eq('')
|
395
|
+
expect(tokens[0].line).to eq(1)
|
396
|
+
expect(tokens[0].column).to eq(1)
|
375
397
|
|
376
|
-
tokens[1].type.
|
377
|
-
tokens[1].value.
|
378
|
-
tokens[1].line.
|
379
|
-
tokens[1].column.
|
398
|
+
expect(tokens[1].type).to eq(:UNENC_VARIABLE)
|
399
|
+
expect(tokens[1].value).to eq('foo')
|
400
|
+
expect(tokens[1].line).to eq(1)
|
401
|
+
expect(tokens[1].column).to eq(2)
|
380
402
|
|
381
|
-
tokens[2].type.
|
382
|
-
tokens[2].value.
|
383
|
-
tokens[2].line.
|
384
|
-
tokens[2].column.
|
403
|
+
expect(tokens[2].type).to eq(:DQMID)
|
404
|
+
expect(tokens[2].value).to eq('')
|
405
|
+
expect(tokens[2].line).to eq(1)
|
406
|
+
expect(tokens[2].column).to eq(6)
|
385
407
|
|
386
|
-
tokens[3].type.
|
387
|
-
tokens[3].value.
|
388
|
-
tokens[3].line.
|
389
|
-
tokens[3].column.
|
408
|
+
expect(tokens[3].type).to eq(:UNENC_VARIABLE)
|
409
|
+
expect(tokens[3].value).to eq('bar')
|
410
|
+
expect(tokens[3].line).to eq(1)
|
411
|
+
expect(tokens[3].column).to eq(6)
|
390
412
|
|
391
|
-
tokens[4].type.
|
392
|
-
tokens[4].value.
|
393
|
-
tokens[4].line.
|
394
|
-
tokens[4].column.
|
413
|
+
expect(tokens[4].type).to eq(:DQPOST)
|
414
|
+
expect(tokens[4].value).to eq('')
|
415
|
+
expect(tokens[4].line).to eq(1)
|
416
|
+
expect(tokens[4].column).to eq(10)
|
395
417
|
end
|
396
418
|
|
397
419
|
it 'should handle "foo$bar$"' do
|
398
420
|
@lexer.interpolate_string(%q{foo$bar$"}, 1, 1)
|
399
421
|
tokens = @lexer.tokens
|
400
422
|
|
401
|
-
tokens.length.
|
423
|
+
expect(tokens.length).to eq(3)
|
402
424
|
|
403
|
-
tokens[0].type.
|
404
|
-
tokens[0].value.
|
405
|
-
tokens[0].line.
|
406
|
-
tokens[0].column.
|
425
|
+
expect(tokens[0].type).to eq(:DQPRE)
|
426
|
+
expect(tokens[0].value).to eq('foo')
|
427
|
+
expect(tokens[0].line).to eq(1)
|
428
|
+
expect(tokens[0].column).to eq(1)
|
407
429
|
|
408
|
-
tokens[1].type.
|
409
|
-
tokens[1].value.
|
410
|
-
tokens[1].line.
|
411
|
-
tokens[1].column.
|
430
|
+
expect(tokens[1].type).to eq(:UNENC_VARIABLE)
|
431
|
+
expect(tokens[1].value).to eq('bar')
|
432
|
+
expect(tokens[1].line).to eq(1)
|
433
|
+
expect(tokens[1].column).to eq(5)
|
412
434
|
|
413
|
-
tokens[2].type.
|
414
|
-
tokens[2].value.
|
415
|
-
tokens[2].line.
|
416
|
-
tokens[2].column.
|
435
|
+
expect(tokens[2].type).to eq(:DQPOST)
|
436
|
+
expect(tokens[2].value).to eq('$')
|
437
|
+
expect(tokens[2].line).to eq(1)
|
438
|
+
expect(tokens[2].column).to eq(9)
|
417
439
|
end
|
418
440
|
|
419
441
|
it 'should handle "foo$$bar"' do
|
420
442
|
@lexer.interpolate_string(%q{foo$$bar"}, 1, 1)
|
421
443
|
tokens = @lexer.tokens
|
422
444
|
|
423
|
-
tokens.length.
|
445
|
+
expect(tokens.length).to eq(3)
|
424
446
|
|
425
|
-
tokens[0].type.
|
426
|
-
tokens[0].value.
|
427
|
-
tokens[0].line.
|
428
|
-
tokens[0].column.
|
447
|
+
expect(tokens[0].type).to eq(:DQPRE)
|
448
|
+
expect(tokens[0].value).to eq('foo$')
|
449
|
+
expect(tokens[0].line).to eq(1)
|
450
|
+
expect(tokens[0].column).to eq(1)
|
429
451
|
|
430
|
-
tokens[1].type.
|
431
|
-
tokens[1].value.
|
432
|
-
tokens[1].line.
|
433
|
-
tokens[1].column.
|
452
|
+
expect(tokens[1].type).to eq(:UNENC_VARIABLE)
|
453
|
+
expect(tokens[1].value).to eq('bar')
|
454
|
+
expect(tokens[1].line).to eq(1)
|
455
|
+
expect(tokens[1].column).to eq(6)
|
434
456
|
|
435
|
-
tokens[2].type.
|
436
|
-
tokens[2].value.
|
437
|
-
tokens[2].line.
|
438
|
-
tokens[2].column.
|
457
|
+
expect(tokens[2].type).to eq(:DQPOST)
|
458
|
+
expect(tokens[2].value).to eq('')
|
459
|
+
expect(tokens[2].line).to eq(1)
|
460
|
+
expect(tokens[2].column).to eq(10)
|
439
461
|
end
|
440
462
|
|
441
463
|
it 'should handle an empty string' do
|
442
464
|
@lexer.interpolate_string(%q{"}, 1, 1)
|
443
465
|
tokens = @lexer.tokens
|
444
466
|
|
445
|
-
tokens.length.
|
467
|
+
expect(tokens.length).to eq(1)
|
446
468
|
|
447
|
-
tokens[0].type.
|
448
|
-
tokens[0].value.
|
449
|
-
tokens[0].line.
|
450
|
-
tokens[0].column.
|
469
|
+
expect(tokens[0].type).to eq(:STRING)
|
470
|
+
expect(tokens[0].value).to eq('')
|
471
|
+
expect(tokens[0].line).to eq(1)
|
472
|
+
expect(tokens[0].column).to eq(1)
|
451
473
|
end
|
452
474
|
|
453
475
|
it 'should handle "$foo::::bar"' do
|
454
476
|
@lexer.interpolate_string(%q{$foo::::bar"}, 1, 1)
|
455
477
|
tokens = @lexer.tokens
|
456
478
|
|
457
|
-
tokens.length.
|
479
|
+
expect(tokens.length).to eq(3)
|
458
480
|
|
459
|
-
tokens[0].type.
|
460
|
-
tokens[0].value.
|
461
|
-
tokens[0].line.
|
462
|
-
tokens[0].column.
|
481
|
+
expect(tokens[0].type).to eq(:DQPRE)
|
482
|
+
expect(tokens[0].value).to eq('')
|
483
|
+
expect(tokens[0].line).to eq(1)
|
484
|
+
expect(tokens[0].column).to eq(1)
|
463
485
|
|
464
|
-
tokens[1].type.
|
465
|
-
tokens[1].value.
|
466
|
-
tokens[1].line.
|
467
|
-
tokens[1].column.
|
486
|
+
expect(tokens[1].type).to eq(:UNENC_VARIABLE)
|
487
|
+
expect(tokens[1].value).to eq('foo')
|
488
|
+
expect(tokens[1].line).to eq(1)
|
489
|
+
expect(tokens[1].column).to eq(2)
|
468
490
|
|
469
|
-
tokens[2].type.
|
470
|
-
tokens[2].value.
|
471
|
-
tokens[2].line.
|
472
|
-
tokens[2].column.
|
491
|
+
expect(tokens[2].type).to eq(:DQPOST)
|
492
|
+
expect(tokens[2].value).to eq('::::bar')
|
493
|
+
expect(tokens[2].line).to eq(1)
|
494
|
+
expect(tokens[2].column).to eq(6)
|
473
495
|
end
|
474
496
|
end
|
475
497
|
|
@@ -494,8 +516,8 @@ describe PuppetLint::Lexer do
|
|
494
516
|
].each do |keyword|
|
495
517
|
it "should handle '#{keyword}' as a keyword" do
|
496
518
|
token = @lexer.tokenise(keyword).first
|
497
|
-
token.type.
|
498
|
-
token.value.
|
519
|
+
expect(token.type).to eq(keyword.upcase.to_sym)
|
520
|
+
expect(token.value).to eq(keyword)
|
499
521
|
end
|
500
522
|
end
|
501
523
|
|
@@ -532,6 +554,8 @@ describe PuppetLint::Lexer do
|
|
532
554
|
[:MINUS, '-'],
|
533
555
|
[:DIV, '/'],
|
534
556
|
[:TIMES, '*'],
|
557
|
+
[:MODULO, '%'],
|
558
|
+
[:PIPE, '|'],
|
535
559
|
[:LSHIFT, '<<'],
|
536
560
|
[:RSHIFT, '>>'],
|
537
561
|
[:MATCH, '=~'],
|
@@ -540,205 +564,208 @@ describe PuppetLint::Lexer do
|
|
540
564
|
[:OUT_EDGE, '<-'],
|
541
565
|
[:IN_EDGE_SUB, '~>'],
|
542
566
|
[:OUT_EDGE_SUB, '<~'],
|
567
|
+
[:NEWLINE, "\r"],
|
568
|
+
[:NEWLINE, "\n"],
|
569
|
+
[:NEWLINE, "\r\n"],
|
543
570
|
].each do |name, string|
|
544
571
|
it "should have a token named '#{name.to_s}'" do
|
545
572
|
token = @lexer.tokenise(string).first
|
546
|
-
token.type.
|
547
|
-
token.value.
|
573
|
+
expect(token.type).to eq(name)
|
574
|
+
expect(token.value).to eq(string)
|
548
575
|
end
|
549
576
|
end
|
550
577
|
|
551
578
|
context ':CLASSREF' do
|
552
579
|
it 'should match single capitalised alphanumeric term' do
|
553
580
|
token = @lexer.tokenise('One').first
|
554
|
-
token.type.
|
555
|
-
token.value.
|
581
|
+
expect(token.type).to eq(:CLASSREF)
|
582
|
+
expect(token.value).to eq('One')
|
556
583
|
end
|
557
584
|
|
558
585
|
it 'should match two capitalised alphanumeric terms sep by ::' do
|
559
586
|
token = @lexer.tokenise('One::Two').first
|
560
|
-
token.type.
|
561
|
-
token.value.
|
587
|
+
expect(token.type).to eq(:CLASSREF)
|
588
|
+
expect(token.value).to eq('One::Two')
|
562
589
|
end
|
563
590
|
|
564
591
|
it 'should match many capitalised alphanumeric terms sep by ::' do
|
565
592
|
token = @lexer.tokenise('One::Two::Three::Four::Five').first
|
566
|
-
token.type.
|
567
|
-
token.value.
|
593
|
+
expect(token.type).to eq(:CLASSREF)
|
594
|
+
expect(token.value).to eq('One::Two::Three::Four::Five')
|
568
595
|
end
|
569
596
|
|
570
597
|
it 'should match capitalised terms prefixed by ::' do
|
571
598
|
token = @lexer.tokenise('::One').first
|
572
|
-
token.type.
|
573
|
-
token.value.
|
599
|
+
expect(token.type).to eq(:CLASSREF)
|
600
|
+
expect(token.value).to eq('::One')
|
574
601
|
end
|
575
602
|
end
|
576
603
|
|
577
604
|
context ':NAME' do
|
578
605
|
it 'should match lowercase alphanumeric terms' do
|
579
606
|
token = @lexer.tokenise('one-two').first
|
580
|
-
token.type.
|
581
|
-
token.value.
|
607
|
+
expect(token.type).to eq(:NAME)
|
608
|
+
expect(token.value).to eq('one-two')
|
582
609
|
end
|
583
610
|
|
584
611
|
it 'should match lowercase alphanumeric terms sep by ::' do
|
585
612
|
token = @lexer.tokenise('one::two').first
|
586
|
-
token.type.
|
587
|
-
token.value.
|
613
|
+
expect(token.type).to eq(:NAME)
|
614
|
+
expect(token.value).to eq('one::two')
|
588
615
|
end
|
589
616
|
|
590
617
|
it 'should match many lowercase alphanumeric terms sep by ::' do
|
591
618
|
token = @lexer.tokenise('one::two::three::four::five').first
|
592
|
-
token.type.
|
593
|
-
token.value.
|
619
|
+
expect(token.type).to eq(:NAME)
|
620
|
+
expect(token.value).to eq('one::two::three::four::five')
|
594
621
|
end
|
595
622
|
|
596
623
|
it 'should match lowercase alphanumeric terms prefixed by ::' do
|
597
624
|
token = @lexer.tokenise('::1one::2two::3three').first
|
598
|
-
token.type.
|
599
|
-
token.value.
|
625
|
+
expect(token.type).to eq(:NAME)
|
626
|
+
expect(token.value).to eq('::1one::2two::3three')
|
600
627
|
end
|
601
628
|
end
|
602
629
|
|
603
630
|
context ':NUMBER' do
|
604
631
|
it 'should match numeric terms' do
|
605
632
|
token = @lexer.tokenise('1234567890').first
|
606
|
-
token.type.
|
607
|
-
token.value.
|
633
|
+
expect(token.type).to eq(:NUMBER)
|
634
|
+
expect(token.value).to eq('1234567890')
|
608
635
|
end
|
609
636
|
|
610
637
|
it 'should match float terms' do
|
611
638
|
token = @lexer.tokenise('12345.6789').first
|
612
|
-
token.type.
|
613
|
-
token.value.
|
639
|
+
expect(token.type).to eq(:NUMBER)
|
640
|
+
expect(token.value).to eq('12345.6789')
|
614
641
|
end
|
615
642
|
|
616
643
|
it 'should match hexadecimal terms' do
|
617
644
|
token = @lexer.tokenise('0xCAFE1029').first
|
618
|
-
token.type.
|
619
|
-
token.value.
|
645
|
+
expect(token.type).to eq(:NUMBER)
|
646
|
+
expect(token.value).to eq('0xCAFE1029')
|
620
647
|
end
|
621
648
|
|
622
649
|
it 'should match float with exponent terms' do
|
623
650
|
token = @lexer.tokenise('10e23').first
|
624
|
-
token.type.
|
625
|
-
token.value.
|
651
|
+
expect(token.type).to eq(:NUMBER)
|
652
|
+
expect(token.value).to eq('10e23')
|
626
653
|
end
|
627
654
|
|
628
655
|
it 'should match float with negative exponent terms' do
|
629
656
|
token = @lexer.tokenise('10e-23').first
|
630
|
-
token.type.
|
631
|
-
token.value.
|
657
|
+
expect(token.type).to eq(:NUMBER)
|
658
|
+
expect(token.value).to eq('10e-23')
|
632
659
|
end
|
633
660
|
|
634
661
|
it 'should match float with exponent terms' do
|
635
662
|
token = @lexer.tokenise('1.234e5').first
|
636
|
-
token.type.
|
637
|
-
token.value.
|
663
|
+
expect(token.type).to eq(:NUMBER)
|
664
|
+
expect(token.value).to eq('1.234e5')
|
638
665
|
end
|
639
666
|
end
|
640
667
|
|
641
668
|
context ':COMMENT' do
|
642
669
|
it 'should match everything on a line after #' do
|
643
670
|
token = @lexer.tokenise('foo # bar baz')[2]
|
644
|
-
token.type.
|
645
|
-
token.value.
|
671
|
+
expect(token.type).to eq(:COMMENT)
|
672
|
+
expect(token.value).to eq(' bar baz')
|
646
673
|
end
|
647
674
|
end
|
648
675
|
|
649
676
|
context ':MLCOMMENT' do
|
650
677
|
it 'should match comments on a single line' do
|
651
678
|
token = @lexer.tokenise('/* foo bar */').first
|
652
|
-
token.type.
|
653
|
-
token.value.
|
679
|
+
expect(token.type).to eq(:MLCOMMENT)
|
680
|
+
expect(token.value).to eq('foo bar')
|
654
681
|
end
|
655
682
|
|
656
683
|
it 'should match comments on multiple lines' do
|
657
684
|
token = @lexer.tokenise("/* foo\n * bar\n*/").first
|
658
|
-
token.type.
|
659
|
-
token.value.
|
685
|
+
expect(token.type).to eq(:MLCOMMENT)
|
686
|
+
expect(token.value).to eq("foo\nbar")
|
660
687
|
end
|
661
688
|
end
|
662
689
|
|
663
690
|
context ':SLASH_COMMENT' do
|
664
691
|
it 'should match everyone on a line after //' do
|
665
692
|
token = @lexer.tokenise('foo // bar baz')[2]
|
666
|
-
token.type.
|
667
|
-
token.value.
|
693
|
+
expect(token.type).to eq(:SLASH_COMMENT)
|
694
|
+
expect(token.value).to eq(' bar baz')
|
668
695
|
end
|
669
696
|
end
|
670
697
|
|
671
698
|
context ':SSTRING' do
|
672
699
|
it 'should match a single quoted string' do
|
673
700
|
token = @lexer.tokenise("'single quoted string'").first
|
674
|
-
token.type.
|
675
|
-
token.value.
|
701
|
+
expect(token.type).to eq(:SSTRING)
|
702
|
+
expect(token.value).to eq('single quoted string')
|
676
703
|
end
|
677
704
|
|
678
705
|
it "should match a single quoted string with an escaped '" do
|
679
706
|
token = @lexer.tokenise(%q{'single quoted string with "\\'"'}).first
|
680
|
-
token.type.
|
681
|
-
token.value.
|
707
|
+
expect(token.type).to eq(:SSTRING)
|
708
|
+
expect(token.value).to eq('single quoted string with "\\\'"')
|
682
709
|
end
|
683
710
|
|
684
711
|
it "should match a single quoted string with an escaped $" do
|
685
712
|
token = @lexer.tokenise(%q{'single quoted string with "\$"'}).first
|
686
|
-
token.type.
|
687
|
-
token.value.
|
713
|
+
expect(token.type).to eq(:SSTRING)
|
714
|
+
expect(token.value).to eq('single quoted string with "\\$"')
|
688
715
|
end
|
689
716
|
|
690
717
|
it "should match a single quoted string with an escaped ." do
|
691
718
|
token = @lexer.tokenise(%q{'single quoted string with "\."'}).first
|
692
|
-
token.type.
|
693
|
-
token.value.
|
719
|
+
expect(token.type).to eq(:SSTRING)
|
720
|
+
expect(token.value).to eq('single quoted string with "\\."')
|
694
721
|
end
|
695
722
|
|
696
723
|
it "should match a single quoted string with an escaped \\n" do
|
697
724
|
token = @lexer.tokenise(%q{'single quoted string with "\n"'}).first
|
698
|
-
token.type.
|
699
|
-
token.value.
|
725
|
+
expect(token.type).to eq(:SSTRING)
|
726
|
+
expect(token.value).to eq('single quoted string with "\\n"')
|
700
727
|
end
|
701
728
|
|
702
729
|
it "should match a single quoted string with an escaped \\" do
|
703
730
|
token = @lexer.tokenise(%q{'single quoted string with "\\\\"'}).first
|
704
|
-
token.type.
|
705
|
-
token.value.
|
731
|
+
expect(token.type).to eq(:SSTRING)
|
732
|
+
expect(token.value).to eq('single quoted string with "\\\\"')
|
706
733
|
end
|
707
734
|
|
708
735
|
it "should match an empty string" do
|
709
736
|
token = @lexer.tokenise("''").first
|
710
|
-
token.type.
|
711
|
-
token.value.
|
737
|
+
expect(token.type).to eq(:SSTRING)
|
738
|
+
expect(token.value).to eq('')
|
712
739
|
end
|
713
740
|
|
714
741
|
it "should match an empty string ending with \\\\" do
|
715
742
|
token = @lexer.tokenise("'foo\\\\'").first
|
716
|
-
token.type.
|
717
|
-
token.value.
|
743
|
+
expect(token.type).to eq(:SSTRING)
|
744
|
+
expect(token.value).to eq(%{foo\\\\})
|
718
745
|
end
|
719
746
|
end
|
720
747
|
|
721
748
|
context ':REGEX' do
|
722
749
|
it 'should match anything enclosed in //' do
|
723
750
|
token = @lexer.tokenise('/this is a regex/').first
|
724
|
-
token.type.
|
725
|
-
token.value.
|
751
|
+
expect(token.type).to eq(:REGEX)
|
752
|
+
expect(token.value).to eq('this is a regex')
|
726
753
|
end
|
727
754
|
|
728
755
|
it 'should not match if there is \n in the regex' do
|
729
756
|
token = @lexer.tokenise("/this is \n a regex/").first
|
730
|
-
token.type.
|
757
|
+
expect(token.type).to_not eq(:REGEX)
|
731
758
|
end
|
732
759
|
|
733
760
|
it 'should not consider \/ to be the end of the regex' do
|
734
761
|
token = @lexer.tokenise('/this is \/ a regex/').first
|
735
|
-
token.type.
|
736
|
-
token.value.
|
762
|
+
expect(token.type).to eq(:REGEX)
|
763
|
+
expect(token.value).to eq('this is \\/ a regex')
|
737
764
|
end
|
738
765
|
|
739
766
|
it 'should not match chained division' do
|
740
767
|
tokens = @lexer.tokenise('$x = $a/$b/$c')
|
741
|
-
tokens.select { |r| r.type == :REGEX }.
|
768
|
+
expect(tokens.select { |r| r.type == :REGEX }).to be_empty
|
742
769
|
end
|
743
770
|
end
|
744
771
|
|
@@ -746,7 +773,7 @@ describe PuppetLint::Lexer do
|
|
746
773
|
it 'should parse strings with \\\\\\' do
|
747
774
|
expect {
|
748
775
|
@lexer.tokenise("exec { \"/bin/echo \\\\\\\"${environment}\\\\\\\"\": }")
|
749
|
-
}.to_not raise_error
|
776
|
+
}.to_not raise_error
|
750
777
|
end
|
751
778
|
end
|
752
779
|
end
|