summaryrefslogtreecommitdiffstats
path: root/test/parser
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-08-23 16:09:14 +0000
committerLuke Kanies <luke@madstop.com>2005-08-23 16:09:14 +0000
commit6029ef7812765775306ff8394005c326e359d886 (patch)
tree32cbe5ea68e0e9fbdc0935d0b41e58fdfcba9e3d /test/parser
parente87eb58ce8dc40ba8c66233bf17cea61094e7647 (diff)
downloadpuppet-6029ef7812765775306ff8394005c326e359d886.tar.gz
puppet-6029ef7812765775306ff8394005c326e359d886.tar.xz
puppet-6029ef7812765775306ff8394005c326e359d886.zip
Moving all files into a consolidated trunk. All tests pass except the known-failing certificate test, but there appear to be some errors that are incorrectly not resulting in failurs. I will track those down ASAP.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@576 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/parser')
-rw-r--r--test/parser/tc_lexer.rb112
-rw-r--r--test/parser/tc_parser.rb55
2 files changed, 167 insertions, 0 deletions
diff --git a/test/parser/tc_lexer.rb b/test/parser/tc_lexer.rb
new file mode 100644
index 000000000..b8fd3e23b
--- /dev/null
+++ b/test/parser/tc_lexer.rb
@@ -0,0 +1,112 @@
+if __FILE__ == $0
+ $:.unshift '../../lib'
+ $:.unshift '../../../../library/trunk/lib/'
+ $:.unshift '../../../../library/trunk/test/'
+ $puppetbase = "../.."
+end
+
+require 'puppet'
+require 'puppet/parser/lexer'
+require 'test/unit'
+require 'puppettest.rb'
+
+# $Id$
+
+#%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
+ def setup
+ Puppet[:loglevel] = :debug if __FILE__ == $0
+ @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"],[:QTEXT,"scanner"],[:NAME,"test"],[false,false]],
+%q{a harder "scanner test"
+} => [[:NAME,"a"],[:NAME,"harder"],[:QTEXT,"scanner test"],[false,false]],
+%q{a hardest "scanner \"test\""
+} => [[:NAME,"a"],[:NAME,"hardest"],[:QTEXT,'scanner "test"'],[false,false]],
+%q{function("call")} => [[:NAME,"function"],[:LPAREN,"("],[:QTEXT,'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
+end
diff --git a/test/parser/tc_parser.rb b/test/parser/tc_parser.rb
new file mode 100644
index 000000000..b88bd8116
--- /dev/null
+++ b/test/parser/tc_parser.rb
@@ -0,0 +1,55 @@
+if __FILE__ == $0
+ $:.unshift '../../lib'
+ $:.unshift '../../../../library/trunk/lib/'
+ $:.unshift '../../../../library/trunk/test/'
+ $puppetbase = "../.."
+end
+
+require 'puppet'
+require 'puppet/parser/parser'
+require 'test/unit'
+require 'puppettest'
+
+# $Id$
+
+class TestParser < Test::Unit::TestCase
+ # hmmm
+ # this is complicated, because we store references to the created
+ # objects in a central store
+ def setup
+ Puppet[:loglevel] = :debug if __FILE__ == $0
+ 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
+ @parser.parse
+ }
+ Puppet::Type.allclear
+ }
+ end
+end