Stricter defexamples checking

* 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.
master
Basil L. Contovounesios 2 years ago
parent 13f9fcd09d
commit 5df7605da5
No known key found for this signature in database
GPG Key ID: 598403058CAFA86C
  1. 18
      dev/dash-defs.el
  2. 4
      dev/examples.el

@ -53,7 +53,8 @@ differences in implementation between systems. Used in place of
dash--epsilon))) dash--epsilon)))
(defun dash--example-to-test (example) (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 (pcase example
(`(,actual => ,expected) `(should (equal ,actual ,expected))) (`(,actual => ,expected) `(should (equal ,actual ,expected)))
(`(,actual ~> ,expected) `(should (approx= ,actual ,expected))) (`(,actual ~> ,expected) `(should (approx= ,actual ,expected)))
@ -75,13 +76,14 @@ See `dash--groups'."
"Define a set of EXAMPLES and corresponding ERT tests for FN. "Define a set of EXAMPLES and corresponding ERT tests for FN.
See `dash--groups'." See `dash--groups'."
(declare (indent defun)) (declare (indent defun))
(setq examples (-partition 3 examples)) (let (triples tests)
`(progn (while (let ((triple (-take 3 examples)))
(push (cons ',fn ',examples) dash--groups) (push (dash--example-to-test triple) tests)
(ert-deftest ,fn () (push triple triples)
;; Emacs 28.1 complains about an empty `let' body if the test (setq examples (nthcdr 3 examples))))
;; body is empty. `(progn
,@(or (mapcar #'dash--example-to-test examples) '(nil))))) (push (cons ',fn ',(nreverse triples)) dash--groups)
(ert-deftest ,fn () ,@(nreverse tests)))))
;; Added in Emacs 25.1. ;; Added in Emacs 25.1.
(defvar text-quoting-style) (defvar text-quoting-style)

@ -1356,8 +1356,8 @@ related predicates."
=> '(a b) => '(a b)
(let ((dash--short-list-length 0)) (-intersection '(a b) '(b a a))) (let ((dash--short-list-length 0)) (-intersection '(a b) '(b a a)))
=> '(a b) => '(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 (defexamples -powerset
(-powerset '()) => '(()) (-powerset '()) => '(())

Loading…
Cancel
Save