hy/tests/macros/test_macro_processor.py

37 lines
1.0 KiB
Python
Raw Normal View History

2013-03-08 04:52:47 +01:00
from hy.macros import macro, process
from hy.models.expression import HyExpression
from hy.models.string import HyString
from hy.models.symbol import HySymbol
from hy.models.list import HyList
@macro("test")
def tmac(tree):
""" Turn an expression into a list """
return HyList(tree[1:])
def test_preprocessor_simple():
""" Test basic macro expantion """
obj = process(HyExpression(["test", "one", "two"]))
assert obj == HyList(["one", "two"])
assert type(obj) == HyList
def test_preprocessor_expression():
""" Test inner macro expantion """
obj = process(HyExpression([HySymbol("test"),
HyExpression([HySymbol("test"),
HyString("one"),
HyString("two")])]))
assert type(obj) == HyList
assert type(obj[0]) == HyList
assert obj[0] == HyList([HyString("one"), HyString("two")])
2013-03-08 05:04:20 +01:00
obj = HyList([HyString("one"), HyString("two")])
assert obj == process(obj)