From f0f54888519d120cab2a0d0f8ae8a89252bceebd Mon Sep 17 00:00:00 2001 From: Alex Harvey Date: Tue, 4 Sep 2018 19:52:03 +1000 Subject: [PATCH 1/2] Add = as Operator in Puppet lexer The = sign had been missed apparently as a valid Puppet operator. Also adds tests. Fixes #979. --- lib/rouge/lexers/puppet.rb | 2 +- spec/lexers/puppet_spec.rb | 49 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/rouge/lexers/puppet.rb b/lib/rouge/lexers/puppet.rb index eabdbc3d12..3d2cb628b6 100644 --- a/lib/rouge/lexers/puppet.rb +++ b/lib/rouge/lexers/puppet.rb @@ -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 diff --git a/spec/lexers/puppet_spec.rb b/spec/lexers/puppet_spec.rb index a36474aa0c..c4fc7db47c 100644 --- a/spec/lexers/puppet_spec.rb +++ b/spec/lexers/puppet_spec.rb @@ -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 From e1ad61a48e59d810a810c747ae8ba1e0967ac855 Mon Sep 17 00:00:00 2001 From: Alex Harvey Date: Wed, 5 Sep 2018 09:31:39 +1000 Subject: [PATCH 2/2] Remove Puppet Rspec tests and add visual samples Based on discussion on the PR, it is agreed to add sample code in spec/visual/samples/puppet and not have the Rspec tests that I added. --- spec/lexers/puppet_spec.rb | 49 -------------------------------------- spec/visual/samples/puppet | 9 +++++++ 2 files changed, 9 insertions(+), 49 deletions(-) diff --git a/spec/lexers/puppet_spec.rb b/spec/lexers/puppet_spec.rb index c4fc7db47c..a36474aa0c 100644 --- a/spec/lexers/puppet_spec.rb +++ b/spec/lexers/puppet_spec.rb @@ -3,55 +3,6 @@ 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 diff --git a/spec/visual/samples/puppet b/spec/visual/samples/puppet index e9451f7220..48e720f185 100644 --- a/spec/visual/samples/puppet +++ b/spec/visual/samples/puppet @@ -10,3 +10,12 @@ node /www\.example\.com/ { } } } + +class foo::bar ( + Array[String] = foo::bar::baz, +) { + $foo = [ + 'bar', + 'baz', + ] +}