hy/tests/lexer/test_list_lexing.py

45 lines
912 B
Python
Raw Normal View History

2012-12-16 00:20:15 +01:00
from hy.lex.tokenize import tokenize
def test_list_lex():
2012-12-16 00:24:40 +01:00
"""test basic lexing of lists"""
2012-12-16 00:20:15 +01:00
fn = tokenize("(fn [1 2 3 4])")[0]
assert fn == [
2012-12-17 03:44:14 +01:00
"fn", [1, 2, 3, 4]
2012-12-16 00:20:15 +01:00
]
2012-12-16 00:24:06 +01:00
def test_list_recurse():
2012-12-16 00:24:40 +01:00
""" test we can recurse lists """
2012-12-16 00:24:06 +01:00
fn = tokenize("(fn [1 2 3 4 [5 6 7]])")[0]
assert fn == [
2012-12-17 03:44:14 +01:00
"fn", [1, 2, 3, 4, [5, 6, 7]]
2012-12-16 00:24:06 +01:00
]
def test_double_rainbow():
2012-12-16 00:24:40 +01:00
""" DOUBLE LISTS """
2012-12-16 00:24:06 +01:00
fn = tokenize("(fn [1 2 3 4] [5 6 7])")[0]
assert fn == [
2012-12-17 03:44:14 +01:00
"fn", [1, 2, 3, 4], [5, 6, 7]
2012-12-16 00:24:06 +01:00
]
2012-12-16 00:38:34 +01:00
def test_string_in_list():
""" String in list """
fn = tokenize('(fn [1 2 "three four" 5])')[0]
assert fn == [
2012-12-17 03:44:14 +01:00
"fn", [1, 2, "three four", 5]
2012-12-16 00:38:34 +01:00
]
def test_list_recurse_with_comment():
""" test we can recurse lists """
fn = tokenize("""
(fn [1 ; this is a test
2 3 4 [5 6 7]])
""")[0]
assert fn == [
2012-12-17 03:44:14 +01:00
"fn", [1, 2, 3, 4, [5, 6, 7]]
2012-12-16 00:38:34 +01:00
]