hy/tests/macros/test_macro_processor.py
Paul Tagliamonte b78be9a594 Jank @olasd's hack, clean up core.
The core shall from now on be only for the core language bits. Macro
 bits shall live in hy.macros and in hy.compiler. This cleans up
 garbage.
2013-07-06 14:00:11 -04:00

38 lines
1.0 KiB
Python

from hy.macros import macro, process
from hy.lex import tokenize
from hy.models.string import HyString
from hy.models.list import HyList
from hy.models.symbol import HySymbol
from hy.models.expression import HyExpression
@macro("test")
def tmac(*tree):
""" Turn an expression into a list """
return HyList(tree)
def test_preprocessor_simple():
""" Test basic macro expansion """
obj = process(tokenize('(test "one" "two")')[0], __name__)
assert obj == HyList(["one", "two"])
assert type(obj) == HyList
def test_preprocessor_expression():
""" Test that macro expansion doesn't recurse"""
obj = process(tokenize('(test (test "one" "two"))')[0], __name__)
assert type(obj) == HyList
assert type(obj[0]) == HyExpression
assert obj[0] == HyExpression([HySymbol("test"),
HyString("one"),
HyString("two")])
obj = HyList([HyString("one"), HyString("two")])
obj = tokenize('(shill ["one" "two"])')[0][1]
assert obj == process(obj, '')