Tests: Update (add, reorganize)
They all pass now (with a temporary, uncommitted workaround in makem.sh for a Buttercup bug: <https://github.com/jorgenschaefer/emacs-buttercup/issues/218>).
This commit is contained in:
parent
73ef71ced7
commit
6602f32165
1 changed files with 542 additions and 457 deletions
|
|
@ -205,22 +205,85 @@ with keyword arg NOW in PLIST."
|
|||
(expect (org-ql--value-at (point-min) #'org-get-local-tags)
|
||||
:to-be nil))))
|
||||
|
||||
(describe "Query functions/macros"
|
||||
|
||||
(it "org-ql-select"
|
||||
(expect (length (org-ql-select org-ql-test-buffer
|
||||
'(category)
|
||||
:sort 'deadline))
|
||||
:to-equal org-ql-test-num-headings))
|
||||
(it "org-ql-query"
|
||||
(expect (length (org-ql-query :select 'element
|
||||
:from org-ql-test-buffer
|
||||
:where '(category)
|
||||
:order-by 'date))
|
||||
:to-equal org-ql-test-num-headings)))
|
||||
|
||||
(describe "Query pre-processing"
|
||||
|
||||
(describe "Coalescing"
|
||||
;; NOTE: Queries are expected to be normalized before being coalesced,
|
||||
;; and `org-ql--normalize-query' calls `org-ql--coalesce-ands' as its
|
||||
;; final step, so in these tests we just call the former.
|
||||
(it "coalesces a single AND clause that uses one predicate (and preserves argument order)"
|
||||
(expect (org-ql--normalize-query '(and (rifle "foo") (rifle "bar")))
|
||||
:to-equal '(and (rifle :regexps '("foo" "bar")))))
|
||||
(it "coalesces a single AND clause that uses two predicates (and preserves predicate order)"
|
||||
(expect (org-ql--normalize-query '(and (rifle "foo") (rifle "bar")
|
||||
(heading "baz") (heading "buz")))
|
||||
:to-equal '(and (rifle :regexps '("foo" "bar")) (heading "baz" "buz"))))
|
||||
(it "preserves independent OR clauses"
|
||||
(expect (org-ql--normalize-query '(and (or (rifle "foo") (rifle "bar"))
|
||||
(or (rifle "baz") (rifle "buz"))))
|
||||
:to-equal '(and (or (rifle :regexps '("foo")) (rifle :regexps '("bar"))) (or (rifle :regexps '("baz")) (rifle :regexps '("buz"))))))
|
||||
(it "coalesces an AND clause within an OR clause"
|
||||
(expect (org-ql--normalize-query '(or (regexp "bar") (and (rifle "foo") (rifle "bar"))))
|
||||
:to-equal '(or (regexp "bar") (and (rifle :regexps '("foo" "bar"))))))
|
||||
(it "coalesces multiple AND clauses within an OR clause"
|
||||
(expect (org-ql--normalize-query '(or (and (rifle "foo") (rifle "bar"))
|
||||
(and (rifle "baz") (rifle "buz"))))
|
||||
:to-equal '(or (and (rifle :regexps '("foo" "bar"))) (and (rifle :regexps '("baz" "buz"))))))
|
||||
(it "coalesces arguments to predicates which use coalescing functions and whose calls are eligible for coalescing"
|
||||
(expect (org-ql--normalize-query '(and (src "foo") (src "bar")))
|
||||
:to-equal '(and (src :lang nil :regexps ("foo" "bar"))))
|
||||
(expect (org-ql--normalize-query '(and (src "foo" :lang "elisp") (src "bar" :lang "elisp")))
|
||||
:to-equal '(and (src :lang "elisp" :regexps ("foo" "bar")))))
|
||||
(it "does not coalesce arguments to predicates which use coalescing functions and whose calls are ineligible for coalescing"
|
||||
(expect (org-ql--normalize-query '(and (src "foo" :lang "elisp") (src "bar")))
|
||||
;; NOTE: The current implementation of `org-ql--normalize-query'
|
||||
;; reorders clauses in this case. Fixing that would probably
|
||||
;; not be worth the effort in code or runtime.
|
||||
:to-equal '(and (src :regexps ("bar")) (src :lang "elisp" :regexps ("foo"))))
|
||||
(expect (org-ql--normalize-query '(and (src "foo" :lang "elisp") (src "bar" :lang "python")))
|
||||
:to-equal '(and (src :lang "python" :regexps ("bar")) (src :lang "elisp" :regexps ("foo"))))))
|
||||
|
||||
(describe "Normalization"
|
||||
|
||||
(it "Default predicate"
|
||||
(expect (org-ql--normalize-query "scheduled")
|
||||
;; No colon after keyword, so not a predicate query.
|
||||
:to-equal '(rifle :regexps '("scheduled")))
|
||||
(expect (org-ql--normalize-query "\"quoted phrase\"")
|
||||
:to-equal '(rifle :regexps '("\"quoted phrase\""))))
|
||||
|
||||
(describe "Plain strings"
|
||||
(it "normalizes plain strings to the default predicate (using AND)"
|
||||
(expect (org-ql--normalize-query '(and "string1" "string2"))
|
||||
:to-equal '(and (rifle :regexps '("string1" "string2")))))
|
||||
(it "normalizes plain strings to the default predicate (using OR)"
|
||||
(expect (org-ql--normalize-query '(or "string1" "string2"))
|
||||
:to-equal '(or (rifle :regexps '("string1")) (rifle :regexps '("string2")))))
|
||||
(it "normalizes plain strings within sub-expressions to the default predicate"
|
||||
(expect (org-ql--normalize-query '(and (todo "TODO")
|
||||
(or "string1" "string2")))
|
||||
:to-equal '(and (todo "TODO") (or (rifle :regexps '("string1")) (rifle :regexps '("string2")))))
|
||||
(expect (org-ql--normalize-query '(when (todo "TODO")
|
||||
(or "string1" "string2")))
|
||||
:to-equal '(when (todo "TODO") (or (rifle :regexps '("string1")) (rifle :regexps '("string2")))))
|
||||
(expect (org-ql--normalize-query '(when "string-cond1"
|
||||
(or "string1" "string2")))
|
||||
:to-equal '(when (rifle :regexps '("string-cond1")) (or (rifle :regexps '("string1")) (rifle :regexps '("string2")))))
|
||||
(expect (org-ql--normalize-query '(when (and "string-cond1" "string-cond2")
|
||||
(or "string1" "string2")))
|
||||
:to-equal '(when (and (rifle :regexps '("string-cond1")) (rifle :regexps '("string-cond2"))) (or (rifle :regexps '("string1")) (rifle :regexps '("string2")))))
|
||||
(expect (org-ql--normalize-query '(unless (and "stringcondition1" "stringcond2")
|
||||
(or "string1" "string2")))
|
||||
:to-equal '(unless (and (rifle :regexps '("stringcondition1")) (rifle :regexps '("stringcond2"))) (or (rifle :regexps '("string1")) (rifle :regexps '("string2")))))))
|
||||
|
||||
(describe "(rifle)"
|
||||
(it "with one argument"
|
||||
(expect (org-ql--normalize-query '(rifle "foo."))
|
||||
:to-equal '(rifle :regexps '("foo\\."))))
|
||||
(it "with two arguments"
|
||||
(expect (org-ql--normalize-query '(rifle "foo." "bar"))
|
||||
:to-equal '(rifle :regexps '("foo\\." "bar")))))
|
||||
|
||||
(describe "(level)"
|
||||
(it "with one level"
|
||||
(expect (org-ql--normalize-query '(level "1"))
|
||||
|
|
@ -251,6 +314,25 @@ with keyword arg NOW in PLIST."
|
|||
(expect (org-ql--normalize-query '(olp "a." "b"))
|
||||
:to-equal '(org-ql--predicate-outline-path "a\\." "b"))))
|
||||
|
||||
(describe "(src)"
|
||||
(it "normalizes a non-keyword arg to keywords"
|
||||
(expect (org-ql--normalize-query '(src "foo"))
|
||||
:to-equal '(src :regexps ("foo"))))
|
||||
(it "normalizes non-keyword args to keywords"
|
||||
(expect (org-ql--normalize-query '(src "foo" "bar"))
|
||||
:to-equal '(src :regexps ("foo" "bar"))))
|
||||
(it "normalizes a non-keyword arg with a :lang keyword arg to keywords"
|
||||
(expect (org-ql--normalize-query '(src "foo" :lang "bar"))
|
||||
:to-equal '(src :lang "bar" :regexps ("foo"))))
|
||||
(it "normalizes non-keyword args with a :lang keyword arg to keywords"
|
||||
(expect (org-ql--normalize-query '(src "foo" "bar" :lang "baz"))
|
||||
:to-equal '(src :lang "baz" :regexps ("foo" "bar"))))
|
||||
(it "normalizes all-keyword args without looping"
|
||||
(expect (org-ql--normalize-query '(src :regexps ("foo") :lang "bar"))
|
||||
:to-equal '(src :lang "bar" :regexps ("foo")))
|
||||
(expect (org-ql--normalize-query '(src :regexps ("foo") :lang))
|
||||
:to-equal '(src :regexps ("foo")))))
|
||||
|
||||
(describe "(tags-inherited)"
|
||||
(it "handles 0 arguments"
|
||||
(expect (org-ql--normalize-query '(tags-inherited))
|
||||
|
|
@ -460,31 +542,7 @@ with keyword arg NOW in PLIST."
|
|||
:with-time t))
|
||||
(expect (org-ql--normalize-query '(ts :on 1))
|
||||
:to-equal `(ts :from ,(ts-inc 'day 1 beg-of-today-ts)
|
||||
:to ,(ts-inc 'day 1 end-of-today-ts)))))))
|
||||
|
||||
(describe "Plain strings"
|
||||
(it "normalizes plain strings to the default predicate (using AND)"
|
||||
(expect (org-ql--normalize-query '(and "string1" "string2"))
|
||||
:to-equal '(and (regexp "string1") (regexp "string2"))))
|
||||
(it "normalizes plain strings to the default predicate (using OR)"
|
||||
(expect (org-ql--normalize-query '(or "string1" "string2"))
|
||||
:to-equal '(or (regexp "string1") (regexp "string2"))))
|
||||
(it "normalizes plain strings within sub-expressions to the default predicate"
|
||||
(expect (org-ql--normalize-query '(and (todo "TODO")
|
||||
(or "string1" "string2")))
|
||||
:to-equal '(and (todo "TODO") (or (regexp "string1") (regexp "string2"))))
|
||||
(expect (org-ql--normalize-query '(when (todo "TODO")
|
||||
(or "string1" "string2")))
|
||||
:to-equal '(when (todo "TODO") (or (regexp "string1") (regexp "string2"))))
|
||||
(expect (org-ql--normalize-query '(when "string-cond1"
|
||||
(or "string1" "string2")))
|
||||
:to-equal '(when (regexp "string-cond1") (or (regexp "string1") (regexp "string2"))))
|
||||
(expect (org-ql--normalize-query '(when (and "string-cond1" "string-cond2")
|
||||
(or "string1" "string2")))
|
||||
:to-equal '(when (and (regexp "string-cond1") (regexp "string-cond2")) (or (regexp "string1") (regexp "string2"))))
|
||||
(expect (org-ql--normalize-query '(unless (and "stringcondition1" "stringcond2")
|
||||
(or "string1" "string2")))
|
||||
:to-equal '(unless (and (regexp "stringcondition1") (regexp "stringcond2")) (or (regexp "string1") (regexp "string2"))))))
|
||||
:to ,(ts-inc 'day 1 end-of-today-ts)))
|
||||
|
||||
;; FIXME: This test fails, but only on GitHub CI; it works fine
|
||||
;; locally. It seems to be something to do with Buttercup and
|
||||
|
|
@ -514,13 +572,25 @@ with keyword arg NOW in PLIST."
|
|||
;; :to ,(make-ts :unix 1546408799.0))
|
||||
;; (ts :type inactive
|
||||
;; :from ,(make-ts :unix 1546322400.0)
|
||||
;; :to ,(make-ts :unix 1546408799.0))))
|
||||
)
|
||||
;; :to ,(make-ts :unix 1546408799.0)))))
|
||||
)))))
|
||||
|
||||
(describe "Query preambles"
|
||||
|
||||
;; TODO: Other predicates.
|
||||
|
||||
(describe "(rifle)"
|
||||
(it "with one argument"
|
||||
(expect (org-ql--query-preamble (org-ql--normalize-query '(rifle "foo.")))
|
||||
:to-equal (list :query '(rifle :regexps '("foo\\."))
|
||||
:preamble "\\(?:\\<\\(?:foo\\.\\)\\)"
|
||||
:preamble-case-fold t)))
|
||||
(it "with two arguments"
|
||||
(expect (org-ql--query-preamble (org-ql--normalize-query '(rifle "foo." "bar")))
|
||||
:to-equal (list :query '(rifle :regexps '("foo\\." "bar"))
|
||||
:preamble "\\(?:\\<\\(?:foo\\.\\|bar\\)\\)"
|
||||
:preamble-case-fold t))))
|
||||
|
||||
(describe "(clocked)"
|
||||
(it "without arguments"
|
||||
(expect (org-ql--query-preamble '(clocked))
|
||||
|
|
@ -577,19 +647,14 @@ with keyword arg NOW in PLIST."
|
|||
(expect (org-ql--query-string-to-sexp "!todo:CHECK,SOMEDAY todo:")
|
||||
:to-equal '(and (not (todo "CHECK" "SOMEDAY")) (todo)))
|
||||
(expect (org-ql--query-string-to-sexp "tags:universe !moon")
|
||||
:to-equal '(and (tags "universe") (not (regexp "moon"))))
|
||||
:to-equal '(and (tags "universe") (not (rifle "moon"))))
|
||||
(expect (org-ql--query-string-to-sexp "!moon tags:universe")
|
||||
:to-equal '(and (not (regexp "moon")) (tags "universe")))
|
||||
:to-equal '(and (not (rifle "moon")) (tags "universe")))
|
||||
(expect (org-ql--query-string-to-sexp "mars !ts:on=today")
|
||||
:to-equal '(and (regexp "mars") (not (ts :on "today"))))
|
||||
:to-equal '(and (rifle "mars") (not (ts :on "today"))))
|
||||
(expect (org-ql--query-string-to-sexp "!\"quoted phrase\"")
|
||||
:to-equal '(not (regexp "quoted phrase"))))
|
||||
:to-equal '(not (rifle "quoted phrase"))))
|
||||
(it "Regexp predicates"
|
||||
(expect (org-ql--query-string-to-sexp "scheduled")
|
||||
;; No colon after keyword, so not a predicate query.
|
||||
:to-equal '(regexp "scheduled"))
|
||||
(expect (org-ql--query-string-to-sexp "\"quoted phrase\"")
|
||||
:to-equal '(regexp "quoted phrase"))
|
||||
(expect (org-ql--query-string-to-sexp "regexp:word")
|
||||
:to-equal '(regexp "word"))
|
||||
(expect (org-ql--query-string-to-sexp "regexp:\"quoted phrase\"")
|
||||
|
|
@ -673,7 +738,23 @@ with keyword arg NOW in PLIST."
|
|||
:to-equal "tags:space !regexp:moon"))
|
||||
(it "(or ...)"
|
||||
(expect (org-ql--query-sexp-to-string '(or (tags "book" "books") (priority "A")))
|
||||
:to-equal nil)))
|
||||
:to-equal nil))))
|
||||
|
||||
(describe "Query functions"
|
||||
|
||||
(describe "org-ql-select"
|
||||
(it "returns matching entries"
|
||||
(expect (length (org-ql-select org-ql-test-buffer
|
||||
'(category)
|
||||
:sort 'deadline))
|
||||
:to-equal org-ql-test-num-headings)))
|
||||
(describe "org-ql-query"
|
||||
(it "returns matching entries"
|
||||
(expect (length (org-ql-query :select 'element
|
||||
:from org-ql-test-buffer
|
||||
:where '(category)
|
||||
:order-by 'date))
|
||||
:to-equal org-ql-test-num-headings))))
|
||||
|
||||
(describe "Query results"
|
||||
|
||||
|
|
@ -729,7 +810,7 @@ with keyword arg NOW in PLIST."
|
|||
(org-ql-expect ('(descendants (todo "CHECK")))
|
||||
'("Recurring")))
|
||||
(org-ql-it "with granddescendants query"
|
||||
(org-ql-expect ('(descendants (descendants "moon")))
|
||||
(org-ql-expect ('(descendants (descendants (regexp "moon"))))
|
||||
'("Take over the universe")))
|
||||
(org-ql-it "with query that should not match parent"
|
||||
;; This test would fail if the `descendants' predicate did not properly exclude
|
||||
|
|
@ -1176,6 +1257,7 @@ with keyword arg NOW in PLIST."
|
|||
(org-ql-it ">= a priority"
|
||||
(org-ql-expect ('(priority >= "B"))
|
||||
'("Take over the universe" "Take over the world" "Skype with president of Antarctica" "Take over Mars" "Renew membership in supervillain club" "Learn universal sign language" "Internet" "Spaceship lease" "Fix flux capacitor"))))
|
||||
|
||||
(describe "(property)"
|
||||
|
||||
;; MAYBE: Add support for (property) without arguments.
|
||||
|
|
@ -1202,16 +1284,6 @@ with keyword arg NOW in PLIST."
|
|||
:sort 'todo)
|
||||
'("Take over the universe")))
|
||||
|
||||
(org-ql-it "with a plain string"
|
||||
(org-ql-expect ("Take over"
|
||||
:sort 'todo)
|
||||
'("Take over the universe" "Take over the world" "Take over Mars" "Take over the moon" "Get haircut")))
|
||||
|
||||
(org-ql-it "with two plain strings in an OR"
|
||||
(org-ql-expect ('(or "Take over" "universe")
|
||||
:sort 'todo)
|
||||
'("Take over the universe" "Take over the world" "Take over Mars" "Take over the moon" "Get haircut")))
|
||||
|
||||
(org-ql-it "case-folding predicate with non-case-folding preamble"
|
||||
;; e.g. the (todo) predicate disables case-folding in its preamble, but that
|
||||
;; should not prevent case-folding in this and other predicates (issue #114).
|
||||
|
|
@ -1219,6 +1291,19 @@ with keyword arg NOW in PLIST."
|
|||
:sort 'todo)
|
||||
'("Take over the universe" "Take over the world" "Take over Mars" "Take over the moon" "Get haircut"))))
|
||||
|
||||
(describe "(rifle)"
|
||||
(org-ql-it "with one argument"
|
||||
(org-ql-expect ('(rifle "weekend"))
|
||||
;; In entry text.
|
||||
'("Take over the world"))
|
||||
(org-ql-expect ('(rifle "moon"))
|
||||
;; In outline path.
|
||||
'("Take over the moon" "Visit the moon")))
|
||||
(org-ql-it "with two arguments"
|
||||
(org-ql-expect ('(rifle "Take" "world"))
|
||||
;; In entry text (including tags) and/or outline path.
|
||||
'("Take over the world" "Skype with president of Antarctica" "Get haircut"))))
|
||||
|
||||
(describe "(scheduled)"
|
||||
|
||||
(org-ql-it "without arguments"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue