mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-25 04:18:08 +01:00
lib/sexp: provide relative lastmod queries
Test the relatively trivial logic changes for the sexp query parser first before refactoring that logic to share with the infix query parser.
This commit is contained in:
parent
84e4e130e2
commit
606d9b02e4
4 changed files with 47 additions and 0 deletions
|
@ -125,6 +125,9 @@ bounds. Either upper or lower bound may be specified as ``""`` or
|
||||||
``*`` to specify the lowest possible lower bound or highest possible
|
``*`` to specify the lowest possible lower bound or highest possible
|
||||||
upper bound.
|
upper bound.
|
||||||
|
|
||||||
|
``lastmod`` ranges support negative arguments, interpreted relative to
|
||||||
|
the most recent database revision (see :option:`count --lastmod`).
|
||||||
|
|
||||||
.. _field-table:
|
.. _field-table:
|
||||||
|
|
||||||
.. table:: Fields with supported modifiers
|
.. table:: Fields with supported modifiers
|
||||||
|
|
|
@ -575,6 +575,9 @@ _sexp_parse_range (notmuch_database_t *notmuch, const _sexp_prefix_t *prefix,
|
||||||
return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
|
return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (from_idx < 0)
|
||||||
|
from_idx += notmuch_database_get_revision (notmuch, NULL);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (EMPTY_STRING (to))
|
if (EMPTY_STRING (to))
|
||||||
to_idx = LONG_MAX;
|
to_idx = LONG_MAX;
|
||||||
|
@ -585,6 +588,9 @@ _sexp_parse_range (notmuch_database_t *notmuch, const _sexp_prefix_t *prefix,
|
||||||
return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
|
return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (to_idx < 0)
|
||||||
|
to_idx += notmuch_database_get_revision (notmuch, NULL);
|
||||||
|
|
||||||
output = Xapian::Query (Xapian::Query::OP_VALUE_RANGE, NOTMUCH_VALUE_LAST_MOD,
|
output = Xapian::Query (Xapian::Query::OP_VALUE_RANGE, NOTMUCH_VALUE_LAST_MOD,
|
||||||
Xapian::sortable_serialise (from_idx),
|
Xapian::sortable_serialise (from_idx),
|
||||||
Xapian::sortable_serialise (to_idx));
|
Xapian::sortable_serialise (to_idx));
|
||||||
|
|
|
@ -934,6 +934,14 @@ notmuch search lastmod:$revision..$revision | notmuch_search_sanitize > EXPECTED
|
||||||
notmuch search --query=sexp "(and (lastmod $revision))" | notmuch_search_sanitize > OUTPUT
|
notmuch search --query=sexp "(and (lastmod $revision))" | notmuch_search_sanitize > OUTPUT
|
||||||
test_expect_equal_file EXPECTED OUTPUT
|
test_expect_equal_file EXPECTED OUTPUT
|
||||||
|
|
||||||
|
test_begin_subtest "lastmod query, one argument (negative)"
|
||||||
|
notmuch tag +4EFC743A.3060609@april.org id:4EFC743A.3060609@april.org
|
||||||
|
revision=$(notmuch count --lastmod '*' | cut -f3)
|
||||||
|
revision1=$((revision - 1))
|
||||||
|
notmuch search lastmod:$revision1..$revision1 | notmuch_search_sanitize > EXPECTED
|
||||||
|
notmuch search --query=sexp "(lastmod -1)" | notmuch_search_sanitize > OUTPUT
|
||||||
|
test_expect_equal_file_nonempty EXPECTED OUTPUT
|
||||||
|
|
||||||
test_begin_subtest "lastmod query, two arguments"
|
test_begin_subtest "lastmod query, two arguments"
|
||||||
notmuch tag +keithp from:keithp
|
notmuch tag +keithp from:keithp
|
||||||
revision2=$(notmuch count --lastmod '*' | cut -f3)
|
revision2=$(notmuch count --lastmod '*' | cut -f3)
|
||||||
|
@ -941,16 +949,38 @@ notmuch search lastmod:$revision..$revision2 | notmuch_search_sanitize > EXPECTE
|
||||||
notmuch search --query=sexp "(and (lastmod $revision $revision2))" | notmuch_search_sanitize > OUTPUT
|
notmuch search --query=sexp "(and (lastmod $revision $revision2))" | notmuch_search_sanitize > OUTPUT
|
||||||
test_expect_equal_file EXPECTED OUTPUT
|
test_expect_equal_file EXPECTED OUTPUT
|
||||||
|
|
||||||
|
test_begin_subtest "lastmod query, two arguments, first negative"
|
||||||
|
revdiff=$((revision2 - revision))
|
||||||
|
notmuch search lastmod:$revision..$revision2 | notmuch_search_sanitize > EXPECTED
|
||||||
|
notmuch search --query=sexp "(lastmod -$revdiff $revision2)" | notmuch_search_sanitize > OUTPUT
|
||||||
|
test_expect_equal_file EXPECTED OUTPUT
|
||||||
|
|
||||||
|
test_begin_subtest "lastmod query, two arguments, second negative"
|
||||||
|
revdiff=$((revision2 - revision))
|
||||||
|
notmuch search lastmod:..$revision | notmuch_search_sanitize > EXPECTED
|
||||||
|
notmuch search --query=sexp "(lastmod 0 -$revdiff)" | notmuch_search_sanitize > OUTPUT
|
||||||
|
test_expect_equal_file EXPECTED OUTPUT
|
||||||
|
|
||||||
test_begin_subtest "lastmod query, lower bound only"
|
test_begin_subtest "lastmod query, lower bound only"
|
||||||
notmuch search lastmod:$revision.. | notmuch_search_sanitize > EXPECTED
|
notmuch search lastmod:$revision.. | notmuch_search_sanitize > EXPECTED
|
||||||
notmuch search --query=sexp "(lastmod $revision \"\")" | notmuch_search_sanitize > OUTPUT
|
notmuch search --query=sexp "(lastmod $revision \"\")" | notmuch_search_sanitize > OUTPUT
|
||||||
test_expect_equal_file_nonempty EXPECTED OUTPUT
|
test_expect_equal_file_nonempty EXPECTED OUTPUT
|
||||||
|
|
||||||
|
test_begin_subtest "lastmod query, lower bound only (negative)"
|
||||||
|
notmuch search lastmod:$revision.. | notmuch_search_sanitize > EXPECTED
|
||||||
|
notmuch search --query=sexp "(lastmod -$revdiff \"\")" | notmuch_search_sanitize > OUTPUT
|
||||||
|
test_expect_equal_file_nonempty EXPECTED OUTPUT
|
||||||
|
|
||||||
test_begin_subtest "lastmod query, upper bound only"
|
test_begin_subtest "lastmod query, upper bound only"
|
||||||
notmuch search lastmod:..$revision2 | notmuch_search_sanitize > EXPECTED
|
notmuch search lastmod:..$revision2 | notmuch_search_sanitize > EXPECTED
|
||||||
notmuch search --query=sexp "(lastmod \"\" $revision2)" | notmuch_search_sanitize > OUTPUT
|
notmuch search --query=sexp "(lastmod \"\" $revision2)" | notmuch_search_sanitize > OUTPUT
|
||||||
test_expect_equal_file_nonempty EXPECTED OUTPUT
|
test_expect_equal_file_nonempty EXPECTED OUTPUT
|
||||||
|
|
||||||
|
test_begin_subtest "lastmod query, upper bound only (negative)"
|
||||||
|
notmuch search lastmod:..$revision | notmuch_search_sanitize > EXPECTED
|
||||||
|
notmuch search --query=sexp "(lastmod \"\" -$revdiff)" | notmuch_search_sanitize > OUTPUT
|
||||||
|
test_expect_equal_file_nonempty EXPECTED OUTPUT
|
||||||
|
|
||||||
test_begin_subtest "lastmod query, lower bound only, using *"
|
test_begin_subtest "lastmod query, lower bound only, using *"
|
||||||
notmuch search lastmod:$revision.. | notmuch_search_sanitize > EXPECTED
|
notmuch search lastmod:$revision.. | notmuch_search_sanitize > EXPECTED
|
||||||
notmuch search --query=sexp "(lastmod $revision *)" | notmuch_search_sanitize > OUTPUT
|
notmuch search --query=sexp "(lastmod $revision *)" | notmuch_search_sanitize > OUTPUT
|
||||||
|
|
|
@ -95,4 +95,12 @@ subtotal=$(notmuch count lastmod:..$lastmod)
|
||||||
result=$(($subtotal == $total-1))
|
result=$(($subtotal == $total-1))
|
||||||
test_expect_equal 1 "$result"
|
test_expect_equal 1 "$result"
|
||||||
|
|
||||||
|
if [ $NOTMUCH_HAVE_SFSEXP -eq 1 ]; then
|
||||||
|
test_begin_subtest 'exclude one message using negative lastmod (sexp)'
|
||||||
|
total=$(notmuch count '*')
|
||||||
|
notmuch tag +${RANDOM} id:4EFC743A.3060609@april.org
|
||||||
|
count=$(notmuch count --query=sexp '(lastmod -1 *)')
|
||||||
|
test_expect_equal 1 "$count"
|
||||||
|
fi
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in a new issue