summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2009-07-26 13:44:06 +0200
committerJames Turnbull <james@lovedthanlost.net>2009-08-01 11:15:28 +1000
commit0ccd2590b2bf0494388c4656759b47612776bc53 (patch)
tree75371d2b34bb055d8d06a235d33fefe0530dcbfa /spec/unit
parent201ae59eacaff289a8a5bb45f7d301c1a490a119 (diff)
downloadpuppet-0ccd2590b2bf0494388c4656759b47612776bc53.tar.gz
puppet-0ccd2590b2bf0494388c4656759b47612776bc53.tar.xz
puppet-0ccd2590b2bf0494388c4656759b47612776bc53.zip
Add regex, match and not match token to the lexer
The lexer recognizes regex delimited by / as in: /^$/ The match operator is defined by =~ The not match operator is defined by !~ Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/parser/lexer.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/spec/unit/parser/lexer.rb b/spec/unit/parser/lexer.rb
index 3c765d431..8b73de195 100755
--- a/spec/unit/parser/lexer.rb
+++ b/spec/unit/parser/lexer.rb
@@ -178,6 +178,8 @@ describe Puppet::Parser::Lexer::TOKENS do
:TIMES => '*',
:LSHIFT => '<<',
:RSHIFT => '>>',
+ :MATCH => '=~',
+ :NOMATCH => '!~',
}.each do |name, string|
it "should have a token named #{name.to_s}" do
Puppet::Parser::Lexer::TOKENS[name].should_not be_nil
@@ -451,6 +453,18 @@ describe Puppet::Parser::Lexer::TOKENS[:VARIABLE] do
end
end
+describe Puppet::Parser::Lexer::TOKENS[:REGEX] do
+ before { @token = Puppet::Parser::Lexer::TOKENS[:REGEX] }
+
+ it "should match against any expression enclosed in //" do
+ @token.regex.should =~ '/this is a regex/'
+ end
+
+ it "should return the REGEX token and a Regexp" do
+ @token.convert(stub("lexer"), "/myregex/").should == [Puppet::Parser::Lexer::TOKENS[:REGEX], Regexp.new(/myregex/)]
+ end
+end
+
describe Puppet::Parser::Lexer, "when lexing comments" do
before { @lexer = Puppet::Parser::Lexer.new }