Skip to content

Commit

Permalink
Fix up date filter tests
Browse files Browse the repository at this point in the history
Due to a bug in Emacs 25 (all releases) where ERT tests don't expand
macros properly, these tests didn't actually work. However, we don't
actually need or want a macro here anyway, so just get rid of it!
  • Loading branch information
skeeto committed Sep 10, 2020
1 parent 2b8d7fe commit 73023f1
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions tests/elfeed-search-tests.el
Expand Up @@ -25,32 +25,37 @@
(test-search-parse-filter-duration "@2019-06-01--4-days-ago" 23 4)
(test-search-parse-filter-duration "@4-days-ago--2019-06-01" 23 4))))

(defmacro run-date-filter (filter entry-time-string test-time-string)
"Creates an entry with ENTRY-TIME-STRING, sets the current time
to TEST-TIME-STRING and then tests the compiled filter function
by calling it with entry and FILTER. Returns t if the filter
matches, nil otherwise."
`(let* ((test-time (seconds-to-time (elfeed-parse-simple-iso-8601 ,test-time-string)))
(entry-time (seconds-to-time (elfeed-parse-simple-iso-8601 ,entry-time-string)))
(orig-float-time (symbol-function 'float-time))
(entry (elfeed-entry--create
:title "test-entry"
:date (float-time entry-time))))
(cl-letf (((symbol-function 'current-time)
(lambda () test-time))
((symbol-function 'float-time)
(lambda (&optional time)
(funcall orig-float-time (or time test-time)))))
(catch 'elfeed-db-done
(let ((filter-fn (elfeed-search-compile-filter (elfeed-search-parse-filter ,filter))))
(funcall filter-fn entry nil 0))))))
(defun run-date-filter (filter entry-datetime test-datetime)
"Test if time FILTER passes ENTRY-DATETIME against TEST-DATETIME."
(let* ((test-secs (elfeed-parse-simple-iso-8601 test-datetime))
(test-time (seconds-to-time test-secs))
(entry-secs (elfeed-parse-simple-iso-8601 entry-datetime))
(entry-time (seconds-to-time entry-secs))
(orig-float-time (symbol-function 'float-time))
(entry (elfeed-entry--create
:title "test-entry"
:date (float-time entry-time))))
(cl-letf (((symbol-function 'current-time)
(lambda () test-time))
((symbol-function 'float-time)
(lambda (&optional time)
(funcall orig-float-time (or time test-time)))))
(catch 'elfeed-db-done
(let* ((parsed (elfeed-search-parse-filter filter))
(filter (elfeed-search-compile-filter parsed)))
(funcall filter entry nil 0))))))

(ert-deftest elfeed-search-compile-filter ()
(should (null (run-date-filter "@1-days-ago" "2019-06-23" "2019-06-25")))
(should (run-date-filter "@3-days-ago" "2019-06-23" "2019-06-25"))
(should (null (run-date-filter "@30-days-ago--10-days-ago" "2019-06-23" "2019-06-25")))
(should (run-date-filter "@2019-06-01" "2019-06-23" "2019-06-25"))
(should (null (run-date-filter "@2019-06-01--2019-06-20" "2019-06-23" "2019-06-25"))))
(should-not (run-date-filter "@1-days-ago"
"2019-06-23" "2019-06-25"))
(should (run-date-filter "@3-days-ago"
"2019-06-23" "2019-06-25"))
(should-not (run-date-filter "@30-days-ago--10-days-ago"
"2019-06-23" "2019-06-25"))
(should (run-date-filter "@2019-06-01"
"2019-06-23" "2019-06-25"))
(should-not (run-date-filter "@2019-06-01--2019-06-20"
"2019-06-23" "2019-06-25")))

(ert-deftest elfeed-search-unparse-filter ()
(should (string-equal "@5-minutes-ago" (elfeed-search-unparse-filter '(:after 300))))
Expand Down

0 comments on commit 73023f1

Please sign in to comment.