diff --git a/tests/elfeed-search-tests.el b/tests/elfeed-search-tests.el index eecd033..cd70a65 100644 --- a/tests/elfeed-search-tests.el +++ b/tests/elfeed-search-tests.el @@ -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))))