diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-11-23 23:45:16 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-11-23 23:45:16 +0000 |
commit | 0e8216e6243341fee5981589a6cb37f9e4223fe8 (patch) | |
tree | 9021fe7eca0e23089e5aaad722eab4b1b1ffbe96 /t/test-custodian-parser.rb | |
parent | be4f7e138591e94b0546296d8337ba2190d78402 (diff) |
Test that macro-expansion works correctly
Diffstat (limited to 't/test-custodian-parser.rb')
-rwxr-xr-x | t/test-custodian-parser.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/t/test-custodian-parser.rb b/t/test-custodian-parser.rb index 4387d13..5017179 100755 --- a/t/test-custodian-parser.rb +++ b/t/test-custodian-parser.rb @@ -210,4 +210,54 @@ EOF end + + + # + # Test the expansion of macros. + # + def test_macro_expansion + + # + # Create a parser - validate it is free of macros. + # + parser = Custodian::Parser.new() + macros = parser.macros + assert( macros.empty? ) + + # + # Expand a line - which should result in no change + # as the line does not involve a known-macro + # + in_txt = "example.bytemark.co.uk must run smtp." + out_txt = parser.expand_macro( in_txt ) + + # + # The difference is the return value will be an array + # + assert( out_txt.kind_of? Array ) + assert( out_txt.size() == 1 ) + assert( out_txt[0] == in_txt ) + + + # + # Now define a macro + # + parser.parse_line( "TARGET is example1.bytemark.co.uk and example2.bytemark.co.uk." ) + macros = parser.macros + assert( !macros.empty? ) + + # + # Now we have a two-host macro, repeat the expansion + # + ret = parser.expand_macro( "TARGET must run smtp on 25." ) + + # + # The result should be an array + # + assert( ret.kind_of? Array ) + assert_equal( ret.size(), 2 ) + assert( ret[0] =~ /example1/) + assert( ret[1] =~ /example2/) + + end end |