summaryrefslogtreecommitdiffstats
path: root/test/parser
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-04-04 23:30:56 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-04-04 23:30:56 +0000
commit8db837ad7663c611f1fe92189e36158404a452cc (patch)
tree4353df4b7c670128d15be578b4ac8f63da57db86 /test/parser
parentd4a5b480f2451041109d867052db2285990d01a6 (diff)
getting rid of the parser tree, and moving everything into the language dir
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1070 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/parser')
-rw-r--r--test/parser/lexer.rb128
-rw-r--r--test/parser/node.rb84
-rw-r--r--test/parser/parser.rb212
3 files changed, 0 insertions, 424 deletions
diff --git a/test/parser/lexer.rb b/test/parser/lexer.rb
deleted file mode 100644
index 083342cc7..000000000
--- a/test/parser/lexer.rb
+++ /dev/null
@@ -1,128 +0,0 @@
-if __FILE__ == $0
- $:.unshift '../../lib'
- $:.unshift '..'
- $puppetbase = "../.."
-end
-
-require 'puppet'
-require 'puppet/parser/lexer'
-require 'test/unit'
-require 'puppettest.rb'
-
-#%q{service("telnet") = \{
-# port => "23",
-# protocol => "tcp",
-# name => "telnet",
-#\}
-#} => [[:NAME, "service"], [:LPAREN, "("], [:DQUOTE, "\""], [:NAME, "telnet"], [:DQUOTE, "\""], [:RPAREN, ")"], [:EQUALS, "="], [:lbrace, "{"], [:NAME, "port"], [:FARROW, "=>"], [:DQUOTE, "\""], [:NAME, "23"], [:DQUOTE, "\""], [:COMMA, ","], [:NAME, "protocol"], [:FARROW, "=>"], [:DQUOTE, "\""], [:NAME, "tcp"], [:DQUOTE, "\""], [:COMMA, ","], [:NAME, "name"], [:FARROW, "=>"], [:DQUOTE, "\""], [:NAME, "telnet"], [:DQUOTE, "\""], [:COMMA, ","], [:RBRACE, "}"]]
-
-class TestLexer < Test::Unit::TestCase
- include TestPuppet
- def setup
- super
- @lexer = Puppet::Parser::Lexer.new()
- end
-
- def test_simple_lex
- strings = {
-%q{\\} => [[:BACKSLASH,"\\"],[false,false]],
-%q{simplest scanner test} => [[:NAME,"simplest"],[:NAME,"scanner"],[:NAME,"test"],[false,false]],
-%q{returned scanner test
-} => [[:NAME,"returned"],[:NAME,"scanner"],[:NAME,"test"],[false,false]]
- }
- strings.each { |str,ary|
- @lexer.string = str
- assert_equal(
- ary,
- @lexer.fullscan()
- )
- }
- end
-
- def test_quoted_strings
- strings = {
-%q{a simple "scanner" test
-} => [[:NAME,"a"],[:NAME,"simple"],[:DQTEXT,"scanner"],[:NAME,"test"],[false,false]],
-%q{a simple 'single quote scanner' test
-} => [[:NAME,"a"],[:NAME,"simple"],[:SQTEXT,"single quote scanner"],[:NAME,"test"],[false,false]],
-%q{a harder 'a $b \c"'
-} => [[:NAME,"a"],[:NAME,"harder"],[:SQTEXT,'a $b \c"'],[false,false]],
-%q{a harder "scanner test"
-} => [[:NAME,"a"],[:NAME,"harder"],[:DQTEXT,"scanner test"],[false,false]],
-%q{a hardest "scanner \"test\""
-} => [[:NAME,"a"],[:NAME,"hardest"],[:DQTEXT,'scanner "test"'],[false,false]],
-%q{a hardestest "scanner \"test\"
-"
-} => [[:NAME,"a"],[:NAME,"hardestest"],[:DQTEXT,'scanner "test"
-'],[false,false]],
-%q{function("call")} => [[:NAME,"function"],[:LPAREN,"("],[:DQTEXT,'call'],[:RPAREN,")"],[false,false]]
-}
- strings.each { |str,array|
- @lexer.string = str
- assert_equal(
- array,
- @lexer.fullscan()
- )
- }
- end
-
- def test_errors
- strings = %w{
- ^
- @
- }
- strings.each { |str|
- @lexer.string = str
- assert_raise(RuntimeError) {
- @lexer.fullscan()
- }
- }
- end
-
- def test_more_error
- assert_raise(TypeError) {
- @lexer.fullscan()
- }
- end
-
- def test_files
- textfiles() { |file|
- @lexer.file = file
- assert_nothing_raised() {
- @lexer.fullscan()
- }
- Puppet::Type.allclear
- }
- end
-
- def test_strings
- names = %w{this is a bunch of names}
- types = %w{Many Different Words A Word}
- words = %w{differently Cased words A a}
-
- names.each { |t|
- @lexer.string = t
- assert_equal(
- [[:NAME,t],[false,false]],
- @lexer.fullscan
- )
- }
- types.each { |t|
- @lexer.string = t
- assert_equal(
- [[:TYPE,t],[false,false]],
- @lexer.fullscan
- )
- }
- end
-
- def test_emptystring
- bit = '$var = ""'
-
- assert_nothing_raised {
- @lexer.string = bit
- }
- end
-end
-
-# $Id$
diff --git a/test/parser/node.rb b/test/parser/node.rb
deleted file mode 100644
index 5013b190d..000000000
--- a/test/parser/node.rb
+++ /dev/null
@@ -1,84 +0,0 @@
-if __FILE__ == $0
- $:.unshift '../../lib'
- $:.unshift '..'
- $puppetbase = "../.."
-end
-
-require 'puppet'
-require 'puppet/parser/parser'
-require 'test/unit'
-require 'puppettest'
-
-class TestParser < Test::Unit::TestCase
- include ParserTesting
-
- def setup
- super
- Puppet[:parseonly] = true
- @parser = Puppet::Parser::Parser.new()
- end
-
- def test_simple_hostname
- check_parseable "host1"
- check_parseable "'host2'"
- check_parseable [ "'host1'", "host2" ]
- check_parseable [ "'host1'", "'host2'" ]
- end
-
- def test_qualified_hostname
- check_parseable "'host.example.com'"
- check_parseable [ "'host.example.com'", "host1" ]
- check_parseable "'host-1.37examples.example.com'"
- check_parseable "'svn.23.nu'"
- check_parseable "'HOST'"
- end
-
- def test_reject_hostname
- check_nonparseable "host.example.com"
- check_nonparseable "host@example.com"
- check_nonparseable "\"host\""
- check_nonparseable "'$foo.example.com'"
- check_nonparseable "'host1 host2'"
- check_nonparseable "HOST"
- end
-
- AST = Puppet::Parser::AST
-
- def check_parseable(hostnames)
- unless hostnames.is_a?(Array)
- hostnames = [ hostnames ]
- end
- assert_nothing_raised {
- @parser.string = "node #{hostnames.join(" ")} { }"
- }
- # Strip quotes
- hostnames.map! { |s| s.sub(/^'(.*)'$/, "\\1") }
- ast = nil
- assert_nothing_raised {
- ast = @parser.parse
- }
- # Verify that the AST has the expected structure
- # and that the leaves have the right hostnames in them
- assert_kind_of(AST::ASTArray, ast)
- assert_equal(1, ast.children.size)
- nodedef = ast.children[0]
- assert_kind_of(AST::NodeDef, nodedef)
- assert_kind_of(AST::ASTArray, nodedef.names)
- assert_equal(hostnames.size, nodedef.names.children.size)
- hostnames.size.times do |i|
- hostnode = nodedef.names.children[i]
- assert_kind_of(AST::HostName, hostnode)
- assert_equal(hostnames[i], hostnode.value)
- end
- end
-
- def check_nonparseable(hostname)
- assert_nothing_raised {
- @parser.string = "node #{hostname} { }"
- }
-
- assert_raise(Puppet::DevError, Puppet::ParseError) {
- @parser.parse
- }
- end
-end
diff --git a/test/parser/parser.rb b/test/parser/parser.rb
deleted file mode 100644
index a9b2631f1..000000000
--- a/test/parser/parser.rb
+++ /dev/null
@@ -1,212 +0,0 @@
-if __FILE__ == $0
- $:.unshift '../../lib'
- $:.unshift '..'
- $puppetbase = "../.."
-end
-
-require 'puppet'
-require 'puppet/parser/parser'
-require 'test/unit'
-require 'puppettest'
-
-class TestParser < Test::Unit::TestCase
- include ParserTesting
- def setup
- super
- Puppet[:parseonly] = true
- #@lexer = Puppet::Parser::Lexer.new()
- @parser = Puppet::Parser::Parser.new()
- end
-
- def test_each_file
- textfiles { |file|
- Puppet.debug("parsing %s" % file) if __FILE__ == $0
- assert_nothing_raised() {
- @parser.file = file
- @parser.parse
- }
-
- Puppet::Type.eachtype { |type|
- type.each { |obj|
- assert(obj.file)
- assert(obj.name)
- assert(obj.line)
- }
- }
- Puppet::Type.allclear
- }
- end
-
- def test_failers
- failers { |file|
- Puppet.debug("parsing failer %s" % file) if __FILE__ == $0
- assert_raise(Puppet::ParseError) {
- @parser.file = file
- ast = @parser.parse
- Puppet::Parser::Scope.new.evaluate(:ast => ast)
- }
- Puppet::Type.allclear
- }
- end
-
- def test_arrayrvalues
- parser = Puppet::Parser::Parser.new()
- ret = nil
- file = tempfile()
- assert_nothing_raised {
- parser.string = "file { \"#{file}\": mode => [755, 640] }"
- }
-
- assert_nothing_raised {
- ret = parser.parse
- }
- end
-
- def mkmanifest(file)
- name = File.join(tmpdir, "file%s" % rand(100))
- @@tmpfiles << name
-
- File.open(file, "w") { |f|
- f.puts "file { \"%s\": ensure => file, mode => 755 }\n" %
- name
- }
- end
-
- def test_importglobbing
- basedir = File.join(tmpdir(), "importesting")
- @@tmpfiles << basedir
- Dir.mkdir(basedir)
-
- subdir = "subdir"
- Dir.mkdir(File.join(basedir, subdir))
- manifest = File.join(basedir, "manifest")
- File.open(manifest, "w") { |f|
- f.puts "import \"%s/*\"" % subdir
- }
-
- 4.times { |i|
- path = File.join(basedir, subdir, "subfile%s" % i)
- mkmanifest(path)
- }
-
- assert_nothing_raised("Could not parse multiple files") {
- parser = Puppet::Parser::Parser.new()
- parser.file = manifest
- parser.parse
- }
- end
-
- def test_nonexistent_import
- basedir = File.join(tmpdir(), "importesting")
- @@tmpfiles << basedir
- Dir.mkdir(basedir)
- manifest = File.join(basedir, "manifest")
- File.open(manifest, "w") do |f|
- f.puts "import \" no such file \""
- end
- assert_raise(Puppet::ParseError) {
- parser = Puppet::Parser::Parser.new()
- parser.file = manifest
- parser.parse
- }
- end
-
- def test_defaults
- basedir = File.join(tmpdir(), "defaulttesting")
- @@tmpfiles << basedir
- Dir.mkdir(basedir)
-
- defs1 = {
- "testing" => "value"
- }
-
- defs2 = {
- "one" => "two",
- "three" => "four",
- "five" => false,
- "seven" => "eight",
- "nine" => true,
- "eleven" => "twelve"
- }
-
- mkdef = proc { |hash|
- hash.collect { |arg, value|
- "%s = %s" % [arg, value]
- }.join(", ")
- }
- manifest = File.join(basedir, "manifest")
- File.open(manifest, "w") { |f|
- f.puts "
- define method(#{mkdef.call(defs1)}, other) {
- $variable = $testing
- }
-
- define othermethod(#{mkdef.call(defs2)}, goodness) {
- $more = less
- }
-
- method {
- other => yayness
- }
-
- othermethod {
- goodness => rahness
- }
-"
- }
-
- ast = nil
- assert_nothing_raised("Could not parse multiple files") {
- parser = Puppet::Parser::Parser.new()
- parser.file = manifest
- ast = parser.parse
- }
-
- assert(ast, "Did not receive AST while parsing defaults")
-
- scope = nil
- assert_nothing_raised("Could not evaluate defaults parse tree") {
- scope = Puppet::Parser::Scope.new()
- scope.name = "parsetest"
- scope.type = "parsetest"
- objects = scope.evaluate(:ast => ast)
- }
-
- method = nil
- othermethod = nil
- assert_nothing_raised {
- method = scope.find { |child|
- child.is_a?(Puppet::Parser::Scope) and child.type == "method"
- }
- defs1.each { |var, value|
- curval = method.lookupvar(var)
- assert_equal(value, curval, "Did not get default")
- }
- }
-
- assert_nothing_raised {
- method = scope.find { |child|
- child.is_a?(Puppet::Parser::Scope) and child.type == "othermethod"
- }
- defs2.each { |var, value|
- curval = method.lookupvar(var)
- assert_equal(value, curval, "Did not get default")
- }
- }
- end
-
- def test_trailingcomma
- path = tempfile()
- str = %{file { "#{path}": ensure => file, }
- }
-
- parser = Puppet::Parser::Parser.new
- parser.string = str
-
- assert_nothing_raised("Could not parse trailing comma") {
- parser.parse
- }
- end
-end
-
-# $Id$