hy/tests/lexer/test_basic_lexing.py

61 lines
1.2 KiB
Python
Raw Normal View History

2012-12-15 23:22:14 +01:00
from hy.lex.tokenize import tokenize
def test_simple_tokenize():
2012-12-15 23:31:23 +01:00
"""Checking we can still handle something simple."""
2012-12-15 23:22:14 +01:00
assert [["+", "1", "1"]] == tokenize("(+ 1 1)")
def test_double_tokenize():
2012-12-15 23:31:23 +01:00
"""Checking if we can lex two things at once."""
2012-12-15 23:22:14 +01:00
assert [
["+", "1", "2"],
["-", "1", "1"]
] == tokenize("(+ 1 2) (- 1 1)")
def test_simple_recurse():
2012-12-15 23:31:23 +01:00
""" Test recursion """
assert [
['fn',
'one',
['fn', 'two'],
]
] == tokenize("(fn one (fn two))")
def test_mid_recurse():
""" Test some crazy recursion """
2012-12-15 23:22:14 +01:00
assert [
2012-12-15 23:31:23 +01:00
['fn',
'one',
['fn', 'two'],
['fn', 'three'],
2012-12-15 23:22:14 +01:00
]
2012-12-15 23:31:23 +01:00
] == tokenize("(fn one (fn two)(fn three))")
def test_full_recurse():
""" Test something we could see for real """
assert [
['fn',
'el',
['+',
'1',
'2',
['==',
'1',
'20'
],
['-',
'1',
'1'
],
]
],
['fn1', 'foo', 'bar']
] == tokenize("(fn el (+ 1 2 (== 1 20) (- 1 1)))(fn1 foo bar)")