Skip to content

Commit

Permalink
Fix optaional values as arrays in lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
okamsn committed Jan 27, 2024
1 parent 73d776d commit 9273e55
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
6 changes: 3 additions & 3 deletions loopy-destructure.el
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ MAP-OR-KEY-VARS is whether there are map or key variables."
(cdr pos-vars) opt-vars
rest-var map-or-key-vars))))
(opt-vars (loopy--pcase-let-workaround (var default supplied)
(pcase-let (((or `(,var ,default ,supplied)
`(,var ,default)
`(,var)
(pcase-let (((or (seq var default supplied)
(seq var default)
(seq var)
var)
(car opt-vars)))
(setq var (loopy--get-var-pattern var))
Expand Down
61 changes: 59 additions & 2 deletions tests/misc-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -679,14 +679,19 @@ INPUT is the destructuring usage. OUTPUT-PATTERN is what to match."
((loopy (a b &optional (c 13)))
(list a b c)))))

(should (equal (list 1 2 13)
(pcase (list 1 2)
((loopy (a b &optional [c 13]))
(list a b c)))))

(should (equal (list 1 2 13 nil)
(pcase (list 1 2)
((loopy (a b &optional (c 13 c-supplied)))
((loopy (a b &optional [c 13 c-supplied]))
(list a b c c-supplied)))))

(should (equal (list 1 2 3 t)
(pcase (list 1 2 3)
((loopy (a b &optional (c 13 c-supplied)))
((loopy (a b &optional [c 13 c-supplied]))
(list a b c c-supplied))))))

(ert-deftest pcase-tests-loopy-&optional-sub-seq ()
Expand All @@ -698,28 +703,70 @@ also provides a default value."
((loopy (a b &optional ((c d))))
(list a b c d)))))

(should (equal (list 1 2 3 4)
(pcase (list 1 2 (list 3 4))
((loopy (a b &optional [(c d)]))
(list a b c d)))))

(should (equal (list 1 2 nil nil)
(pcase (list 1 2)
((loopy (a b &optional ((c d))))
(list a b c d)))))


(should (equal (list 1 2 nil nil)
(pcase (list 1 2)
((loopy (a b &optional [(c d)]))
(list a b c d)))))

(should (equal (list 1 2 13 14)
(pcase (list 1 2)
((loopy (a b &optional ((c d) (list 13 14))))
(list a b c d)))))

(should (equal (list 1 2 13 14)
(pcase (list 1 2)
((loopy (a b &optional [(c d) (list 13 14)]))
(list a b c d)))))

(should (equal (list 1 2 13 14)
(pcase (list 1 2)
((loopy ( a b
&optional ((c &optional (d 14))
(list 13))))
(list a b c d)))))

(should (equal (list 1 2 13 14)
(pcase (list 1 2)
((loopy ( a b
&optional ((c &optional [d 14])
(list 13))))
(list a b c d)))))

(should (equal (list 1 2 13 14)
(pcase (list 1 2)
((loopy ( a b
&optional [(c &optional (d 14))
(list 13)]))
(list a b c d)))))

(should (equal (list 1 2 13 14)
(pcase (list 1 2)
((loopy ( a b
&optional [(c &optional [d 14])
(list 13)]))
(list a b c d)))))

(should (equal (list 1 2 13 14 nil)
(pcase (list 1 2)
((loopy (a b &optional ((c d) (list 13 14) cd-supplied)))
(list a b c d cd-supplied)))))

(should (equal (list 1 2 13 14 nil)
(pcase (list 1 2)
((loopy (a b &optional [(c d) (list 13 14) cd-supplied]))
(list a b c d cd-supplied)))))

(should (equal (list 1 2 13 14 nil t nil)
(pcase (list 1 2)
((loopy ( a b
Expand All @@ -728,6 +775,16 @@ also provides a default value."
(d 14 d-sub-sup))
(list 13)
cd-supplied)))
(list a b c d cd-supplied c-sub-sup d-sub-sup)))))

(should (equal (list 1 2 13 14 nil t nil)
(pcase (list 1 2)
((loopy ( a b
&optional
[(&optional (c 27 c-sub-sup)
[d 14 d-sub-sup])
(list 13)
cd-supplied]))
(list a b c d cd-supplied c-sub-sup d-sub-sup))))))

(ert-deftest pcase-tests-loopy-&rest-should-error ()
Expand Down

0 comments on commit 9273e55

Please sign in to comment.