Browse Source

Added tests for Condition error handling

Alois Mahdal 9 years ago
parent
commit
19f3530b6e
1 changed files with 19 additions and 4 deletions
  1. 19
    4
      t/Cond.t

+ 19
- 4
t/Cond.t View File

@@ -10,11 +10,26 @@ BEGIN { use_ok( 'SugarTrail::Template::Condition' ); }
10 10
 require_ok( 'SugarTrail::Template::Condition' );
11 11
 
12 12
 my $params = { os => "wxx", proto => "imap" };
13
+my $c;
14
+my $test;
13 15
 
14
-my $c = SugarTrail::Template::Condition->new('proto==imap');
15
-ok($c, "c is true");
16
-ok($c->match($params), "params match");
16
+$test = "normal condition:";
17
+$c = SugarTrail::Template::Condition->new('proto==imap');
18
+ok($c, "$test: c is true");
19
+ok($c->match($params), "$test: params match");
20
+
21
+
22
+my @badsyn = ("", "==", "pop imap", "==imap", "pop==");
23
+
24
+for my $bad (@badsyn) {
25
+    $test = "syntax: '$bad' ";
26
+    $c = SugarTrail::Template::Condition->new($bad);
27
+    ok($c, "$test: c true (late parsing)");
28
+    ok(!($c->{error}), "$test: c has no error before match attempt");
29
+    ok(!($c->match($params)), "$test: c does not match");
30
+    ok($c->{error}, "$test: c has error after match attempt");
31
+    like($c->{error}, qr/^syntax error\W/, "$test: error content");
32
+}
17 33
 
18
-&helper::dmupp(condition=>$c);
19 34
 
20 35
 done_testing();