summaryrefslogtreecommitdiff
path: root/llama-test.el
diff options
context:
space:
mode:
authorJonas Bernoulli <jonas@bernoul.li>2024-09-15 18:29:26 +0200
committerJonas Bernoulli <jonas@bernoul.li>2024-09-15 18:29:26 +0200
commit58ee34c635130241dc357e53210e18c5e0934923 (patch)
tree706a4fd0390f0cda5df82038f42d92f899d5a0f9 /llama-test.el
parentfffe9cff4ba0478aafcbdf4375e28605d30dc537 (diff)
Add more tests
Diffstat (limited to 'llama-test.el')
-rw-r--r--llama-test.el66
1 files changed, 66 insertions, 0 deletions
diff --git a/llama-test.el b/llama-test.el
index 8d1eeb4..3e380b8 100644
--- a/llama-test.el
+++ b/llama-test.el
@@ -300,6 +300,72 @@
(% %2 %1))))
)
+(defmacro llama-test--flatten (expr)
+ (when (vectorp expr)
+ (setq expr (mapcan (lambda (e)
+ (if (vectorp e) (append e ()) (list e)))
+ (append expr ()))))
+ (let ((body ()))
+ (while expr
+ (if (listp expr) (push (pop expr) body) (push expr body) (setq expr nil)))
+ (cons 'list (nreverse body))))
+
+(ert-deftest llama-test-502-vector nil
+ :expected-result :failed
+
+ ;; Real world example: (##-let [val %1] ...).
+
+ (should (equal (##llama-test--flatten [[1 %1]])
+ (lambda (%1)
+ (llama-test--flatten [[1 %1]]))))
+
+ (should (equal (##llama-test--flatten [%2 [%1]])
+ (lambda (%1 %2)
+ (llama-test--flatten [%2 [%1]]))))
+
+ (should (equal (##llama-test--flatten [%1 _%2 %3])
+ ;; failure:
+ ;; (lambda (%1 _%2 %3)
+ ;; (llama-test--flatten [%1 llama--unused-argument %3]))
+ (lambda (%1 _%2 %3)
+ (llama-test--flatten [%1 %3]))))
+ )
+
+(ert-deftest llama-test-502-dotted nil
+ :expected-result :failed
+
+ ;; Real world example: ???.
+
+ (should (equal (##llama-test--flatten (%1 . %2))
+ (lambda (%1 %2)
+ (llama-test--flatten (%1 . %2)))))
+
+ (should (equal (##llama-test--flatten (%1 %2 . %3))
+ (lambda (%1 %2 %3)
+ (llama-test--flatten (%1 %2 . %3)))))
+
+ (should (equal (##llama-test--flatten (%1 _%2 . %3))
+ ;; failure:
+ ;; (lambda (%1 _%2 %3)
+ ;; (llama-test--flatten (%1 _%2 . %3)))
+ (lambda (%1 _%2 %3)
+ (llama-test--flatten (%1 . %3)))))
+
+ (should (equal (##llama-test--flatten (%1 _%2 %3 . %4))
+ ;; failure:
+ ;; (lambda (%1 _%2 %3 %4)
+ ;; (llama-test--flatten (%1 _%2 %3 . %4)))
+ (lambda (%1 _%2 %3 %4)
+ (llama-test--flatten (%1 %3 . %4)))))
+ )
+
+(ert-deftest llama-test-503-quoted nil
+
+ (should (equal (##cons %1 '(%2))
+ (lambda (%1)
+ (cons %1 '(%2)))))
+ )
+
(ert-deftest llama-test-901-errors-first nil
(should-error (##list %1 &1))
(should-error (##list &1 %1))