]> git.cworth.org Git - notmuch/blob - test/T131-show-limiting.sh
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / test / T131-show-limiting.sh
1 #!/usr/bin/env bash
2 test_description='"notmuch show" --offset and --limit parameters'
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 add_email_corpus
6
7 show () {
8     local kind="$1"
9     shift
10     if [ "$kind" = messages ]; then
11         set -- --unthreaded "$@"
12     fi
13     notmuch show --body=false --format=text --entire-thread=false "$@" "*" |
14         sed -nre 's/^.message\{.*\<depth:0\>.*/&/p'
15 }
16
17 for outp in messages threads; do
18     test_begin_subtest "$outp: limit does the right thing"
19     show $outp | head -n 20 >expected
20     show $outp --limit=20 >output
21     test_expect_equal_file expected output
22
23     test_begin_subtest "$outp: concatenation of limited shows"
24     show $outp | head -n 20 >expected
25     show $outp --limit=10 >output
26     show $outp --limit=10 --offset=10 >>output
27     test_expect_equal_file expected output
28
29     test_begin_subtest "$outp: limit larger than result set"
30     N=$(notmuch count --output=$outp "*")
31     show $outp >expected
32     show $outp --limit=$((1 + N)) >output
33     test_expect_equal_file expected output
34
35     test_begin_subtest "$outp: limit = 0"
36     test_expect_equal "$(show $outp --limit=0)" ""
37
38     test_begin_subtest "$outp: offset does the right thing"
39     # note: tail -n +N is 1-based
40     show $outp | tail -n +21 >expected
41     show $outp --offset=20 >output
42     test_expect_equal_file expected output
43
44     test_begin_subtest "$outp: offset = 0"
45     show $outp >expected
46     show $outp --offset=0 >output
47     test_expect_equal_file expected output
48
49     test_begin_subtest "$outp: negative offset"
50     show $outp | tail -n 20 >expected
51     show $outp --offset=-20 >output
52     test_expect_equal_file expected output
53
54     test_begin_subtest "$outp: negative offset"
55     show $outp | tail -n 1 >expected
56     show $outp --offset=-1 >output
57     test_expect_equal_file expected output
58
59     test_begin_subtest "$outp: negative offset combined with limit"
60     show $outp | tail -n 20 | head -n 10 >expected
61     show $outp --offset=-20 --limit=10 >output
62     test_expect_equal_file expected output
63
64     test_begin_subtest "$outp: negative offset combined with equal limit"
65     show $outp | tail -n 20 >expected
66     show $outp --offset=-20 --limit=20 >output
67     test_expect_equal_file expected output
68
69     test_begin_subtest "$outp: negative offset combined with large limit"
70     show $outp | tail -n 20 >expected
71     show $outp --offset=-20 --limit=50 >output
72     test_expect_equal_file expected output
73
74     test_begin_subtest "$outp: negative offset larger than results"
75     N=$(notmuch count --output=$outp "*")
76     show $outp >expected
77     show $outp --offset=-$((1 + N)) >output
78     test_expect_equal_file expected output
79 done
80
81 test_done