2013-03-08 04:52:47 +01:00
|
|
|
|
|
|
|
from hy.macros import macro, process
|
2013-03-09 00:46:51 +01:00
|
|
|
from hy.lex import tokenize
|
2013-03-08 04:52:47 +01:00
|
|
|
|
|
|
|
from hy.models.string import HyString
|
|
|
|
from hy.models.list import HyList
|
|
|
|
|
|
|
|
|
|
|
|
@macro("test")
|
2013-05-11 09:09:34 +02:00
|
|
|
def tmac(*tree):
|
2013-03-08 04:52:47 +01:00
|
|
|
""" Turn an expression into a list """
|
2013-05-11 09:09:34 +02:00
|
|
|
return HyList(tree)
|
2013-03-08 04:52:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_preprocessor_simple():
|
|
|
|
""" Test basic macro expantion """
|
2013-03-09 00:46:51 +01:00
|
|
|
obj = process(tokenize('(test "one" "two")')[0])
|
2013-03-08 04:52:47 +01:00
|
|
|
assert obj == HyList(["one", "two"])
|
|
|
|
assert type(obj) == HyList
|
|
|
|
|
|
|
|
|
|
|
|
def test_preprocessor_expression():
|
|
|
|
""" Test inner macro expantion """
|
2013-03-09 00:46:51 +01:00
|
|
|
obj = process(tokenize('(test (test "one" "two"))')[0])
|
2013-03-08 04:52:47 +01:00
|
|
|
|
|
|
|
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")])
|
2013-03-09 00:46:51 +01:00
|
|
|
obj = tokenize('(shill ["one" "two"])')[0][1]
|
2013-03-08 05:04:20 +01:00
|
|
|
assert obj == process(obj)
|