diff options
Diffstat (limited to 'pigeonhole/tests/extensions/index')
-rw-r--r-- | pigeonhole/tests/extensions/index/basic.svtest | 93 | ||||
-rw-r--r-- | pigeonhole/tests/extensions/index/errors.svtest | 20 | ||||
-rw-r--r-- | pigeonhole/tests/extensions/index/errors/syntax.sieve | 26 |
3 files changed, 139 insertions, 0 deletions
diff --git a/pigeonhole/tests/extensions/index/basic.svtest b/pigeonhole/tests/extensions/index/basic.svtest new file mode 100644 index 0000000..0706022 --- /dev/null +++ b/pigeonhole/tests/extensions/index/basic.svtest @@ -0,0 +1,93 @@ +require "vnd.dovecot.testsuite"; +require "index"; +require "date"; +require "variables"; +require "subaddress"; + +test_set "message" text: +To: first@friep.example.com +X-A: First +Received: from mx.example.com (127.0.0.13) by mx.example.org + (127.0.0.12) with Macrosoft SMTP Server (TLS) id 1.2.3.4; + Wed, 12 Nov 2014 18:18:31 +0100 +To: second@friep.example.com +From: stephan@example.org +Received: from mx.example.com (127.0.0.13) by mx.example.org + (127.0.0.12) with Macrosoft SMTP Server (TLS) id 1.2.3.4; + Wed, 12 Nov 2014 18:18:30 +0100 +X-A: Second +To: third@friep.example.com +X-A: Third +Received: from mx.example.com (127.0.0.13) by mx.example.org + (127.0.0.12) with Macrosoft SMTP Server (TLS) id 1.2.3.4; + Wed, 12 Nov 2014 18:18:29 +0100 +Subject: Frop! +X-A: Fourth +To: fourth@friep.example.com +Received: from mx.example.com (127.0.0.13) by mx.example.org + (127.0.0.12) with Macrosoft SMTP Server (TLS) id 1.2.3.4; + Wed, 12 Nov 2014 18:18:28 +0100 + +Frop +. +; + +test "Header :index" { + if not header :index 3 "x-a" "Third" { + test_fail "wrong header retrieved"; + } + + if header :index 3 "x-a" ["First", "Second", "Fourth"] { + test_fail "other header retrieved"; + } +} + +test "Header :index :last" { + if not header :index 3 :last "x-a" "Second" { + test_fail "wrong header retrieved"; + } + + if header :index 3 :last "x-a" ["First", "Third", "Fourth"] { + test_fail "other header retrieved"; + } +} + +test "Address :index" { + if not address :localpart :index 2 "to" "second" { + test_fail "wrong header retrieved"; + } + + if address :localpart :index 2 "to" ["first", "third", "fourth"] { + test_fail "other header retrieved"; + } +} + +test "Address :index :last" { + if not address :localpart :index 2 :last "to" "third" { + test_fail "wrong header retrieved"; + } + + if address :localpart :index 2 :last "to" ["first", "second", "fourth"] { + test_fail "other header retrieved"; + } +} + +test "Date :index" { + if not date :index 1 "received" "second" "31" { + test_fail "wrong header retrieved"; + } + + if date :index 1 "received" "second" ["30", "29", "28"] { + test_fail "other header retrieved"; + } +} + +test "Date :index :last" { + if not date :index 1 :last "received" "second" "28"{ + test_fail "wrong header retrieved"; + } + + if date :index 1 :last "received" "second" ["31", "30", "29"] { + test_fail "other header retrieved"; + } +} diff --git a/pigeonhole/tests/extensions/index/errors.svtest b/pigeonhole/tests/extensions/index/errors.svtest new file mode 100644 index 0000000..4bfe2dc --- /dev/null +++ b/pigeonhole/tests/extensions/index/errors.svtest @@ -0,0 +1,20 @@ +require "vnd.dovecot.testsuite"; + +require "relational"; +require "comparator-i;ascii-numeric"; + +/* + * Invalid syntax + */ + +test "Invalid Syntax" { + if test_script_compile "errors/syntax.sieve" { + test_fail "compile should have failed"; + } + + if not test_error :count "eq" :comparator "i;ascii-numeric" "7" { + test_fail "wrong number of errors reported"; + } +} + + diff --git a/pigeonhole/tests/extensions/index/errors/syntax.sieve b/pigeonhole/tests/extensions/index/errors/syntax.sieve new file mode 100644 index 0000000..ee19d88 --- /dev/null +++ b/pigeonhole/tests/extensions/index/errors/syntax.sieve @@ -0,0 +1,26 @@ +require "date"; +require "index"; + +# Not an error +if header :last :index 2 "to" "ok" { } + +# Not an error +if header :index 444 :last "to" "ok" { } + +# 1: missing argument +if header :index "to" "ok" {} + +# 2: missing argument +if header :index :last "to" "ok" {} + +# 3: erroneous string argument +if header :index "frop" "to" "ok" {} + +# 4: last without index +if header :last "to" "ok" {} + +# 5: index 0 +if header :index 0 "to" "ok" {} + +# 6: index 0 last +if header :index 0 :last "to" "ok" {} |