aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test-testutil-gloss--load-wiktionary-fixture.el37
-rw-r--r--tests/testutil-gloss.el17
2 files changed, 54 insertions, 0 deletions
diff --git a/tests/test-testutil-gloss--load-wiktionary-fixture.el b/tests/test-testutil-gloss--load-wiktionary-fixture.el
new file mode 100644
index 0000000..daf24af
--- /dev/null
+++ b/tests/test-testutil-gloss--load-wiktionary-fixture.el
@@ -0,0 +1,37 @@
+;;; test-testutil-gloss--load-wiktionary-fixture.el --- Tests for fixture loader -*- lexical-binding: t -*-
+
+;; SPDX-License-Identifier: GPL-3.0-or-later
+
+;;; Commentary:
+;; Tests for `gloss-test--load-wiktionary-fixture' covering
+;; Normal/Boundary/Error cases.
+
+;;; Code:
+
+(require 'ert)
+(require 'testutil-gloss)
+
+(ert-deftest test-testutil-gloss-load-wiktionary-fixture-existing-returns-string ()
+ "Normal: an existing fixture loads as a non-empty JSON string."
+ (let ((body (gloss-test--load-wiktionary-fixture "anaphora")))
+ (should (stringp body))
+ (should (> (length body) 0))
+ (should (string-prefix-p "{" body))))
+
+(ert-deftest test-testutil-gloss-load-wiktionary-fixture-smallest-fixture-loads ()
+ "Boundary: the 404 error-body fixture (smallest) loads as a string."
+ (let ((body (gloss-test--load-wiktionary-fixture "404")))
+ (should (stringp body))
+ (should (> (length body) 0))
+ (should (string-match-p "404" body))))
+
+(ert-deftest test-testutil-gloss-load-wiktionary-fixture-missing-raises-error ()
+ "Error: a missing fixture signals `error' with the path in the message."
+ (let* ((name "does-not-exist-xyzzy")
+ (err (should-error (gloss-test--load-wiktionary-fixture name)
+ :type 'error)))
+ (should (string-match-p (format "wiktionary-%s\\.json" name)
+ (error-message-string err)))))
+
+(provide 'test-testutil-gloss--load-wiktionary-fixture)
+;;; test-testutil-gloss--load-wiktionary-fixture.el ends here
diff --git a/tests/testutil-gloss.el b/tests/testutil-gloss.el
index 7510765..36ba7ef 100644
--- a/tests/testutil-gloss.el
+++ b/tests/testutil-gloss.el
@@ -76,5 +76,22 @@ any visiting buffer if BODY created them."
(when (file-exists-p gloss-file)
(delete-file gloss-file)))))
+(defconst gloss-test--testutil-dir
+ (file-name-directory (or load-file-name buffer-file-name default-directory))
+ "Directory of this testutil file; used to locate fixtures.")
+
+(defun gloss-test--load-wiktionary-fixture (name)
+ "Return the raw JSON body of fixture `wiktionary-NAME.json' as a string.
+NAME is the fixture name without the `wiktionary-' prefix or `.json'
+suffix (e.g. \"anaphora\"). Fixtures live in tests/fixtures/ alongside
+this file. Signal `error' with the full path if the file is missing."
+ (let ((path (expand-file-name (format "fixtures/wiktionary-%s.json" name)
+ gloss-test--testutil-dir)))
+ (unless (file-exists-p path)
+ (error "Wiktionary fixture not found: %s" path))
+ (with-temp-buffer
+ (insert-file-contents path)
+ (buffer-string))))
+
(provide 'testutil-gloss)
;;; testutil-gloss.el ends here