]> git.notmuchmail.org Git - notmuch/commitdiff
test: add tests for notmuch search --offset and --limit
authorJani Nikula <jani@nikula.org>
Tue, 15 Nov 2011 20:08:53 +0000 (22:08 +0200)
committerDavid Bremner <bremner@debian.org>
Tue, 15 Nov 2011 23:25:58 +0000 (19:25 -0400)
Signed-off-by: Jani Nikula <jani@nikula.org>
test/notmuch-test
test/search-limiting [new file with mode: 0755]

index 29de30d7652c3fc6bc7889c44cc450b8b92086cc..adfd589fe0765d19d575d4714f59ef4f352b6022 100755 (executable)
@@ -25,6 +25,7 @@ TESTS="
   search-by-folder
   search-position-overlap-bug
   search-insufficient-from-quoting
+  search-limiting
   tagging
   json
   multipart
diff --git a/test/search-limiting b/test/search-limiting
new file mode 100755 (executable)
index 0000000..303762c
--- /dev/null
@@ -0,0 +1,71 @@
+#!/usr/bin/env bash
+test_description='"notmuch search" --offset and --limit parameters'
+. ./test-lib.sh
+
+add_email_corpus
+
+for outp in messages threads; do
+    test_begin_subtest "${outp}: limit does the right thing"
+    notmuch search --output=${outp} "*" | head -n 20 >expected
+    notmuch search --output=${outp} --limit=20 "*" >output
+    test_expect_equal_file expected output
+
+    test_begin_subtest "${outp}: concatenation of limited searches"
+    notmuch search --output=${outp} "*" | head -n 20 >expected
+    notmuch search --output=${outp} --limit=10 "*" >output
+    notmuch search --output=${outp} --limit=10 --offset=10 "*" >>output
+    test_expect_equal_file expected output
+
+    test_begin_subtest "${outp}: limit larger than result set"
+    N=`notmuch count --output=${outp} "*"`
+    notmuch search --output=${outp} "*" >expected
+    notmuch search --output=${outp} --limit=$((1 + ${N})) "*" >output
+    test_expect_equal_file expected output
+
+    test_begin_subtest "${outp}: limit = 0"
+    test_expect_equal "`notmuch search --output=${outp} --limit=0 "*"`" ""
+
+    test_begin_subtest "${outp}: offset does the right thing"
+    # note: tail -n +N is 1-based
+    notmuch search --output=${outp} "*" | tail -n +21 >expected
+    notmuch search --output=${outp} --offset=20 "*" >output
+    test_expect_equal_file expected output
+
+    test_begin_subtest "${outp}: offset = 0"
+    notmuch search --output=${outp} "*" >expected
+    notmuch search --output=${outp} --offset=0 "*" >output
+    test_expect_equal_file expected output
+
+    test_begin_subtest "${outp}: negative offset"
+    notmuch search --output=${outp} "*" | tail -n 20 >expected
+    notmuch search --output=${outp} --offset=-20 "*" >output
+    test_expect_equal_file expected output
+
+    test_begin_subtest "${outp}: negative offset"
+    notmuch search --output=${outp} "*" | tail -n 1 >expected
+    notmuch search --output=${outp} --offset=-1 "*" >output
+    test_expect_equal_file expected output
+
+    test_begin_subtest "${outp}: negative offset combined with limit"
+    notmuch search --output=${outp} "*" | tail -n 20 | head -n 10 >expected
+    notmuch search --output=${outp} --offset=-20 --limit=10 "*" >output
+    test_expect_equal_file expected output
+
+    test_begin_subtest "${outp}: negative offset combined with equal limit"
+    notmuch search --output=${outp} "*" | tail -n 20 >expected
+    notmuch search --output=${outp} --offset=-20 --limit=20 "*" >output
+    test_expect_equal_file expected output
+
+    test_begin_subtest "${outp}: negative offset combined with large limit"
+    notmuch search --output=${outp} "*" | tail -n 20 >expected
+    notmuch search --output=${outp} --offset=-20 --limit=50 "*" >output
+    test_expect_equal_file expected output
+
+    test_begin_subtest "${outp}: negative offset larger then results"
+    N=`notmuch count --output=${outp} "*"`
+    notmuch search --output=${outp} "*" >expected
+    notmuch search --output=${outp} --offset=-$((1 + ${N})) "*" >output
+    test_expect_equal_file expected output
+done
+
+test_done