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)))