diff options
| author | Stefan Kangas | 2020-06-07 19:57:45 +0200 |
|---|---|---|
| committer | Stefan Kangas | 2020-06-07 19:57:45 +0200 |
| commit | 80abaea1d9c6f1e53fe88befe16de3b219cdd919 (patch) | |
| tree | a4d5a8f708714b4143333954bfc00468f68998f7 | |
| parent | 53fba73ff2599d2e5f06927d474311dc987a4c4d (diff) | |
| download | emacs-80abaea1d9c6f1e53fe88befe16de3b219cdd919.tar.gz emacs-80abaea1d9c6f1e53fe88befe16de3b219cdd919.zip | |
Use lexical-binding in lunar.el and add tests
* lisp/calendar/lunar.el: Use lexical-binding.
(lunar-phases, diary-lunar-phases): Silence byte-compiler.
* test/lisp/calendar/lunar-tests.el: New file.
| -rw-r--r-- | lisp/calendar/lunar.el | 17 | ||||
| -rw-r--r-- | test/lisp/calendar/lunar-tests.el | 70 |
2 files changed, 79 insertions, 8 deletions
diff --git a/lisp/calendar/lunar.el b/lisp/calendar/lunar.el index 3d5a0a236b4..1c0f4da0f4b 100644 --- a/lisp/calendar/lunar.el +++ b/lisp/calendar/lunar.el | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | ;;; lunar.el --- calendar functions for phases of the moon | 1 | ;;; lunar.el --- calendar functions for phases of the moon -*- lexical-binding:t -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1992-1993, 1995, 1997, 2001-2020 Free Software | 3 | ;; Copyright (C) 1992-1993, 1995, 1997, 2001-2020 Free Software |
| 4 | ;; Foundation, Inc. | 4 | ;; Foundation, Inc. |
| @@ -255,6 +255,8 @@ use instead of point." | |||
| 255 | If called with an optional prefix argument ARG, prompts for month and year. | 255 | If called with an optional prefix argument ARG, prompts for month and year. |
| 256 | This function is suitable for execution in an init file." | 256 | This function is suitable for execution in an init file." |
| 257 | (interactive "P") | 257 | (interactive "P") |
| 258 | (with-suppressed-warnings ((lexical date)) | ||
| 259 | (defvar date)) | ||
| 258 | (save-excursion | 260 | (save-excursion |
| 259 | (let* ((date (if arg (calendar-read-date t) | 261 | (let* ((date (if arg (calendar-read-date t) |
| 260 | (calendar-current-date))) | 262 | (calendar-current-date))) |
| @@ -262,18 +264,17 @@ This function is suitable for execution in an init file." | |||
| 262 | (displayed-year (calendar-extract-year date))) | 264 | (displayed-year (calendar-extract-year date))) |
| 263 | (calendar-lunar-phases)))) | 265 | (calendar-lunar-phases)))) |
| 264 | 266 | ||
| 265 | ;; The function below is designed to be used in sexp diary entries, | ||
| 266 | ;; and may be present in users' diary files, so suppress the warning | ||
| 267 | ;; about this prefix-less dynamic variable. It's called from | ||
| 268 | ;; `diary-list-sexp-entries', which binds the variable. | ||
| 269 | (with-suppressed-warnings ((lexical date)) | ||
| 270 | (defvar date)) | ||
| 271 | |||
| 272 | ;;;###diary-autoload | 267 | ;;;###diary-autoload |
| 273 | (defun diary-lunar-phases (&optional mark) | 268 | (defun diary-lunar-phases (&optional mark) |
| 274 | "Moon phases diary entry. | 269 | "Moon phases diary entry. |
| 275 | An optional parameter MARK specifies a face or single-character string to | 270 | An optional parameter MARK specifies a face or single-character string to |
| 276 | use when highlighting the day in the calendar." | 271 | use when highlighting the day in the calendar." |
| 272 | ;; This function is designed to be used in sexp diary entries, and | ||
| 273 | ;; may be present in users' diary files, so suppress the warning | ||
| 274 | ;; about this prefix-less dynamic variable. It's called from | ||
| 275 | ;; `diary-list-sexp-entries', which binds the variable. | ||
| 276 | (with-suppressed-warnings ((lexical date)) | ||
| 277 | (defvar date)) | ||
| 277 | (let* ((index (lunar-index date)) | 278 | (let* ((index (lunar-index date)) |
| 278 | (phase (lunar-phase index))) | 279 | (phase (lunar-phase index))) |
| 279 | (while (calendar-date-compare phase (list date)) | 280 | (while (calendar-date-compare phase (list date)) |
diff --git a/test/lisp/calendar/lunar-tests.el b/test/lisp/calendar/lunar-tests.el new file mode 100644 index 00000000000..8d8a988e503 --- /dev/null +++ b/test/lisp/calendar/lunar-tests.el | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | ;;; lunar-tests.el --- tests for calendar/lunar.el -*- lexical-binding:t -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2020 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Stefan Kangas <stefankangas@gmail.com> | ||
| 6 | |||
| 7 | ;; This file is part of GNU Emacs. | ||
| 8 | |||
| 9 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 10 | ;; it under the terms of the GNU General Public License as published by | ||
| 11 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 12 | ;; (at your option) any later version. | ||
| 13 | |||
| 14 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | ;; GNU General Public License for more details. | ||
| 18 | |||
| 19 | ;; You should have received a copy of the GNU General Public License | ||
| 20 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 21 | |||
| 22 | ;;; Code: | ||
| 23 | |||
| 24 | (require 'ert) | ||
| 25 | (require 'lunar) | ||
| 26 | |||
| 27 | (defmacro with-lunar-test (&rest body) | ||
| 28 | `(let ((calendar-latitude 40.1) | ||
| 29 | (calendar-longitude -88.2) | ||
| 30 | (calendar-location-name "Urbana, IL") | ||
| 31 | (calendar-time-zone -360) | ||
| 32 | (calendar-standard-time-zone-name "CST") | ||
| 33 | (calendar-time-display-form '(12-hours ":" minutes am-pm))) | ||
| 34 | ,@body)) | ||
| 35 | |||
| 36 | (ert-deftest lunar-test-phase () | ||
| 37 | (with-lunar-test | ||
| 38 | (should (equal (lunar-phase 1) | ||
| 39 | '((1 7 1900) "11:40pm" 1 ""))))) | ||
| 40 | |||
| 41 | (ert-deftest lunar-test-eclipse-check () | ||
| 42 | (with-lunar-test | ||
| 43 | (should (equal (eclipse-check 1 1) "** Eclipse **")))) | ||
| 44 | |||
| 45 | (ert-deftest lunar-test-phase-list () | ||
| 46 | (with-lunar-test | ||
| 47 | (should (equal (lunar-phase-list 3 1871) | ||
| 48 | '(((3 20 1871) "11:03pm" 0 "") | ||
| 49 | ((3 29 1871) "1:46am" 1 "** Eclipse **") | ||
| 50 | ((4 5 1871) "9:20am" 2 "") | ||
| 51 | ((4 12 1871) "12:57am" 3 "** Eclipse possible **") | ||
| 52 | ((4 19 1871) "2:06pm" 0 "") | ||
| 53 | ((4 27 1871) "6:49pm" 1 "") | ||
| 54 | ((5 4 1871) "5:57pm" 2 "") | ||
| 55 | ((5 11 1871) "9:29am" 3 "") | ||
| 56 | ((5 19 1871) "5:46am" 0 "") | ||
| 57 | ((5 27 1871) "8:02am" 1 "")))))) | ||
| 58 | |||
| 59 | (ert-deftest lunar-test-new-moon-time () | ||
| 60 | (with-lunar-test | ||
| 61 | (should (= (round (lunar-new-moon-time 1)) | ||
| 62 | 2451580)))) | ||
| 63 | |||
| 64 | (ert-deftest lunar-test-new-moon-on-or-after () | ||
| 65 | (with-lunar-test | ||
| 66 | (should (= (round (lunar-new-moon-on-or-after (calendar-absolute-from-gregorian '(5 5 1818)))) | ||
| 67 | 664525)))) | ||
| 68 | |||
| 69 | (provide 'lunar-tests) | ||
| 70 | ;;; lunar-tests.el ends here | ||