summaryrefslogtreecommitdiff
path: root/t/test-custodian-parser.rb
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2012-11-23 10:11:48 +0000
committerSteve Kemp <steve@steve.org.uk>2012-11-23 10:11:48 +0000
commit669e0fa3c0d1570ca4d212bd27ead2fa3b424eec (patch)
treeeced6ec5071646d9223dddffffeee9f8b6dea88d /t/test-custodian-parser.rb
parentbfe7d82ce0f9a864c53c53697992553f444c614d (diff)
Removed the old test cases and added new ones.:wq
Diffstat (limited to 't/test-custodian-parser.rb')
-rwxr-xr-xt/test-custodian-parser.rb141
1 files changed, 141 insertions, 0 deletions
diff --git a/t/test-custodian-parser.rb b/t/test-custodian-parser.rb
new file mode 100755
index 0000000..8fe794e
--- /dev/null
+++ b/t/test-custodian-parser.rb
@@ -0,0 +1,141 @@
+#!/usr/bin/ruby1.8 -I./lib/ -I../lib/
+
+
+require 'test/unit'
+require 'custodian/parser'
+
+
+
+
+#
+# Unit test for our parser.
+#
+class TestCustodianParser < Test::Unit::TestCase
+
+ #
+ # Create the test suite environment: NOP.
+ #
+ def setup
+ end
+
+ #
+ # Destroy the test suite environment: NOP.
+ #
+ def teardown
+ end
+
+
+
+
+
+
+ #
+ # Test we can create a new parser object - specifically
+ # that it throws exceptions if it is not given a filename
+ # that exists.
+ #
+ def test_init
+
+ #
+ # Constructor
+ #
+ assert_nothing_raised do
+ Custodian::Parser.new()
+ end
+ end
+
+
+
+ #
+ # Test that we can define macros.
+ #
+ def test_macros_lines
+
+ parser = Custodian::Parser.new()
+
+ #
+ # Input text
+ #
+ text =<<EOF
+FOO is kvm1.vm.bytemark.co.uk.
+TEST is kvm2.vm.bytemark.co.uk.
+EOF
+
+ #
+ # Test the parser with this text
+ #
+ parser.parse_lines( text )
+
+
+ #
+ # We should now have two macros.
+ #
+ macros = parser.macros
+ assert( ! macros.empty? )
+ assert( macros.size() == 2 )
+ end
+
+
+
+ #
+ # Test that we can define macros.
+ #
+ def test_macros_array
+
+ parser = Custodian::Parser.new()
+
+ #
+ # Input text
+ #
+ text = Array.new()
+ text.push( "FOO is kvm1.vm.bytemark.co.uk." );
+ text.push( "FOO2 is kvm2.vm.bytemark.co.uk." );
+
+ #
+ # Test the parser with this text
+ #
+ parser.parse_lines( text )
+
+
+ #
+ # We should now have two macros.
+ #
+ macros = parser.macros
+ assert( ! macros.empty? )
+ assert( macros.size() == 2 )
+ end
+
+
+
+ #
+ # Duplicate macros are a bug
+ #
+ def test_duplicate_macros
+
+ parser = Custodian::Parser.new()
+
+ #
+ # Input text
+ #
+ text = Array.new()
+ text.push( "FOO is kvm1.vm.bytemark.co.uk." );
+ text.push( "FOO is kvm2.vm.bytemark.co.uk." );
+
+ #
+ # Test the parser with this text
+ #
+ assert_raise ArgumentError do
+ parser.parse_lines( text )
+ end
+
+
+ #
+ # We should now have one macros.
+ #
+ macros = parser.macros
+ assert( ! macros.empty? )
+ assert( macros.size() == 1 )
+ end
+
+
+end