aboutsummaryrefslogtreecommitdiff
path: root/tests/test-wttrin-location-history.el
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-wttrin-location-history.el')
-rw-r--r--tests/test-wttrin-location-history.el53
1 files changed, 44 insertions, 9 deletions
diff --git a/tests/test-wttrin-location-history.el b/tests/test-wttrin-location-history.el
index d03430d..4af8235 100644
--- a/tests/test-wttrin-location-history.el
+++ b/tests/test-wttrin-location-history.el
@@ -113,31 +113,37 @@
;;; wttrin--completion-candidates
(ert-deftest test-wttrin-location-history-normal-candidates-defaults-then-history ()
- "Candidates list defaults first, then history."
+ "Candidates list the sentinel, then defaults, then history."
(test-wttrin-location-history-setup)
(unwind-protect
- (let ((wttrin-default-locations '("Honolulu, HI" "Berkeley, CA"))
+ (let ((wttrin-favorite-location nil)
+ (wttrin-default-locations '("Honolulu, HI" "Berkeley, CA"))
(wttrin--location-history '("Tokyo" "Paris")))
- (should (equal '("Honolulu, HI" "Berkeley, CA" "Tokyo" "Paris")
+ (should (equal (list wttrin--geolocation-sentinel
+ "Honolulu, HI" "Berkeley, CA" "Tokyo" "Paris")
(wttrin--completion-candidates))))
(test-wttrin-location-history-teardown)))
(ert-deftest test-wttrin-location-history-normal-candidates-only-defaults ()
- "With empty history, candidates are just the defaults."
+ "With empty history, candidates are the sentinel then the defaults."
(test-wttrin-location-history-setup)
(unwind-protect
- (let ((wttrin-default-locations '("Honolulu, HI"))
+ (let ((wttrin-favorite-location nil)
+ (wttrin-default-locations '("Honolulu, HI"))
(wttrin--location-history nil))
- (should (equal '("Honolulu, HI") (wttrin--completion-candidates))))
+ (should (equal (list wttrin--geolocation-sentinel "Honolulu, HI")
+ (wttrin--completion-candidates))))
(test-wttrin-location-history-teardown)))
(ert-deftest test-wttrin-location-history-normal-candidates-only-history ()
- "With empty defaults, candidates are just the history."
+ "With empty defaults, candidates are the sentinel then the history."
(test-wttrin-location-history-setup)
(unwind-protect
- (let ((wttrin-default-locations '())
+ (let ((wttrin-favorite-location nil)
+ (wttrin-default-locations '())
(wttrin--location-history '("Tokyo")))
- (should (equal '("Tokyo") (wttrin--completion-candidates))))
+ (should (equal (list wttrin--geolocation-sentinel "Tokyo")
+ (wttrin--completion-candidates))))
(test-wttrin-location-history-teardown)))
;;; wttrin-remove-location-history
@@ -203,5 +209,34 @@
(require 'savehist)
(should (memq 'wttrin--location-history savehist-additional-variables)))
+(ert-deftest test-wttrin-location-history-normal-savehist-register-adds-var ()
+ "wttrin--savehist-register adds the history variable to the save list."
+ (require 'savehist)
+ (let ((savehist-additional-variables '(kill-ring)))
+ (wttrin--savehist-register)
+ (should (memq 'wttrin--location-history savehist-additional-variables))))
+
+(ert-deftest test-wttrin-location-history-boundary-savehist-register-idempotent ()
+ "Registering an already-present variable does not duplicate it."
+ (require 'savehist)
+ (require 'cl-lib)
+ (let ((savehist-additional-variables '(wttrin--location-history wttrin-favorite-location)))
+ (wttrin--savehist-register)
+ (should (= 1 (cl-count 'wttrin--location-history savehist-additional-variables)))
+ (should (= 1 (cl-count 'wttrin-favorite-location savehist-additional-variables)))))
+
+(ert-deftest test-wttrin-location-history-integration-savehist-register-on-save-hook ()
+ "The registration runs on `savehist-save-hook' so it survives a clobber."
+ (require 'savehist)
+ (should (memq 'wttrin--savehist-register savehist-save-hook)))
+
+(ert-deftest test-wttrin-location-history-integration-savehist-survives-clobber ()
+ "A user setq that drops the variable is repaired before the next save."
+ (require 'savehist)
+ (let ((savehist-additional-variables '(kill-ring search-ring)))
+ ;; simulate the save path: savehist-save runs this hook first
+ (run-hooks 'savehist-save-hook)
+ (should (memq 'wttrin--location-history savehist-additional-variables))))
+
(provide 'test-wttrin-location-history)
;;; test-wttrin-location-history.el ends here