From e039c73abdeb81cdafd06f50e3ea42630c345de2 Mon Sep 17 00:00:00 2001 From: Nicolas Dandrimont Date: Fri, 10 May 2013 23:42:13 +0200 Subject: [PATCH] Add tests for quasiquoting --- tests/__init__.py | 1 + tests/native_tests/language.hy | 6 ----- tests/native_tests/quote.hy | 45 ++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 tests/native_tests/quote.hy diff --git a/tests/__init__.py b/tests/__init__.py index 5738538..3290f8c 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -4,6 +4,7 @@ import hy # noqa from .native_tests.defclass import * # noqa from .native_tests.math import * # noqa +from .native_tests.quote import * # noqa from .native_tests.language import * # noqa from .native_tests.unless import * # noqa from .native_tests.when import * # noqa diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index d01a0fd..8d138dc 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -656,12 +656,6 @@ (assert (= (foo 1 2 3 4) [1 2 3 4]))) -(defn test-quoted-hoistable [] - "NATIVE: test quoted hoistable" - (setf f (quote (if true true true))) - (assert (= (car f) "if")) - (assert (= (cdr f) (quote (true true true))))) - (defn test-undefined-name [] "NATIVE: test that undefined names raise errors" (try diff --git a/tests/native_tests/quote.hy b/tests/native_tests/quote.hy new file mode 100644 index 0000000..6114f4f --- /dev/null +++ b/tests/native_tests/quote.hy @@ -0,0 +1,45 @@ +(defn test-quote [] + "NATIVE: test for quoting functionality" + (setf q (quote (a b c))) + (assert (= (len q) 3)) + (assert (= q [(quote a) (quote b) (quote c)]))) + + +(defn test-quoted-hoistable [] + "NATIVE: check whether quote works on hoisted things" + (setf f (quote (if true true true))) + (assert (= (car f) (quote if))) + (assert (= (cdr f) (quote (true true true))))) + + +(defn test-quasiquote [] + "NATIVE: test that quasiquote and quote are equivalent for simple cases" + (setf q (quote (a b c))) + (setf qq (quasiquote (a b c))) + (assert (= q qq))) + + +(defn test-unquote [] + "NATIVE: test that unquote works as expected" + (setf q (quote (unquote foo))) + (assert (= (len q) 2)) + (assert (= (get q 1) (quote foo))) + (setf qq (quasiquote (a b c (unquote (+ 1 2))))) + (assert (= (len qq) 4)) + (assert (= qq (quote (a b c 3))))) + + +(defn test-unquote-splice [] + "NATIVE: test splicing unquotes" + (setf q (quote (c d e))) + (setf qq (quasiquote (a b (unquote-splice q)))) + (assert (= (len qq) 5)) + (assert (= qq (quote (a b c d e))))) + +(defn test-nested-quasiquote [] + "NATIVE: test nested quasiquotes" + (setf qq (quasiquote (1 (quasiquote (unquote (+ 1 (unquote (+ 2 3))))) 4))) + (setf q (quote (1 (quasiquote (unquote (+ 1 5))) 4))) + (assert (= (len q) 3)) + (assert (= (get qq 1) (quote (quasiquote (unquote (+ 1 5)))))) + (assert (= q qq)))