diff options
| author | Steve Kemp <steve@steve.org.uk> | 2012-11-23 20:53:05 +0000 | 
|---|---|---|
| committer | Steve Kemp <steve@steve.org.uk> | 2012-11-23 20:53:05 +0000 | 
| commit | 912bf63dcc21b6313d92839a7bcf4fc5ca6b3333 (patch) | |
| tree | 077a497f50bb0a6b92d7753bfe26cd83257d8bf9 /t | |
| parent | 46ef84aed94360083e4f6bf7a38c1408f13d091a (diff) | |
  Updated test-cases to cover different parsing routes.
Diffstat (limited to 't')
| -rwxr-xr-x | t/test-custodian-parser.rb | 84 | 
1 files changed, 78 insertions, 6 deletions
| 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 @@ -47,6 +51,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 =<<EOF +# This is a comment +# This is also a fine comment +EOF +    assert( parser.parse_lines( str ).nil? ) + +    #  3.b.  Adding a test will return an array of test-objects. +    str = <<EOF +smtp.bytemark.co.uk must run smtp on 25. +google.com must run ping otherwise 'internet broken?'. +EOF +    ret = parser.parse_lines( str ) +    assert( ret.kind_of? Array ); +    assert( ret.size == 1 ) + +  end + + + + +  #    #  Test that we can define macros.    #    def test_macros_lines @@ -77,6 +147,7 @@ EOF +    #    #  Test that we can define macros.    # @@ -107,6 +178,7 @@ EOF +    #    # Duplicate macros are a bug    # @@ -115,11 +187,11 @@ EOF      parser = Custodian::Parser.new()      # -    #  Input text +    #  Input text to parse.      #      text = Array.new() -    text.push( "FOO  is  kvm1.vm.bytemark.co.uk." ); -    text.push( "FOO is  kvm2.vm.bytemark.co.uk." ); +    text.push( "FOO is kvm1.vm.bytemark.co.uk." ); +    text.push( "FOO is kvm2.vm.bytemark.co.uk." );      #      # Test the parser with this text @@ -130,7 +202,7 @@ EOF      # -    #  We should now have one macros. +    #  We should now have one macro.      #      macros = parser.macros      assert( ! macros.empty? ) | 
