Merge branch 'jd/if' of git://github.com/jd/hy

This commit is contained in:
Paul R. Tagliamonte 2013-04-06 08:18:13 -04:00
commit 6aebc5820f
2 changed files with 12 additions and 1 deletions

View File

@ -176,8 +176,10 @@ class HyASTCompiler(object):
raise TypeError("if expects at least 2 arguments, got 1")
body = self._code_branch(self.compile(body))
orel = []
if len(expr) > 0:
if len(expr) == 1:
orel = self._code_branch(self.compile(expr.pop(0)))
elif len(expr) > 1:
raise TypeError("if expects 2 or 3 arguments, got %d" % (len(expr) + 2))
return ast.If(test=test,
body=body,

View File

@ -69,6 +69,15 @@ def test_ast_bad_if_1_arg():
pass
def test_ast_bad_if_too_much_arg():
"Make sure AST can't compile invalid if"
try:
hy_compile(tokenize("(if 1 2 3 4 5)"))
assert False
except TypeError:
pass
def test_ast_valid_if():
"Make sure AST can't compile invalid if"
hy_compile(tokenize("(if foo bar)"))