From e4339cb64a97e0d04a4cb8e7183aeec4e4ae6a29 Mon Sep 17 00:00:00 2001 From: nik gaffney Date: Wed, 13 Nov 2024 17:42:28 +0100 Subject: [PATCH] =?UTF-8?q?=E4=B7=93=20Contemplation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- i-ching.el | 14 +++++++++----- tests.el | 6 +++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/i-ching.el b/i-ching.el index 6ef2b7b..796cfd5 100644 --- a/i-ching.el +++ b/i-ching.el @@ -865,17 +865,21 @@ Provided by Randomness and Integrity Services Ltd. via https://www.random.org/" The hexagram can be entered as a string, or by number." (interactive "sHexagram number? " hexagram) (let ((hexagram-number - (pcase hexagram - ((pred numberp) hexagram) - ((pred i-ching-hexagram-p) - (i-ching-hexagram-to-number hexagram)) - (_ (error "Not a hexagram symbol or number"))))) + (cond + ((i-ching-hexagram-p hexagram) + (i-ching-hexagram-to-number hexagram)) + ((numberp hexagram) hexagram) + ((stringp hexagram) + (if (numberp (string-to-number hexagram)) + (string-to-number hexagram))) + (t (error "Not a hexagram symbol or number"))))) (format "%s\n\n%s\n\nJudgment: %s\n\nImage: %s\n\n" (i-ching-number-to-hexagram hexagram-number) (i-ching-number-to-description hexagram-number) (i-ching-number-to-judgment hexagram-number) (i-ching-number-to-image hexagram-number)))) + ;; querying the I Ching ;;;###autoload diff --git a/tests.el b/tests.el index 33c72c1..d7c64c0 100644 --- a/tests.el +++ b/tests.el @@ -76,7 +76,11 @@ (ert-deftest i-ching-interprets () (should (stringp (i-ching-interpretation 49))) - (should-not (seq-empty-p (i-ching-interpretation 49)))) + (should (stringp (i-ching-interpretation "23"))) + (should (stringp (i-ching-interpretation "䷖"))) + (should-not (seq-empty-p (i-ching-interpretation 49))) + (should-not (seq-empty-p (i-ching-interpretation "23"))) + (should-not (seq-empty-p (i-ching-interpretation "䷖")))) (ert-deftest i-ching-queries () (should (stringp (i-ching-query-string)))