forked from 1History/eww-history-ext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eww-history-ext-test.el
49 lines (42 loc) · 1.68 KB
/
eww-history-ext-test.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(add-to-list 'load-path default-directory)
(require 'ert)
(require 'eww-history-ext)
(setq eww-history-ext-db-file (make-temp-file "eww-history-ext"))
(eww-history-ext-enable)
(defun eww-history-ext-test-visit-url (url)
(let ((buf (get-buffer-create "eww-history-test")))
(if (version<= "28" emacs-version)
(eww url nil buf)
;; https://github.com/emacs-mirror/emacs/blob/emacs-27/lisp/net/eww.el#L266
;; EWW don't have buffer arguments in Emacs 27.
(eww-history-ext-save-history url ""))
(kill-buffer buf)))
(ert-deftest test-eww-history ()
(let ((urls '("https://www.gnu.org/"
"https://www.baidu.com/"
"https://github.com/"
"https://www.gnu.org/")))
(dolist (url urls)
(eww-history-ext-test-visit-url url))
(let* ((results (eww-history-ext-query-latest))
(ids (seq-map 'car results))
(rows (seq-map 'cadr results))
(out-urls (seq-map (lambda (r)
(seq-elt r 2))
rows))
(out-counts (seq-map (lambda (r)
(seq-elt r 3))
rows)))
;; Results
;; [("4"
;; ["2022-04-03 09:22:29" "" "https://www.gnu.org/" "2"])
;; ("3"
;; ["2022-04-03 09:22:29" "" "https://github.com/" "1"])
;; ("2"
;; ["2022-04-03 09:22:29" "" "https://www.baidu.com/" "1"])
;; ("1"
;; ["2022-04-03 09:22:29" "" "https://www.gnu.org/" "2"])]
(should (eql (length results) 4))
(should (equal out-urls (seq-reverse urls)))
(should (equal out-counts '("2" "1" "1" "2")))
)))