From d784f8f71c8d6dd1c0f39955046848f61be951e5 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Thu, 9 Mar 2023 01:45:03 -0600 Subject: [PATCH] Tests: (src) Implement --- README.org | 1 + tests/data-src.org | 29 +++++++++++++++++++++++++++++ tests/test-org-ql.el | 42 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 tests/data-src.org diff --git a/README.org b/README.org index 4935af9..8f8e751 100644 --- a/README.org +++ b/README.org @@ -563,6 +563,7 @@ Simple links may also be written manually in either sexp or non-sexp form, like: *Internal* + Certain query predicates, when called multiple times in an ~and~ sub-expression, are optimized to a single call. + Use ~buffer-chars-modified-tick~ instead of ~buffer-modified-tick~. (Thanks to [[https://github.com/yantar92][Ihor Radchenko]].) ++ Implemented tests for ~src~ predicate. *Credits* + Thanks to [[https://github.com/chasecaleb][Caleb Chase]] for help with [[https://github.com/alphapapa/org-ql/pull/285][#285]], fixed in [[https://github.com/alphapapa/org-ql/commit/91908186fcca4b5fd2e9d26da5bc0375c2b41acf][9190818]]. diff --git a/tests/data-src.org b/tests/data-src.org new file mode 100644 index 0000000..20f75a8 --- /dev/null +++ b/tests/data-src.org @@ -0,0 +1,29 @@ +#+title: org-ql test data for ~src~ predicate + +* Alpha + +#+begin_src elisp + (message "foo") +#+end_src + +#+begin_src python + print("foo") +#+end_src + +#+begin_src js + console.log("foo") +#+end_src + +* Bravo + +#+begin_src elisp + (message "bar") +#+end_src + +#+begin_src python + print("bar") +#+end_src + +* Charlie + +This entry has no source block. diff --git a/tests/test-org-ql.el b/tests/test-org-ql.el index f762231..bac29be 100644 --- a/tests/test-org-ql.el +++ b/tests/test-org-ql.el @@ -1367,9 +1367,45 @@ with keyword arg NOW in PLIST." (org-ql-expect ('(scheduled :on 0)) '("Practice leaping tall buildings in a single bound" "Order a pizza" "Get haircut" "Fix flux capacitor" "Shop for groceries" "Rewrite Emacs in Common Lisp"))))) - ;; ;; TODO: Test (src) predicate. That will require modifying test data, which will be a - ;; ;; significant hassle. Manual testing shows that the predicate appears to work properly. - ;; + (describe "(src)" + (before-each + ;; It would seem preferable to use :var for this, but this seems more reliable. + (setq org-ql-test-buffer (org-ql-test-data-buffer "data-src.org"))) + + (org-ql-it "without arguments" + (org-ql-expect ('(src)) + '("Alpha" "Bravo"))) + + (org-ql-it "with plain argument" + ;; Finds in first source block in entry. + (org-ql-expect ('(src "foo")) + '("Alpha")) + (org-ql-expect ('(src "bar")) + '("Bravo")) + (org-ql-expect ('(src "print")) + ;; Finds in subsequent source block in entry. + '("Alpha" "Bravo"))) + + (org-ql-it "with :regexps argument" + (org-ql-expect ('(src :regexps ("foo"))) + '("Alpha")) + (org-ql-expect ('(src :regexps ("bar"))) + '("Bravo")) + (org-ql-expect ('(src :regexps ("print" "foo"))) + '("Alpha")) + (org-ql-expect ('(src :regexps ("foo" "bar"))) + nil)) + + (org-ql-it "with :lang argument" + ;; Finds in first source block in entry. + (org-ql-expect ('(src :lang "elisp")) + '("Alpha" "Bravo")) + ;; Finds in subsequent source block in entry. + (org-ql-expect ('(src :lang "python")) + '("Alpha" "Bravo")) + (org-ql-expect ('(src :lang "js")) + '("Alpha")))) + (describe "(todo)" (org-ql-it "without arguments"