~ubuntu-branches/ubuntu/trusty/puppet/trusty

« back to all changes in this revision

Viewing changes to spec/unit/parser/lexer_spec.rb

  • Committer: Package Import Robot
  • Author(s): Stig Sandbeck Mathisen
  • Date: 2011-10-22 14:08:22 UTC
  • mfrom: (1.1.25) (3.1.32 sid)
  • Revision ID: package-import@ubuntu.com-20111022140822-odxde5lohc45yhuz
Tags: 2.7.6-1
* New upstream release (CVE-2011-3872)
* Remove cherry-picked "groupadd_aix_warning" patch
* Install all new manpages

Show diffs side-by-side

added added

removed removed

Lines of Context:
230
230
  end
231
231
end
232
232
 
233
 
describe Puppet::Parser::Lexer::TOKENS[:CLASSNAME] do
234
 
  before { @token = Puppet::Parser::Lexer::TOKENS[:CLASSNAME] }
235
 
 
236
 
  it "should match against lower-case alpha-numeric terms separated by double colons" do
237
 
    @token.regex.should =~ "one::two"
238
 
  end
239
 
 
240
 
  it "should match against many lower-case alpha-numeric terms separated by double colons" do
241
 
    @token.regex.should =~ "one::two::three::four::five"
242
 
  end
243
 
 
244
 
  it "should match against lower-case alpha-numeric terms prefixed by double colons" do
245
 
    @token.regex.should =~ "::one"
246
 
  end
247
 
end
248
 
 
249
233
describe Puppet::Parser::Lexer::TOKENS[:CLASSREF] do
250
234
  before { @token = Puppet::Parser::Lexer::TOKENS[:CLASSREF] }
251
235
 
295
279
    Puppet::Parser::Lexer::KEYWORDS.expects(:lookup).returns(keyword)
296
280
    @token.convert(stub('lexer'), "false").should == [Puppet::Parser::Lexer::TOKENS[:BOOLEAN], false]
297
281
  end
 
282
 
 
283
  it "should match against lower-case alpha-numeric terms separated by double colons" do
 
284
    @token.regex.should =~ "one::two"
 
285
  end
 
286
 
 
287
  it "should match against many lower-case alpha-numeric terms separated by double colons" do
 
288
    @token.regex.should =~ "one::two::three::four::five"
 
289
  end
 
290
 
 
291
  it "should match against lower-case alpha-numeric terms prefixed by double colons" do
 
292
    @token.regex.should =~ "::one"
 
293
  end
 
294
 
 
295
  it "should match against nested terms starting with numbers" do
 
296
    @token.regex.should =~ "::1one::2two::3three"
 
297
  end
298
298
end
299
299
 
300
300
describe Puppet::Parser::Lexer::TOKENS[:NUMBER] do
445
445
    %q["foo$bar$"]                                                  => [[:DQPRE,"foo"],[:VARIABLE,"bar"],[:DQPOST,"$"]],
446
446
    %q["foo$$bar"]                                                  => [[:DQPRE,"foo$"],[:VARIABLE,"bar"],[:DQPOST,""]],
447
447
    %q[""]                                                          => [[:STRING,""]],
 
448
    %q["123 456 789 0"]                                             => [[:STRING,"123 456 789 0"]],
 
449
    %q["${123} 456 $0"]                                             => [[:DQPRE,""],[:VARIABLE,"123"],[:DQMID," 456 "],[:VARIABLE,"0"],[:DQPOST,""]],
 
450
    %q["$foo::::bar"]                                               => [[:DQPRE,""],[:VARIABLE,"foo"],[:DQPOST,"::::bar"]]
448
451
  }.each { |src,expected_result|
449
452
    it "should handle #{src} correctly" do
450
453
      tokens_scanned_from(src).should be_like(*expected_result)
660
663
  end
661
664
 
662
665
  it "should correctly lex variables" do
663
 
    ["$variable", "$::variable", "$qualified::variable", "$further::qualified::variable"].each do |string|
 
666
    ["$variable", "$::variable", "$qualified::variable", "$further::qualified::variable", "$hyphenated-variable", "$-variable-with-leading-dash"].each do |string|
664
667
      tokens_scanned_from(string).should be_like([:VARIABLE,string.sub(/^\$/,'')])
665
668
    end
666
669
  end
 
670
 
 
671
  it "should not include whitespace in a variable" do
 
672
    tokens_scanned_from("$foo bar").should_not be_like([:VARIABLE, "foo bar"])
 
673
  end
 
674
  it "should not include excess colons in a variable" do
 
675
    tokens_scanned_from("$foo::::bar").should_not be_like([:VARIABLE, "foo::::bar"])
 
676
  end
667
677
end
668
678
 
669
679
describe "Puppet::Parser::Lexer in the old tests when lexing example files" do