Skip to content

Commit

Permalink
Fix some tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
okamsn committed Jan 26, 2024
1 parent 95da512 commit e9195fd
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 23 deletions.
4 changes: 2 additions & 2 deletions loopy-destructure.el
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ the pattern doesn't match."
(let ((var-list)
(destructuring-expression))
(cl-flet ((signaler (&rest _)
(list 'signal (quote 'loopy-bad-desctructuring)
(list 'signal (quote 'loopy-bad-run-time-desctructuring)
(list 'quote var))))
;; This sets `destructuring-expression' and `var-list'.
(setq destructuring-expression
Expand Down Expand Up @@ -682,7 +682,7 @@ should only be used if VAR-OR-VAL is a variable."
;; that work with state and bad for efficiency.
(value-holder (gensym "loopy--pcase-workaround")))
(cl-flet ((signaler (&rest _)
(list 'signal (quote 'loopy-bad-desctructuring)
(list 'signal (quote 'loopy-bad-run-time-desctructuring)
(list 'quote var))))
(if (fboundp 'pcase-compile-patterns)
(setq full-main-body
Expand Down
12 changes: 8 additions & 4 deletions loopy-misc.el
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,16 @@

;;;;; Errors on Destructuring
(define-error 'loopy-bad-desctructuring
"Loopy: Bad destructuring"
'loopy-error)
"Loopy: Bad destructuring"
'loopy-error)

(define-error 'loopy-bad-run-time-desctructuring
"Loopy: Bad run-time destructuring (value doesn't match)"
'loopy-error)

(define-error 'loopy-&whole-sequence
"Loopy: `&whole' variable is sequence"
'loopy-bad-desctructuring)
"Loopy: `&whole' variable is sequence"
'loopy-bad-desctructuring)

(define-error 'loopy-&whole-missing
"Loopy: `&whole' variable is missing"
Expand Down
61 changes: 44 additions & 17 deletions tests/misc-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
(require 'pcase)
(require 'map)
(require 'loopy)
(require 'loopy-destructure)
;; (require 'loopy-destructure)

(ert-deftest pcase-pat-defined ()
(should (get 'loopy 'pcase-macroexpander)))
Expand Down Expand Up @@ -184,23 +184,23 @@ INPUT is the destructuring usage. OUTPUT-PATTERN is what to match."
(eval (quote (loopy-let* (((a b c &key d e . f) '(1 2 3 :e 5 :d 4)))
(list a b c d e f))))))

(should (equal '(1 2 3 7 6 (4 5 :e 6 :d 7))
(eval (quote (loopy-let* (((a b c &key d e . f) '(1 2 3 4 5 :e 6 :d 7)))
(should (equal '(1 2 3 7 6 (:e 6 :d 7))
(eval (quote (loopy-let* (((a b c _ _ &key d e . f) '(1 2 3 4 5 :e 6 :d 7)))
(list a b c d e f))))))

(should (equal '(1 2 3 7 6 (4 5 :e 6 :d 7))
(eval (quote (loopy-let* (((a b c &key d e &rest f)
(should (equal '(1 2 3 7 6 (4 5 :e 6 :d 7) 5)
(eval (quote (loopy-let* (((a b c &key ((4 key4)) d e &rest f)
'(1 2 3 4 5 :e 6 :d 7)))
(list a b c d e f))))))
(list a b c d e f key4))))))

(should (equal '(1 2 3 7 6 (4 5 :e 6 :d 7))
(eval (quote (loopy-let* (((a b c &rest f &key d e)
(should (equal '(1 2 3 7 6 (4 5 :e 6 :d 7) 5)
(eval (quote (loopy-let* (((a b c &rest f &key ((4 key4)) d e)
'(1 2 3 4 5 :e 6 :d 7)))
(list a b c d e f))))))
(list a b c d e f key4))))))

(should-error (eval (quote (loopy-let* (((&key d e) '(:a 7 :e 5 :d 4)))
(list d e a))))
:type 'loopy-&key-unmatched)
:type 'loopy-bad-run-time-desctructuring)

(should (equal '(4 5)
(eval (quote (loopy-let* (((&key d e &allow-other-keys) '(:a 7 :e 5 :d 4)))
Expand Down Expand Up @@ -235,24 +235,50 @@ INPUT is the destructuring usage. OUTPUT-PATTERN is what to match."
'(1 2 3 :e 5 :d 4)))
(list cat a b c d e f))))))

(should (equal '((1 2 3 4 5 :e 6 :d 7) 1 2 3 7 6 (4 5 :e 6 :d 7))
(eval (quote (loopy-let* (((&whole cat a b c &key d e . f)
(should (equal '((1 2 3 4 5 :e 6 :d 7) 1 2 3 7 6 (4 5 :e 6 :d 7) 5)
(eval (quote (loopy-let* (((&whole cat a b c &key d e ((4 key4)). f)
'(1 2 3 4 5 :e 6 :d 7)))
(list cat a b c d e f key4))))))

(should (equal '((1 2 3 4 5 e 6 d 7) 1 2 3 7 6 (4 5 e 6 d 7))
(eval (quote (loopy-let* (((&whole cat a b c &map d e . f)
'(1 2 3 4 5 e 6 d 7)))
(list cat a b c d e f))))))

(should (equal '((1 2 3 4 5 :e 6 :d 7) 1 2 3 7 6 (4 5 :e 6 :d 7))
(eval (quote (loopy-let* (((&whole cat a b c &key d e &rest f)
(eval (quote (loopy-let* (((&whole cat a b c &map (:d d) (:e e) . f)
'(1 2 3 4 5 :e 6 :d 7)))
(list cat a b c d e f))))))

(should (equal '((1 2 3 4 5 :e 6 :d 7) 1 2 3 7 6 (4 5 :e 6 :d 7) 5)
(eval (quote (loopy-let* (((&whole cat a b c &key d e ((4 key4)) &rest f)
'(1 2 3 4 5 :e 6 :d 7)))
(list cat a b c d e f key4))))))

(should (equal '((1 2 3 4 5 e 6 d 7) 1 2 3 7 6 (4 5 e 6 d 7))
(eval (quote (loopy-let* (((&whole cat a b c &map d e &rest f)
'(1 2 3 4 5 e 6 d 7)))
(list cat a b c d e f))))))

(should (equal '((1 2 3 4 5 :e 6 :d 7) 1 2 3 7 6 (4 5 :e 6 :d 7) 5)
(eval (quote (loopy-let* (((&whole cat a b c &rest f &key d e ((4 key4)))
'(1 2 3 4 5 :e 6 :d 7)))
(list cat a b c d e f key4))))))

(should (equal '((1 2 3 4 5 :e 6 :d 7) 1 2 3 7 6 (4 5 :e 6 :d 7))
(eval (quote (loopy-let* (((&whole cat a b c &rest f &key d e)
(eval (quote (loopy-let* (((&whole cat a b c &rest f
&map (:d d) (:e e))
'(1 2 3 4 5 :e 6 :d 7)))
(list cat a b c d e f))))))

(should (equal '((:a 7 :e 5 :d 4) 4 5)
(eval (quote (loopy-let* (((&whole cat &key d e)
(eval (quote (loopy-let* (((&whole cat &key d e &allow-other-keys)
'(:a 7 :e 5 :d 4)))
(list cat d e))))))

(should (equal '((:a 7 :e 5 :d 4 :allow-other-keys t) 4 5)
(eval (quote (loopy-let* (((&whole cat &key d e)
'(:a 7 :e 5 :d 4 :allow-other-keys t)))
(list cat d e)))))))

;; This only tests the getting of values.
Expand Down Expand Up @@ -976,11 +1002,12 @@ also provides a default value."
(list a b))))))

(ert-deftest pcase-tests-loopy-all ()
(should (equal '(1 2 3 4 5 (:k1 111 :k2 222) 111 222 333 444)
(should (equal '(1 2 3 4 5 (:k1 111 :k2 222) 111 222 111 222 333 444)
(pcase (list 1 2 3 4 5 :k1 111 :k2 222)
((loopy ( a b c
&optional d e
&rest r
&key k1 k2
&map (:k1 map1) (:k2 map2)
&aux (x1 333) (x2 444)))
(list a b c d e r k1 k2 x1 x2))))))
(list a b c d e r k1 k2 map1 map2 x1 x2))))))

0 comments on commit e9195fd

Please sign in to comment.