Merge branch 'jd/if' of git://github.com/jd/hy
This commit is contained in:
commit
6aebc5820f
@ -176,8 +176,10 @@ class HyASTCompiler(object):
|
|||||||
raise TypeError("if expects at least 2 arguments, got 1")
|
raise TypeError("if expects at least 2 arguments, got 1")
|
||||||
body = self._code_branch(self.compile(body))
|
body = self._code_branch(self.compile(body))
|
||||||
orel = []
|
orel = []
|
||||||
if len(expr) > 0:
|
if len(expr) == 1:
|
||||||
orel = self._code_branch(self.compile(expr.pop(0)))
|
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,
|
return ast.If(test=test,
|
||||||
body=body,
|
body=body,
|
||||||
|
@ -69,6 +69,15 @@ def test_ast_bad_if_1_arg():
|
|||||||
pass
|
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():
|
def test_ast_valid_if():
|
||||||
"Make sure AST can't compile invalid if"
|
"Make sure AST can't compile invalid if"
|
||||||
hy_compile(tokenize("(if foo bar)"))
|
hy_compile(tokenize("(if foo bar)"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user