This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
014build.test.cc
136 lines (117 loc) · 4.08 KB
/
014build.test.cc
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
void test_build_handles_nil() {
read_all("()");
CHECK_TRACE_CONTENTS("cell", "nil");
}
void test_build_handles_nil2() {
read_all("nil");
CHECK_TRACE_CONTENTS("cell", "nil");
}
void test_build_handles_integer() {
read_all("34");
CHECK_TRACE_CONTENTS("cell", "num: 34");
}
void test_build_handles_float() {
read_all("3.4");
CHECK_TRACE_CONTENTS("cell", "float: 3.4");
}
void test_build_warns_on_ambiguous_float() {
Hide_warnings = true;
read_all("-.4");
CHECK_TRACE_WARNS();
CHECK_TRACE_CONTENTS("cell", "float: -0.4");
}
void test_build_creates_floats_on_overflow() {
Hide_warnings = true;
read_all("100000000000000000000");
CHECK_TRACE_WARNS();
CHECK_TRACE_CONTENTS("cell", "float: 1e+20");
}
void test_build_handles_sym() {
read_all("a");
CHECK_TRACE_CONTENTS("cell", "sym: a");
}
void test_build_handles_string() {
read_all("\"a\"");
CHECK_TRACE_CONTENTS("cell", "string: \"a\"");
}
void test_build_doesnt_mix_syms_and_strings() {
TEMP(s, mkref(new_string("a")));
CHECK(s != new_sym("a"));
}
void test_build_handles_quoted_sym() {
TEMP(c, read("'a"));
CHECK_TRACE_CONTENTS("cell", 1, "'a");
CHECK_TRACE_CONTENTS("cell", 2, "sym: 'sym: a");
CHECK_EQ(car(c), new_sym("'"));
CHECK_EQ(cdr(c), new_sym("a"));
}
void test_build_handles_nested_quote() {
read_all("',a");
CHECK_TRACE_CONTENTS("cell", 1, "',a");
CHECK_TRACE_CONTENTS("cell", 2, ",a");
CHECK_TRACE_CONTENTS("cell", 3, "sym: a");
CHECK_TRACE_CONTENTS("cell", /*any frame*/ "sym: 'sym: ,sym: a");
}
void test_build_handles_multiple_atoms() {
read_all("34\n35");
CHECK_TRACE_CONTENTS("cell", "num: 34num: 35");
}
void test_build_handles_form() {
read_all("(34 35)");
CHECK_TRACE_CONTENTS("cell", 2, "(34 35)");
CHECK_TRACE_CONTENTS("cell", 3, "(35)");
CHECK_TRACE_CONTENTS("cell", 4, "nil");
CHECK_TRACE_CONTENTS("cell", /*any frame*/ "num: 34num: 35");
}
void test_build_handles_dotted_list() {
read_all("(34 ... 35)");
CHECK_TRACE_CONTENTS("cell", 2, "(34 ... 35)");
CHECK_TRACE_CONTENTS("cell", 3, "num: 35");
CHECK_TRACE_CONTENTS("cell", /*any frame*/ "num: 34num: 35");
}
void test_build_handles_literal_ellipses() {
TEMP(c, read("'..."));
CHECK_TRACE_TOP("cell", "'...");
CHECK_EQ(car(c), new_sym("'"));
CHECK_EQ(cdr(c), new_sym("..."));
}
void test_build_handles_nested_form() {
read_all("(3 7 (33 23))");
CHECK_TRACE_CONTENTS("cell", 2, "(3 7 (33 23))");
CHECK_TRACE_CONTENTS("cell", 3, "(7 (33 23))");
CHECK_TRACE_CONTENTS("cell", 4, "((33 23))");
CHECK_TRACE_CONTENTS("cell", 5, "nil");
CHECK_TRACE_CONTENTS("cell", /*any frame*/ "num: 3num: 7num: 33num: 23(33 23)");
}
void test_build_handles_strings() {
read_all("(3 7 (33 \"abc\" 23))");
CHECK_TRACE_CONTENTS("cell", 2, "(3 7 (33 \"abc\" 23))");
CHECK_TRACE_CONTENTS("cell", /*any frame*/ "string: \"abc\"");
}
void test_build_handles_syms() {
read_all("(3 7 (33 \"abc\" 3de 23))");
CHECK_TRACE_TOP("cell", "(3 7 (33 \"abc\" 3de 23))");
CHECK_TRACE_CONTENTS("cell", 2, "(3 7 (33 \"abc\" 3de 23))");
CHECK_TRACE_CONTENTS("cell", /*any frame*/ "sym: 3de");
}
void test_build_handles_quotes() {
read_all("`(34 ,(35) ,36 ,@37 ,'(a))");
CHECK_TRACE_CONTENTS("cell", 1, "`(34 ,(35) ,36 ,@37 ,'(a))");
CHECK_TRACE_CONTENTS("cell", 2, "(34 ,(35) ,36 ,@37 ,'(a))");
CHECK_TRACE_CONTENTS("cell", 4, "(,(35) ,36 ,@37 ,'(a))");
CHECK_TRACE_CONTENTS("cell", 5, "(,36 ,@37 ,'(a))");
CHECK_TRACE_CONTENTS("cell", 6, "(,@37 ,'(a))");
CHECK_TRACE_CONTENTS("cell", 7, "(,'(a))");
CHECK_TRACE_CONTENTS("cell", 8, "nil");
CHECK_TRACE_CONTENTS("cell", /*any frame*/ "sym: `num: 34sym: ,num: 35sym: ,num: 36sym: ,@num: 37sym: ,sym: 'sym: a");
}
void test_build_handles_indented_wrapped_lines() {
read_all("a\n (a b c\n d e)");
CHECK_TRACE_TOP("cell", "sym: a(a b c d e)");
CHECK_TRACE_CONTENTS("cell", 2, "(a b c d e)");
CHECK_TRACE_CONTENTS("cell", 3, "(b c d e)");
CHECK_TRACE_CONTENTS("cell", 4, "(c d e)");
CHECK_TRACE_CONTENTS("cell", 5, "(d e)");
CHECK_TRACE_CONTENTS("cell", 6, "(e)");
CHECK_TRACE_CONTENTS("cell", 7, "nil");
}