[swiftsieve] [PATCH] Fix another case of implicit Condition::write() call and tests for it.

Vsevolod Kozlov zaba at thorium.homeunix.org
Tue Mar 10 16:56:59 UTC 2009


---
 lib/App/Swiftsieve/Sieve/Rule.pm |    2 +-
 t/sieve-rule.t                   |   16 ++++++++++++----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/lib/App/Swiftsieve/Sieve/Rule.pm b/lib/App/Swiftsieve/Sieve/Rule.pm
index b42d7a8..e38c043 100644
--- a/lib/App/Swiftsieve/Sieve/Rule.pm
+++ b/lib/App/Swiftsieve/Sieve/Rule.pm
@@ -149,7 +149,7 @@ sub write {
     }
 
     my $out = sprintf("if %s%s (\n    ", $self->inverted ? "not " : "", $self->condition_join);
-    $out .= join(",\n    ", $self->conditions);
+    $out .= join(",\n    ", map { $_->write() } $self->conditions);
 
     my $action = $self->action_command;
     if ($self->action_command ne 'keep' && $self->action_param) {
diff --git a/t/sieve-rule.t b/t/sieve-rule.t
index 25694f3..e8c0e36 100644
--- a/t/sieve-rule.t
+++ b/t/sieve-rule.t
@@ -18,6 +18,7 @@ use warnings;
 
 use Test::More tests => 20;
 use Test::Differences;
+use Test::MockObject;
 
 require_ok('App::Swiftsieve::Sieve::Rule');
 
@@ -51,10 +52,17 @@ is($cond[2]->haystack, 'size', 'haystack 2 parsed correctly');
 is($cond[2]->operator, 'over', 'operator 2 parsed correctly');
 is($cond[2]->needle, 666, 'needle 2 parsed correctly');
 
+sub mock_cond {
+    my $val = $_[0];
+    my $cond = Test::MockObject->new();
+    $cond->mock('write', sub { return "size :over $val" });
+    return $cond;
+}
+
 my $new_rule = new App::Swiftsieve::Sieve::Rule;
 $new_rule->condition_join('allof');
-$new_rule->add_cond('size :over 108');
-$new_rule->add_cond('size :over 666');
+$new_rule->add_cond(mock_cond(108));
+$new_rule->add_cond(mock_cond(666));
 $new_rule->action_command("fileinto");
 $new_rule->action_param("foo");
 
@@ -88,8 +96,8 @@ is($disabled_rule->action_command, 'fileinto', 'action command parsed correctly'
 my $new_disabled_rule = new App::Swiftsieve::Sieve::Rule;
 $new_disabled_rule->enabled(0);
 $new_disabled_rule->condition_join('allof');
-$new_disabled_rule->add_cond('size :over 108');
-$new_disabled_rule->add_cond('size :over 666');
+$new_disabled_rule->add_cond(mock_cond(108));
+$new_disabled_rule->add_cond(mock_cond(666));
 $new_disabled_rule->action_command("keep");
 
 my $disabled_should_be = <<END;
-- 
1.6.0.6




More information about the Swiftsieve-devel mailing list