Skip to content

Commit

Permalink
Add = as Operator in Puppet lexer
Browse files Browse the repository at this point in the history
The = sign had been missed apparently as a valid Puppet operator. Also
adds tests. Fixes rouge-ruby#979.
  • Loading branch information
alex-harvey-z3q committed Sep 4, 2018
1 parent 27a4bfb commit f0f5488
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rouge/lexers/puppet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def self.metaparameters
rule /(in|and|or)\b/, Operator::Word
rule /[=!<>]=/, Operator
rule /[=!]~/, Operator, :regex_allowed
rule %r([<>!+*/-]), Operator
rule %r([=<>!+*/-]), Operator

rule /(class|include)(\s*)(#{qualname})/ do
groups Keyword, Text, Name::Class
Expand Down
49 changes: 49 additions & 0 deletions spec/lexers/puppet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,55 @@
describe Rouge::Lexers::Puppet do
let(:subject) { Rouge::Lexers::Puppet.new }

describe 'lexing' do
include Support::Lexing

describe 'assignment' do
describe 'equals' do
it 'can assign a simple string' do
assert_tokens_equal "$foo = 'bar'",
['Name.Variable', '$foo'],
['Text', ' '],
['Operator', '='],
['Text', ' '],
['Literal.String.Single', "'bar'"]
end

it 'can assign an array' do
assert_tokens_equal "$foo = [\n 'bar',\n 'baz',\n ]",
['Name.Variable', '$foo'],
['Text', ' '],
['Operator', '='],
['Text', ' '],
['Punctuation', '['],
['Text', "\n "],
['Literal.String.Single', "'bar'"],
['Punctuation', ','],
['Text', "\n "],
['Literal.String.Single', "'baz'"],
['Punctuation', ','],
['Text', "\n "],
['Punctuation', ']']
end

it 'can assign a class variable Puppet 4 style' do
assert_tokens_equal "Array[String] $foo = $bar::baz::qux,",
['Name.Class', 'Array'], # Array[String] obviously is
['Punctuation', '['], # not really a Name.Class[Name.Class]!
['Name.Class', 'String'], # Puppet 4 Syntax highlighting seems
['Punctuation', ']'], # look okay by accident here.
['Text', ' '], #
['Name.Variable', '$foo'],
['Text', ' '],
['Operator', '='],
['Text', ' '],
['Name.Variable', '$bar::baz::qux'],
['Punctuation', ',']
end
end
end
end

describe 'guessing' do
include Support::Guessing

Expand Down

0 comments on commit f0f5488

Please sign in to comment.