Add tests for &key arguments in functions

This commit is contained in:
Nicolas Dandrimont 2013-05-08 21:10:30 +02:00
parent 04b2d9d291
commit 5dbf6c6ca9
2 changed files with 13 additions and 0 deletions

View File

@ -350,6 +350,11 @@ def test_ast_non_kwapplyable():
pass
def test_ast_lambda_lists():
"""Ensure the compiler chokes on invalid lambda-lists"""
cant_compile('(fn [&key {"a" b} &key {"foo" bar}] [a foo])')
def test_ast_print():
code = hy_compile(tokenize("(print \"foo\")")).body[0]

View File

@ -637,6 +637,14 @@
(assert (= (foo 10 20 30) [10 (, 20 30) {}])))
(defn test-key-arguments []
"NATIVE: test &key function arguments"
(defn foo [&key {"a" None "b" 1}] [a b])
(assert (= (foo) [None 1]))
(assert (= (kwapply (foo) {"a" 2}) [2 1]))
(assert (= (kwapply (foo) {"b" 42}) [None 42])))
(defn test-quoted-hoistable []
"NATIVE: test quoted hoistable"
(setf f (quote (if true true true)))