From b05726fc4ac9c472fe9ec2f25206a825e55914e1 Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Wed, 30 Dec 2009 04:44:27 +0100
Subject: [PATCH] Imap4flags extension: added tests to verify removeflag
 behavior.

---
 tests/extensions/imap4flags/basic.svtest | 140 ++++++++++++++++++++++-
 1 file changed, 134 insertions(+), 6 deletions(-)

diff --git a/tests/extensions/imap4flags/basic.svtest b/tests/extensions/imap4flags/basic.svtest
index 16682e220..ec94ca18f 100644
--- a/tests/extensions/imap4flags/basic.svtest
+++ b/tests/extensions/imap4flags/basic.svtest
@@ -84,25 +84,153 @@ test "Flag operations" {
 	}
 
 	if hasflag :comparator "i;ascii-numeric" :count "gt" "2" {
-                test_fail "hasflag sees more than two flags";
-        }
+		test_fail "hasflag sees more than two flags";
+	}
 
 	addflag ["C", "D", "E F"];	
 
 	if not hasflag :comparator "i;ascii-numeric" :count "eq" "6" {
-                test_fail "hasflag sees more than two flags";
-        }
+		test_fail "hasflag sees more than two flags";
+	}
 
 	removeflag ["D"];
 
 	if not hasflag :comparator "i;ascii-numeric" :count "eq" "5" {
-                test_fail "hasflag sees more than two flags";
-        }	
+		test_fail "hasflag sees more than two flags";
+	}	
 	
 	if hasflag "D" {
 		test_fail "removed flag still present";
 	}
 }
 
+test "Removal: one" {
+	setflag "\\seen";
+
+	if not hasflag "\\seen" {
+        test_fail "hasflag misses set flag";
+    }
+
+	removeflag "\\seen";
+
+	if hasflag "\\seen" { 
+		test_fail "flag not removed";
+	}
+
+	if not hasflag :comparator "i;ascii-numeric" :count "eq" "0" {
+		test_fail "flags are still set";
+    }
+}
+
+test "Removal: first" {
+	setflag "$frop \\seen";
+
+	if not allof ( hasflag "\\seen", hasflag "$frop" ) {
+        test_fail "hasflag misses set flags";
+    }
+
+	removeflag "$frop";
+
+	if not hasflag "\\seen" { 
+		test_fail "wrong flag removed";
+	}
+
+	if hasflag "$frop" { 
+		test_fail "flag not removed";
+	}	
+
+	if not hasflag :comparator "i;ascii-numeric" :count "eq" "1" {
+		test_fail "more than one flag remains set";
+    }
+}
+
+test "Removal: last" {
+    setflag "\\seen $friep";
+
+    if not allof ( hasflag "\\seen", hasflag "$friep" ) {
+        test_fail "hasflag misses set flags";
+    }
+
+    removeflag "$friep";
+
+    if not hasflag "\\seen" {
+        test_fail "wrong flag removed";
+    }
+
+    if hasflag "$friep" {
+        test_fail "flag not removed";
+    }
+
+    if not hasflag :comparator "i;ascii-numeric" :count "eq" "1" {
+        test_fail "more than one flag remains set";
+    }
+}
+
+test "Removal: middle" {
+    setflag "\\seen $friep \\flagged";
+
+    if not allof ( hasflag "\\flagged", hasflag "\\seen", hasflag "$friep" ) {
+        test_fail "hasflag misses set flags";
+    }
+
+    removeflag "$friep";
+
+    if not allof ( hasflag "\\seen", hasflag "\\flagged" ) {
+        test_fail "wrong flag removed";
+    }
+
+    if hasflag "$friep" {
+        test_fail "flag not removed";
+    }
+
+    if not hasflag :comparator "i;ascii-numeric" :count "eq" "2" {
+        test_fail "more than two flags remain set";
+    }
+}
+
+test "Removal: duplicates" {
+    setflag "\\seen $friep $friep \\flagged $friep";
+
+    if not allof ( hasflag "\\flagged", hasflag "\\seen", hasflag "$friep" ) {
+        test_fail "hasflag misses set flags";
+    }
+
+    removeflag "$friep";
+
+    if not allof ( hasflag "\\seen", hasflag "\\flagged" ) {
+        test_fail "wrong flag removed";
+    }
+
+    if hasflag "$friep" {
+        test_fail "flag not removed";
+    }
+
+    if not hasflag :comparator "i;ascii-numeric" :count "eq" "2" {
+        test_fail "more than two flags remain set";
+    }
+}
+
+test "Removal: whitespace" {
+    setflag "   \\seen     $friep      $friep   \\flagged    $friep   ";
+
+    if not allof ( hasflag "\\flagged", hasflag "\\seen", hasflag "$friep" ) {
+        test_fail "hasflag misses set flags";
+    }
+
+    removeflag "$friep";
+
+    if not allof ( hasflag "\\seen", hasflag "\\flagged" ) {
+        test_fail "wrong flag removed";
+    }
+
+    if hasflag "$friep" {
+        test_fail "flag not removed";
+    }
+
+    if not hasflag :comparator "i;ascii-numeric" :count "eq" "2" {
+        test_fail "more than two flags remain set";
+    }
+}
+
 
 
-- 
GitLab