From 01b75599a500d6276a962b47744166abb25d846c Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Tue, 28 Apr 2026 19:13:05 -0500 Subject: refactor: switch gloss-fetch result to uniform plist shape MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous shape (:ok DEFS) | (:empty :no-defs (...) :failed (...)) was malformed as a plist. The :empty tag at position 0 shifted the plist alignment. plist-get on :no-defs or :failed returned nil. Tests had to use (plist-get (cdr result) ...) as a workaround. The new shape is a uniform plist with all three keys always present: (:defs DEFS :no-defs (SYM ...) :failed (SYM ...)). Consumers branch on whether :defs is non-empty. There is no tag. plist-get works uniformly across success and empty cases. Updated gloss-fetch.el (rollup function and docstrings), 7 test files, and the design doc (docs/design/gloss.org ยง Error Handling). Tested by `make test`. 65 tests pass in 0.36 seconds. --- ...est-gloss-fetch--definitions-404-returns-no-defs.el | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'tests/test-gloss-fetch--definitions-404-returns-no-defs.el') diff --git a/tests/test-gloss-fetch--definitions-404-returns-no-defs.el b/tests/test-gloss-fetch--definitions-404-returns-no-defs.el index 28587ac..1700e79 100644 --- a/tests/test-gloss-fetch--definitions-404-returns-no-defs.el +++ b/tests/test-gloss-fetch--definitions-404-returns-no-defs.el @@ -15,24 +15,24 @@ (require 'testutil-gloss-fetch) (ert-deftest test-gloss-fetch-definitions-404-rolls-up-to-empty-no-defs () - "Normal: a 404 from the only source rolls up to (:empty :no-defs (wiktionary) :failed nil)." + "Normal: a 404 from the only source rolls up with :no-defs = (wiktionary), :failed and :defs = nil." (gloss-fetch-test--with-mocked-url (lambda (_url) (gloss-fetch-test--status-response "HTTP/1.1 404 Not Found" "{\"detail\":\"Page not found\"}")) (let ((result (gloss-fetch-definitions "asdf-not-a-word"))) - (should (eq (car result) :empty)) - (should (member 'wiktionary (plist-get (cdr result) :no-defs))) - (should-not (plist-get (cdr result) :failed))))) + (should-not (plist-get result :defs)) + (should (member 'wiktionary (plist-get result :no-defs))) + (should-not (plist-get result :failed))))) (ert-deftest test-gloss-fetch-definitions-200-empty-rolls-up-to-empty-no-defs () "Boundary: a 200 with an empty JSON object also maps to :no-defs." (gloss-fetch-test--with-mocked-url (lambda (_url) (gloss-fetch-test--ok-response "{}")) (let ((result (gloss-fetch-definitions "term"))) - (should (eq (car result) :empty)) - (should (member 'wiktionary (plist-get (cdr result) :no-defs))) - (should-not (plist-get (cdr result) :failed))))) + (should-not (plist-get result :defs)) + (should (member 'wiktionary (plist-get result :no-defs))) + (should-not (plist-get result :failed))))) (ert-deftest test-gloss-fetch-definitions-200-no-english-rolls-up-to-no-defs () "Boundary: a 200 response with only non-English keys maps to :no-defs." @@ -41,8 +41,8 @@ (gloss-fetch-test--with-mocked-url (lambda (_url) (gloss-fetch-test--ok-response body)) (let ((result (gloss-fetch-definitions "term"))) - (should (eq (car result) :empty)) - (should (member 'wiktionary (plist-get (cdr result) :no-defs))))))) + (should-not (plist-get result :defs)) + (should (member 'wiktionary (plist-get result :no-defs))))))) (provide 'test-gloss-fetch--definitions-404-returns-no-defs) ;;; test-gloss-fetch--definitions-404-returns-no-defs.el ends here -- cgit v1.2.3