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
/
004parenthesize.test.cc
280 lines (226 loc) · 7.93 KB
/
004parenthesize.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
void test_parenthesize_handles_initial_comment() {
read_all("#a\na b");
CHECK_TRACE_CONTENTS("parenthesize", "(ab)");
}
void test_parenthesize_handles_lines_with_initial_parens() {
read_all("(a b c)");
CHECK_TRACE_CONTENTS("parenthesize", "(abc)");
}
void test_parenthesize_handles_lines_with_initial_parens2() {
read_all("(a (b c))");
CHECK_TRACE_CONTENTS("parenthesize", "(a(bc))");
}
void test_parenthesize_skips_indent_tokens() {
read_all(" (a\tb c)");
CHECK_TRACE_CONTENTS("parenthesize", "(abc)");
}
void test_parenthesize_skips_outdent_tokens() {
read_all("(a b c\n bc\n def\n gh)");
CHECK_TRACE_CONTENTS("parenthesize", "(abcbcdefgh)");
}
void test_parenthesize_preserves_following_indent() {
indent_sensitive_stream in("a\n b");
next_expr(in);
CHECK_EQ(in.fd.peek(), ' ');
}
void test_parenthesize_handles_fully_parenthesized_expressions_regardless_of_indent() {
read_all("(a b c\n (def gh)\n (i j k)\n lm\n\n\n (no p))");
CHECK_TRACE_CONTENTS("parenthesize", "(abc(defgh)(ijk)lm(nop))");
}
void test_parenthesize_passes_through_single_word_lines() {
read_all("a");
CHECK_TRACE_CONTENTS("parenthesize", "a");
}
void test_parenthesize_passes_through_single_word_lines2() {
read_all("a \nb\nc");
CHECK_TRACE_CONTENTS("parenthesize", "abc");
}
void test_parenthesize_groups_words_on_single_line() {
read_all("a b c ");
CHECK_TRACE_CONTENTS("parenthesize", "(abc)");
}
void test_parenthesize_groups_words_on_single_line2() {
read_all("a (b c)");
CHECK_TRACE_CONTENTS("parenthesize", "(a(bc))");
}
void test_parenthesize_groups_words_on_single_line3() {
read_all("a (b c) d");
CHECK_TRACE_CONTENTS("parenthesize", "(a(bc)d)");
}
void test_parenthesize_groups_words_on_single_line4() {
read_all("a `(b c)");
CHECK_TRACE_CONTENTS("parenthesize", "(a`(bc))");
}
void test_parenthesize_passes_through_words_on_single_line() {
read_all("(a () b)");
CHECK_TRACE_CONTENTS("parenthesize", "(a()b)");
}
void test_parenthesize_groups_words_on_accidentally_indented_line() {
read_all(" a b c");
CHECK_TRACE_CONTENTS("parenthesize", "(abc)");
}
void test_parenthesize_groups_quoted_words() {
read_all(",a b c");
CHECK_TRACE_CONTENTS("parenthesize", "(,abc)");
}
void test_parenthesize_groups_quoted_words2() {
read_all(",@a b c");
CHECK_TRACE_CONTENTS("parenthesize", "(,@abc)");
}
void test_parenthesize_groups_quoted_words3() {
read_all("'a b c");
CHECK_TRACE_CONTENTS("parenthesize", "('abc)");
}
void test_parenthesize_passes_through_nested_quoted_words() {
read_all("a b\n 'c\n ,d\n e");
CHECK_TRACE_CONTENTS("parenthesize", "(abc,de)");
}
void test_parenthesize_passes_through_quoted_groups() {
read_all(",(a b c)");
CHECK_TRACE_CONTENTS("parenthesize", ",(abc)");
}
void test_parenthesize_passes_through_quoted_groups2() {
read_all(",@(a b c)");
CHECK_TRACE_CONTENTS("parenthesize", ",@(abc)");
}
void test_parenthesize_passes_through_quoted_groups3() {
read_all(",,(a b c)");
CHECK_TRACE_CONTENTS("parenthesize", ",,(abc)");
}
void test_parenthesize_groups_words_on_single_indented_line() {
read_all(" a b c\n 34");
CHECK_TRACE_CONTENTS("parenthesize", "(abc)34");
}
void test_parenthesize_groups_words_on_each_line_without_indent() {
read_all("a b c \nd ef");
CHECK_TRACE_CONTENTS("parenthesize", "(abc)(def)");
}
void test_parenthesize_groups_across_indent() {
read_all("a b c \n d ef");
CHECK_TRACE_CONTENTS("parenthesize", "(abc(def))");
}
void test_parenthesize_groups_across_indent2() {
read_all("a b c \n (d ef)");
CHECK_TRACE_CONTENTS("parenthesize", "(abc(def))");
}
void test_parenthesize_groups_across_indent3() {
read_all("a b c \n (d ef)\n\n g");
CHECK_TRACE_CONTENTS("parenthesize", "(abc(def)g)");
}
void test_parenthesize_groups_nested_indents() {
read_all("a b c\n d e\n f\ny");
CHECK_TRACE_CONTENTS("parenthesize", "(abc(def))y");
}
void test_parenthesize_handles_quotes_and_comments() {
read_all("a b c \n '(d ef)\n\n g #abc");
CHECK_TRACE_CONTENTS("parenthesize", "(abc'(def)g)");
}
void test_parenthesize_takes_indent_from_colon() {
read_all("a b c \n d ef\n : g");
CHECK_TRACE_CONTENTS("parenthesize", "(abc(def)g)");
}
void test_parenthesize_groups_before_outdents() {
read_all("a b c \n d ef\n\n g #abc");
CHECK_TRACE_CONTENTS("parenthesize", "(abc(def)g)");
}
void test_parenthesize_groups_before_outdents2() {
read_all("def foo\n a b c\n d e\nnewdef");
CHECK_TRACE_CONTENTS("parenthesize", "(deffoo(abc)(de))newdef");
}
void test_parenthesize_groups_before_too_much_outdent() {
read_all(" a a\n a\ny");
CHECK_TRACE_CONTENTS("parenthesize", "(aaa)y");
}
void test_parenthesize_groups_across_comments() {
read_all("def foo\n#a b c\n d e\nnew");
CHECK_TRACE_CONTENTS("parenthesize", "(deffoo(de))new");
}
void test_parenthesize_does_not_group_inside_parens() {
read_all("(def foo\n #a b c\n d e)\nnew");
CHECK_TRACE_CONTENTS("parenthesize", "(deffoode)new");
}
void test_parenthesize_does_not_group_inside_parens2() {
read_all("`(def foo\n #a b c\n d e)\nnew");
CHECK_TRACE_CONTENTS("parenthesize", "`(deffoode)new");
}
void test_parenthesize_does_not_group_inside_parens3() {
read_all(" (a b c\n d e)");
CHECK_TRACE_CONTENTS("parenthesize", "(abcde)");
}
void test_parenthesize_does_not_group_inside_arglists() {
read_all("def foo(a (b)\n c d)\n d e\nnew");
CHECK_TRACE_CONTENTS("parenthesize", "(deffoo(a(b)cd)(de))new");
}
void test_next_expr_passes_through_unbalanced_open_paren() {
indent_sensitive_stream in("(");
next_expr(in);
CHECK_TRACE_CONTENTS("parenthesize", "(");
}
void test_parenthesize_errors_on_unbalanced_closed_paren() {
Hide_warnings = true;
indent_sensitive_stream in(")");
next_expr(in);
CHECK_TRACE_WARNS();
}
void test_parenthesize_handles_early_paren() {
read_all("a (b)");
CHECK_TRACE_CONTENTS("parenthesize", "(a(b))");
}
void test_parenthesize_handles_multiple_exprs_on_a_line() {
read_all("() 1 2");
CHECK_TRACE_CONTENTS("parenthesize", "()12");
}
void test_parenthesize_breaks_at_empty_lines_when_interactive() {
read_all("a b\n\n c");
CHECK_TRACE_CONTENTS("parenthesize", "(abc)");
CLEAR_TRACE;
Interactive = true;
read_all("a b\n\n c");
CHECK_TRACE_CONTENTS("parenthesize", "(ab)");
}
void test_parenthesize_breaks_indent_at_empty_lines_when_interactive() {
read_all("a b\n c\n\n d");
CHECK_TRACE_CONTENTS("parenthesize", "(abcd)");
CLEAR_TRACE;
Interactive = true;
read_all("a b\n c\n\n d");
CHECK_TRACE_CONTENTS("parenthesize", "(abc)");
}
void test_parenthesize_refuses_to_group_from_middle_of_line() {
indent_sensitive_stream in("a b\n c\n");
next_expr(in);
CHECK_TRACE_CONTENTS("parenthesize", "(abc)");
rewind(in);
in.at_start_of_line = false;
CLEAR_TRACE;
next_expr(in);
CHECK_TRACE_CONTENTS("parenthesize", "a");
CLEAR_TRACE;
next_expr(in);
CHECK_TRACE_CONTENTS("parenthesize", "b");
CLEAR_TRACE;
next_expr(in);
CHECK_TRACE_CONTENTS("parenthesize", "c");
}
void test_parenthesize_resets_stream_after_multiple_exprs_in_a_line() {
indent_sensitive_stream in("() a\nc d");
next_expr(in);
CHECK_TRACE_CONTENTS("parenthesize", "()");
next_expr(in);
CHECK_TRACE_CONTENTS("parenthesize", "a");
next_expr(in);
CHECK_TRACE_CONTENTS("parenthesize", "(cd)");
}
void test_parenthesize_handles_multiline_parenthesized_exprs_when_interactive() {
read_all("(a b\n)\n");
CHECK_TRACE_CONTENTS("parenthesize", "(ab)");
CLEAR_TRACE;
Interactive = true;
read_all("(a b\n)\n");
CHECK_TRACE_CONTENTS("parenthesize", "(ab)");
}
void rewind(indent_sensitive_stream& in) {
in.fd.clear();
in.fd.seekg(0);
in.at_start_of_line = true;
}