-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_parse.py
56 lines (55 loc) · 1.75 KB
/
test_parse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from smallscheme.dtypes import *
from smallscheme.parse import parse_str
from smallscheme.test_util import teq
def test_parse_str():
def t(a, b):
teq(parse_str(a)[0], b)
t("1234", int_(1234))
t("-1234", int_(-1234))
t("+1234", int_(1234))
t("3.1415", float_(3.1415))
t("+3.1415", float_(3.1415))
t("-3.1415", float_(-3.1415))
t("1", int_(1))
t("1;", int_(1))
t("1 ;; hello, I'm a comment", int_(1))
t("""1 ;; a comment and a newline
""", int_(1))
t("x", atom('x'))
t("y", atom('y'))
t("yxyz", atom('yxyz'))
t("#t", bool_(True))
t("#f", bool_(False))
t("(a)", list_([atom('a')]))
t("(a 1 2)", list_([atom('a'),
int_(1),
int_(2)]))
t("(+ 2 3)", list_([atom('+'),
int_(2),
int_(3)]))
t("(a 1 (b foo x3))",
list_([atom('a'),
int_(1),
list_([atom('b'),
atom('foo'),
atom('x3')])]))
t("(())", list_([list_([])]))
t("((a))", list_([list_([atom('a')])]))
t("((a b))", list_([list_([atom('a'),
atom('b')])]))
t("(a (b))", list_([("atom", "a"),
list_([("atom", "b")])]))
t("((a) b)", list_([list_([("atom", "a")]),
("atom", "b")]))
t("(a (b c) d)", list_([atom('a'),
list_([atom('b'),
atom('c')]),
atom('d')]))
t("(+ (* 2 4) (+ 3 5))",
list_([atom('+'),
list_([atom('*'),
int_(2),
int_(4)]),
list_([atom('+'),
int_(3),
int_(5)])]))