Skip to content

Commit

Permalink
Add tests for destructuring generalized arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
okamsn committed Jan 27, 2024
1 parent 8aa725c commit 0087e57
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions loopy-misc.el
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@
'loopy-bad-desctructuring)

(define-error 'loopy-&optional-generalized-variable
"Loopy: `&optional' variables are not `setf'-able"
"Loopy: `&optional' variables not implemented for generalized variables"
'loopy-bad-destructuring)

(define-error 'loopy-generalized-default
"Loopy: Default values don't make sense for generalized variables"
"Loopy: Default values not implemented for generalized variables"
'loopy-bad-destructuring)

(define-error 'loopy-generalized-supplied
"Loopy: `SUPPLIED-P' variables are not supported for generalized variables"
"Loopy: `SUPPLIED-P' variables not implemented for generalized variables"
'loopy-bad-destructuring)

(define-error 'loopy-&rest-multiple
Expand Down
17 changes: 17 additions & 0 deletions tests/misc-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,16 @@ INPUT is the destructuring usage. OUTPUT-PATTERN is what to match."
whole (mapcar #'1+ whole)))
l))))))

(ert-deftest generalized-array-should-error ()
(should-error (loopy--destructure-generalized-array [a b &optional c] 'val)
:type 'loopy-&optional-generalized-variable)

(should-error (loopy--destructure-generalized-array [a b &map ('c c 27)] 'val)
:type 'loopy-generalized-default)

(should-error (loopy--destructure-generalized-array [a b &map ('c c nil c-supp)] 'val)
:type 'loopy-generalized-supplied))

(ert-deftest destructure-array-refs ()
(should (equal [1 2 3]
(let ((arr [7 7 7]))
Expand Down Expand Up @@ -442,6 +452,13 @@ INPUT is the destructuring usage. OUTPUT-PATTERN is what to match."
(setf a 1 b 2 c 3 d [4]))
arr)))

(should (equal [1 2 3 4 7 0 0 16]
(let ((arr (vector 7 7 7 7 0 0 6)))
(loopy-ref (([a b c &rest d &map (6 idx-6)] arr))
(setf a 1 b 2 c 3 d [4])
(cl-incf idx-6 10))
arr)))

(should (equal [2 3]
(let ((arr [7 7]))
(loopy-ref (([&whole cat a b] arr))
Expand Down

0 comments on commit 0087e57

Please sign in to comment.