Cond.t 909B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Test::More;
  5. use lib 'lib';
  6. use helper;
  7. BEGIN { use_ok( 'SugarTrail::Template::Condition' ); }
  8. require_ok( 'SugarTrail::Template::Condition' );
  9. my $params = { os => "wxx", proto => "imap" };
  10. my $c;
  11. my $test;
  12. $test = "normal condition:";
  13. $c = SugarTrail::Template::Condition->new('proto==imap');
  14. ok($c, "$test: c is true");
  15. ok($c->match($params), "$test: params match");
  16. my @badsyn = ("", "==", "pop imap", "==imap", "pop==");
  17. for my $bad (@badsyn) {
  18. $test = "syntax: '$bad' ";
  19. $c = SugarTrail::Template::Condition->new($bad);
  20. ok($c, "$test: c true (late parsing)");
  21. ok(!($c->{error}), "$test: c has no error before match attempt");
  22. ok(!($c->match($params)), "$test: c does not match");
  23. ok($c->{error}, "$test: c has error after match attempt");
  24. like($c->{error}, qr/^syntax error\W/, "$test: error content");
  25. }
  26. done_testing();