Skip to content

Commit

Permalink
Merge pull request #570 from ninech/multi_line_strings
Browse files Browse the repository at this point in the history
Multi line strings
  • Loading branch information
rodjek authored Dec 5, 2016
2 parents 6b11df4 + f7352a3 commit 041b430
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/puppet-lint/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ def new_token(type, value, length, opts = {})
@line_no += 1
@column = 1
end
if type == :SSTRING and /(?:\r\n|\r|\n)/.match(value)
lines = value.split(/(?:\r\n|\r|\n)/)
@line_no += lines.length-1
@column = lines.last.length
end

token
end
Expand Down
5 changes: 3 additions & 2 deletions spec/puppet-lint/lexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
end

it 'should calculate the line number for a multi line string' do
@lexer.instance_variable_set('@line_no', 2)
token = @lexer.new_token(:SSTRING, "test\ntest", 9)
token = @lexer.new_token(:TEST, 'test', 4)
expect(token.line).to eq(2)
end
Expand All @@ -37,8 +37,9 @@
it 'should calculate the column number for a multi line string' do
@lexer.instance_variable_set('@line_no', 4)
@lexer.instance_variable_set('@column', "gronk".size)
token = @lexer.new_token(:SSTRING, "test\ntest", 9)
token = @lexer.new_token(:TEST, 'test', 4)
expect(token.column).to eq(5)
expect(token.column).to eq(4)
end
end

Expand Down

0 comments on commit 041b430

Please sign in to comment.