diff --git a/tests/misc-tests.el b/tests/misc-tests.el index 3929af60..1c4e0ba2 100644 --- a/tests/misc-tests.el +++ b/tests/misc-tests.el @@ -858,6 +858,18 @@ also provides a default value." (list a b))) :type 'loopy-&key-bad-position)) +(ert-deftest pcase-tests-loopy-&map-should-error () + "`&map' cannot be used after `&map' and `&aux'." + (should-error (pcase (list :a 1 :b 2) + ((loopy (&map a &map b)) + (list a b))) + :type 'loopy-&map-bad-position) + + (should-error (pcase (list :a 1 :b 2) + ((loopy (&aux (a 1) &map b)) + (list a b))) + :type 'loopy-&map-bad-position)) + (ert-deftest pcase-tests-&allow-other-keys () (should-error (pcase (list :a 1 :b 2) ((loopy (&allow-other-keys &key b)) @@ -893,6 +905,18 @@ also provides a default value." ((loopy (&key a b)) (list a b)))))) +(ert-deftest pcase-tests-loopy-&map-permissive () + "`&map' should not require a construct like `&allow-other-keys'." + (should (equal (list 1 2) + (pcase (list 'a 1 'b 2 'c 3) + ((loopy (&map a b)) + (list a b))))) + + (should (equal (list 1 2) + (pcase (list :a 1 :b 2 :c 3) + ((loopy (&map (:a a) (:b b))) + (list a b)))))) + (ert-deftest pcase-tests-loopy-&key-not-first () "The plist should be after positional values and equal to `&rest'." (should (equal (list 1 2 3 11 22) @@ -905,6 +929,18 @@ also provides a default value." ((loopy (a b c &rest r1 &key k1 k2)) (list a b c r1 k1 k2)))))) +(ert-deftest pcase-tests-loopy-&map-not-first () + "The map should be after positional values and equal to `&rest'." + (should (equal (list 1 2 3 11 22) + (pcase (list 1 2 3 'k1 11 'k2 22) + ((loopy (a b c &map k1 k2)) + (list a b c k1 k2))))) + + (should (equal (list 1 2 3 (list :k1 11 :k2 22) 11 22) + (pcase (list 1 2 3 :k1 11 :k2 22) + ((loopy (a b c &rest r1 &map (:k1 k1) (:k2 k2))) + (list a b c r1 k1 k2)))))) + (ert-deftest pcase-tests-loopy-&key-full-form () (should (equal (list 1 2) (pcase (list :a 1 :b 2) @@ -937,6 +973,38 @@ also provides a default value." ((loopy (&key a ((key b) 13 b-supplied))) (list a b b-supplied))))))) +(ert-deftest pcase-tests-loopy-&map-full-form () + (should (equal (list 1 2) + (pcase (list 'a 1 'b 2) + ((loopy (&map a ('b b 13))) + (list a b))))) + + (should (equal (list 1 13) + (pcase (list 'a 1) + ((loopy (&map a ('b b 13))) + (list a b))))) + + (should (equal (list 1 13 nil) + (pcase (list 'a 1) + ((loopy (&map a ('b b 13 b-supplied))) + (list a b b-supplied))))) + + (should (equal (list 1 2 t) + (pcase (list 'a 1 'b 2) + ((loopy (&map a ('b b 13 b-supplied))) + (list a b b-supplied))))) + + (should (equal (list 1 2 t) + (pcase (list :a 1 :bat 2) + ((loopy (&map (:a a) (:bat b 13 b-supplied))) + (list a b b-supplied))))) + + (should (equal (list 1 2 t) + (let ((key :bat)) + (pcase (list :a 1 :bat 2) + ((loopy (&map (:a a) (key b 13 b-supplied))) + (list a b b-supplied))))))) + (ert-deftest pcase-tests-loopy-&key-sub-seq () (should (equal '(1 2 (:c 77 :e should-ignore) nil 77 t 99 nil) (pcase '(:ab (1 2)) @@ -977,6 +1045,19 @@ also provides a default value." cd-supp))) (list a b cd cd-supp c c-supp d d-supp)))))) +(ert-deftest pcase-tests-loopy-&map-sub-seq () + (should (equal '(1 2 (:c 77 :e should-ignore) nil 77 t 99 nil) + (pcase '(:ab (1 2)) + ((loopy (&map + (:ab (a b)) + (:cd ( &whole cd + &map + (:c c 88 c-supp) + (:d d 99 d-supp)) + (list :c 77 :e 'should-ignore) + cd-supp))) + (list a b cd cd-supp c c-supp d d-supp)))))) + (ert-deftest pcase-tests-loopy-&aux-should-error () "`&aux' cannot be used after `&aux'." (should-error (pcase nil