Adding in some tests for print

This commit is contained in:
Paul Tagliamonte 2013-04-01 19:51:21 -04:00
parent b4ba4087df
commit 6831841699
2 changed files with 19 additions and 0 deletions

View File

@ -166,6 +166,14 @@ class HyASTCompiler(object):
@builds("print")
def compile_print_expression(self, expr):
expr.pop(0) # print
if sys.version_info[0] >= 3:
# AST changed with Python 3, we now just call it.
return ast.Call(
func=ast.Name(id='print', ctx=ast.Load()),
args=[self.compile(x) for x in expr],
lineno=expr.start_line,
col_offset=expr.start_column)
return ast.Print(
lineno=expr.start_line,
col_offset=expr.start_column,

View File

@ -20,7 +20,9 @@
from hy.compiler import hy_compile, HyCompileError
from hy.lex import tokenize
import ast
import sys
def _ast_spotcheck(arg, root, secondary):
@ -73,3 +75,12 @@ def test_ast_non_decoratable():
assert True == False
except TypeError:
pass
def test_ast_print():
""" Ensure print doesn't suck. """
code = hy_compile(tokenize("(print \"foo\")")).body[0]
if sys.version_info[0] >= 3:
assert type(code.value) == ast.Call
return
assert type(code) == ast.Print