Fiddling with more AST testing
This commit is contained in:
parent
6eb6a0d24c
commit
a9b5d851b2
@ -25,6 +25,8 @@ from hy.models.symbol import HySymbol
|
|||||||
|
|
||||||
from hy.errors import HyError
|
from hy.errors import HyError
|
||||||
|
|
||||||
|
import ast
|
||||||
|
|
||||||
|
|
||||||
class HyCompileError(HyError):
|
class HyCompileError(HyError):
|
||||||
pass
|
pass
|
||||||
@ -56,8 +58,13 @@ class HyASTCompiler(HyCompiler):
|
|||||||
|
|
||||||
@builds(HyExpression)
|
@builds(HyExpression)
|
||||||
def compile_expression(self, expression):
|
def compile_expression(self, expression):
|
||||||
pass
|
return ast.Call(func=self.compile_symbol(expression[0]),
|
||||||
|
args=[self.compile(x) for x in expression[1:]],
|
||||||
|
keywords=[],
|
||||||
|
starargs=None,
|
||||||
|
kwargs=None)
|
||||||
|
|
||||||
|
|
||||||
@builds(HySymbol)
|
@builds(HySymbol)
|
||||||
def compile_symbol(self, symbol):
|
def compile_symbol(self, symbol):
|
||||||
pass
|
return ast.Name(id=str(symbol), ctx=ast.Load())
|
@ -18,11 +18,20 @@
|
|||||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
# DEALINGS IN THE SOFTWARE.
|
# DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
from hy.compilers.ast import HyASTCompiler
|
from hy.compilers.pyast import HyASTCompiler
|
||||||
from hy.lex import tokenize
|
from hy.lex import tokenize
|
||||||
import ast
|
import ast
|
||||||
|
|
||||||
|
|
||||||
|
def _ast_spotcheck(arg, root, secondary):
|
||||||
|
if "." in arg:
|
||||||
|
local, full = arg.split(".", 1)
|
||||||
|
return _ast_spotcheck(full,
|
||||||
|
getattr(root, local),
|
||||||
|
getattr(secondary, local))
|
||||||
|
assert getattr(root, arg) == getattr(secondary, arg)
|
||||||
|
|
||||||
|
|
||||||
def test_ast_expression_basics():
|
def test_ast_expression_basics():
|
||||||
""" Ensure basic AST expression conversion works. """
|
""" Ensure basic AST expression conversion works. """
|
||||||
compiler = HyASTCompiler()
|
compiler = HyASTCompiler()
|
||||||
@ -39,4 +48,5 @@ def test_ast_expression_basics():
|
|||||||
starargs=None,
|
starargs=None,
|
||||||
kwargs=None,
|
kwargs=None,
|
||||||
)
|
)
|
||||||
assert code == tree
|
_ast_spotcheck("func.id", code, tree)
|
||||||
|
_ast_spotcheck("id", code.args[0], tree.args[0])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user