Skip to content

Commit

Permalink
Stricter defexamples checking
Browse files Browse the repository at this point in the history
* dev/dash-defs.el (dash--example-to-test): Expand docstring.
(defexamples): Ensure each triple is well-formed.
* dev/examples.el (-intersection): Fix badly parenthesized cases.
  • Loading branch information
basil-conto committed Feb 16, 2024
1 parent 13f9fcd commit 5df7605
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 10 additions & 8 deletions dev/dash-defs.el
Expand Up @@ -53,7 +53,8 @@ differences in implementation between systems. Used in place of
dash--epsilon)))

(defun dash--example-to-test (example)
"Return an ERT assertion form based on EXAMPLE."
"Return an ERT assertion form based on EXAMPLE.
Signal an error if EXAMPLE is malformed."
(pcase example
(`(,actual => ,expected) `(should (equal ,actual ,expected)))
(`(,actual ~> ,expected) `(should (approx= ,actual ,expected)))
Expand All @@ -75,13 +76,14 @@ See `dash--groups'."
"Define a set of EXAMPLES and corresponding ERT tests for FN.
See `dash--groups'."
(declare (indent defun))
(setq examples (-partition 3 examples))
`(progn
(push (cons ',fn ',examples) dash--groups)
(ert-deftest ,fn ()
;; Emacs 28.1 complains about an empty `let' body if the test
;; body is empty.
,@(or (mapcar #'dash--example-to-test examples) '(nil)))))
(let (triples tests)
(while (let ((triple (-take 3 examples)))
(push (dash--example-to-test triple) tests)
(push triple triples)
(setq examples (nthcdr 3 examples))))
`(progn
(push (cons ',fn ',(nreverse triples)) dash--groups)
(ert-deftest ,fn () ,@(nreverse tests)))))

;; Added in Emacs 25.1.
(defvar text-quoting-style)
Expand Down
4 changes: 2 additions & 2 deletions dev/examples.el
Expand Up @@ -1356,8 +1356,8 @@ related predicates."
=> '(a b)
(let ((dash--short-list-length 0)) (-intersection '(a b) '(b a a)))
=> '(a b)
(let ((-compare-fn #'string=)) (-intersection '(a) '("a")) => '(a))
(let ((-compare-fn #'string=)) (-intersection '("a") '(a)) => '("a")))
(let ((-compare-fn #'string=)) (-intersection '(a) '("a"))) => '(a)
(let ((-compare-fn #'string=)) (-intersection '("a") '(a))) => '("a"))

(defexamples -powerset
(-powerset '()) => '(())
Expand Down

0 comments on commit 5df7605

Please sign in to comment.