From 1b8b76529aaa67e5517fdb2a7f2902904a75863d Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Fri, 23 Nov 2012 20:53:05 +0000 Subject: Updated test-cases to cover different parsing routes. --- t/test-custodian-parser.rb | 84 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 6 deletions(-) (limited to 't/test-custodian-parser.rb') diff --git a/t/test-custodian-parser.rb b/t/test-custodian-parser.rb index 8fe794e..4387d13 100755 --- a/t/test-custodian-parser.rb +++ b/t/test-custodian-parser.rb @@ -12,12 +12,18 @@ require 'custodian/parser' # class TestCustodianParser < Test::Unit::TestCase + + + # # Create the test suite environment: NOP. # def setup end + + + # # Destroy the test suite environment: NOP. # @@ -27,8 +33,6 @@ class TestCustodianParser < Test::Unit::TestCase - - # # Test we can create a new parser object - specifically # that it throws exceptions if it is not given a filename @@ -46,6 +50,72 @@ class TestCustodianParser < Test::Unit::TestCase + # + # Test the different kinds of parsing: + # + # 1. By string - single line. + # 2. By array - with multiple lines. + # 3. By lines - with newlines. + # + def test_parsing_api + + # + # 1. By string. + # + parser = Custodian::Parser.new() + + # 1.a. Comment lines return nil. + result = parser.parse_line( "# this is a comment" ) + assert( result.nil? ) + + # 1.b. Adding a test will return an array of test-objects. + result = parser.parse_line( "smtp.bytemark.co.uk must run smtp on 25 otherwise 'failure'." ); + assert( !result.nil? ) + assert( result.kind_of? Array ) + assert( result.size == 1 ) + + + # + # 2. By array. + # + parser = Custodian::Parser.new() + # 2.a. Comment lines return nil. + tmp = Array.new() + tmp.push( "# This is a comment.." ) + assert( parser.parse_lines( tmp ).nil? ) + + # 2.b. Adding a test will return an array of test-objects. + tmp = Array.new() + tmp.push( "smtp.bytemark.co.uk must run ssh on 22 otherwise 'oops'." ); + ret = parser.parse_lines( tmp ) + assert( ret.kind_of? Array ); + assert( ret.size == 1 ) + + # + # 3. By lines + # + parser = Custodian::Parser.new() + # 3.a. Comment lines return nil. + str =<