-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ml
351 lines (335 loc) · 23.2 KB
/
test.ml
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
open Compile
open Runner
open Printf
open OUnit2
open Pretty
open Exprs
open Phases
open Errors
open Libtest
open Assembly
open Pretty
open Graph
let te ?input:(input="") name program expected_err = name>::test_err ~std_input:input ~vg:false Naive program name expected_err;;
let t name program input expected = name>::test_run_strats ~args:[] ~std_input:input ~skip_newline:true program name expected;;
let tr name program input expected = name>::test_run ~args:[] ~std_input:input ~skip_newline:true Register program name expected;;
let ta name program input expected = name>::test_run_anf ~args:[] ~std_input:input program name expected;;
let tgc name heap_size program input expected = name>::test_run ~args:[string_of_int heap_size] ~std_input:input ~skip_newline:true Naive program name expected;;
let tvg name program input expected = name>::test_run_valgrind ~args:[] ~std_input:input Naive program name expected;;
let tvgc name heap_size program input expected = name>::test_run_valgrind ~args:[string_of_int heap_size] ~std_input:input Naive program name expected;;
let terr name program input expected = name>::test_err ~args:[] ~std_input:input Naive program name expected;;
let tgcerr name heap_size program input expected = name>::test_err ~args:[string_of_int heap_size] ~std_input:input Naive program name expected;;
let tanf name program input expected = name>::fun _ ->
assert_equal expected (anf (tag program)) ~printer:string_of_aprogram;;
let tparse name program expected = name>::fun _ ->
assert_equal (untagP expected) (untagP (parse_string name program)) ~printer:string_of_program;;
let teq name actual expected = name>::fun _ ->
assert_equal expected actual ~printer:(fun s -> s);;
let builtins_size = 4 (* arity + 0 vars + codeptr + padding *) * (List.length Compile.native_fun_bindings)
let lexing_and_parsing = [
terr "unmatched_parens" "\"hello" "" "Unterminated string";
terr "unmatched_parens_second" "\"hello\"; \"" "" "Unterminated string";
]
let tstring = [
t "tstring_simple" "\"aa\"" "" "aa";
t "tstring_complex" "\"\"\"aaaa
aaaa\"\"\"" "" "aaaa\n aaaa";
t "tstring_quotes" "\"aaaa\\\"\"" ""
"aaaa\"";
t "tstring_encoded_newline" "\"aaaa\\naaaa\"" ""
"aaaa\naaaa";
t "tstring_carriage_return" "\"aaaa\raaaa\"" ""
"aaaa\raaaa";
t "tstring_encoded_carriage_return" "\"aaaa\\raaaa\"" ""
"aaaa\raaaa";
t "tstring_tag" "\"aaaa\taaaa\"" ""
"aaaa\taaaa";
t "tstring_question" "\"aaaa?\"" ""
"aaaa?";
t "input_test" "input()" "hello" "hello";
t "herestring" "let multiline = \"\"\"
\\t\" \"
this is a string
abcd
\"\"\" in multiline" ""
"\n\t\" \"\n this is a string\nabcd\n ";
te "herestring_in_string" "\" hello \"\"\" \"" "Herestring terminated in non-herestring literal";
t "escaped_herestring_in_string" "\" hello \\\"\\\"\\\" \"" "" " hello \"\"\" ";
te "broken_string" "\" \n \"" "Unterminated string literal";
te "unterminated_string" "\"" "Unterminated string";
te "unterminated_herestring" "\"\"\"" "Unterminated string";
t "tostring_return_fail" "let a = \"abcd\", b = \"efgh\", c = tostr(a), d = \"hijk\" in b" "" "efgh";
]
let tstring_wf = [
terr "tstring_illegal" "\"é\"" "" "String é at tstring_illegal, 1:3-1:4 contains at least one illegal character.";
terr "tstring_illegal_2" "\"€\"" "" "String € at tstring_illegal_2, 1:4-1:5 contains at least one illegal character.";
]
let long = "hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello
hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello
hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello
hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello
hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello
hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello
hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello
hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello
hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello
hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello
hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello
hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello"
;;
let long_oneline = ("hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" ^
"hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" ^
"hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" ^
"hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" ^
"hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" ^
"hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" ^
"hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" ^
"hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" ^
"hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" ^
"hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" ^
"hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello" ^
"hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello")
;;
let tstring_complex = [
t "very_long" ("\"\"\"" ^ long ^ "\"\"\"") "" long;
t "empty" "let s = \"\" in s" "" "";
t "big" "let s = \"~\" in s" "" "~";
t "tstring_in_let" "let s = \"test\" in s" "" "test";
t "string_in_tuple" "let s = \"test\" in (s, s, s)" "" "(\"test\", \"test\", \"test\")";
t "string_in_lambda_in_tuple" "let s = (lambda: \"test\") in (s(), s(), s())" "" "(\"test\", \"test\", \"test\")";
tgcerr "string_literal_too_big" (builtins_size + 1) "let a = \"a\" in a" "" "Out of memory";
]
let tstring_gc = [
tgc "tstring_gc_simple" (builtins_size + 2) "\"test\"" "" "test";
tgc "tstring_gc_repeat" (builtins_size + 2) "\"test\"; \"test\"; \"tesc\"; \"tesh\"" "" "tesh";
tgc "tstring_gc_odd" (builtins_size + 6) "let a = \"a\" in let b = \"b\"; \"c\" in let c = \"c\" in a" "" "a";
tgc "tstring_gc_lambda" (builtins_size + 8) "let a = \"a\" in let b = (lambda: print(\"ccccc\")) in b(); print(\"aaaaa\"); a" "" "cccccaaaaaa";
]
let conversions_and_istype = [
t "isstr_str" "isstr(\"hello\")" "" "true";
t "isstr_num" "isstr(5)" "" "false";
t "isstr_bool_t" "isstr(true)" "" "false";
t "isstr_bool_f" "isstr(false)" "" "false";
t "isstr_tuple" "isstr((1, 2, 3))" "" "false";
t "isnum_str" "isnum(\"1\")" "" "false";
t "isbool_str" "isnum(\"true\")" "" "false";
t "istuple_str" "istuple(\"1\")" "" "false";
t "istuple_nil" "istuple(nil)" "" "true";
t "isstr_nil" "isstr(nil)" "" "false";
t "isnum_nil" "isnum(nil)" "" "false";
t "isbool_nil" "isbool(nil)" "" "false";
t "tonum_int" "tonum(1) + 0" "" "1";
t "tonum_str" "tonum(\"1\") + 0" "" "1";
t "tonum_bool_f" "tonum(false) + 0" "" "0";
t "tonum_bool_t" "tonum(true) + 0" "" "1";
te "tonum_nil" "tonum(nil)" "conversion function received invalid value";
te "tonum_invalid_str" "tonum(\"a\")" "Error 18: Error: conversion function received invalid value";
t "tonum_empty_str" "tonum(\"\") + 0" "" "0";
t "tobool_bool_f" "tobool(false) && false" "" "false";
t "tobool_nil" "tobool(nil)" "" "false";
t "tobool_bool_t" "tobool(true) || false" "" "true";
t "tobool_num_0" "tobool(0) || false" "" "false";
t "tobool_num_1" "tobool(1) || false" "" "true";
t "tobool_num_5" "tobool(5) || false" "" "true";
t "tobool_str_t" "tobool(\"true\") || false" "" "true";
t "tobool_str_f" "tobool(\"false\") || false" "" "false";
t "tobool_other_str" "tobool(\"a\")" "" "true";
t "tobool_empty_str" "tobool(\"\")" "" "false";
t "tobool_tuple_empty" "tobool(nil)" "" "false";
t "tobool_tuple_not_empty" "tobool((1,))" "" "true";
t "tostr_str" "tostr(\"hello\")" "" "hello";
t "tostr_nil" "tostr(nil)" "" "nil";
t "tostr_bool_f" "tostr(false)" "" "false";
t "tostr_bool_t" "tostr(true)" "" "true";
t "tostr_num" "tostr(5)" "" "5";
te "tostr_bool_f_err" "tostr(false) || false" "Error 3: Error: expected a boolean, got \"false\"";
te "tostr_bool_t_err" "tostr(true) || false" "Error 3: Error: expected a boolean, got \"true\"";
te "tostr_num_err" "tostr(5) + 0" "Error 2: Error: arithmetic expected a number, got \"5\"";
t "tostr_tuple" "tostr((1, 2, 3))" "" "<tuple>";
t "tonum_str_neg" "tonum(\"-5\") * 1" "" "-5";
te "tonum_tuple" "tonum((1, 2))" "conversion function received invalid value";
t "tonum_str_neg_only" "tonum(\"-\")" "" "0";
t "tostr_neg" "tostr(-5)" "" "-5";
te "tostr_neg_err" "tostr(-5) * 1" "Error 2: Error: arithmetic expected a number, got \"-5\"";
t "totuple_num_1" "tuple(1)" "" "(0, )";
t "len_nil" "len(nil)" "" "0";
t "len_one" "len(tuple(1))" "" "1";
t "totuple_num_5" "tuple(5)" "" "(0, 0, 0, 0, 0)";
t "len_totuple_5" "len(tuple(5))" "" "5";
te "totuple_bool" "tuple(false)" "Tuple creation expected num";
te "totuple_str_empty" "tuple(\"\")" "Tuple creation expected num";
te "ascii_tuple_to_str_invalid_tuple" "ascii_tuple_to_str((128, ))" "Given char ascii value is invalid";
te "ascii_tuple_to_str_invalid_tuple_neg" "ascii_tuple_to_str((-1, ))" "Given char ascii value is invalid";
te "ascii_tuple_to_str_invalid_tuple_bool" "ascii_tuple_to_str((97, false))" "Given char ascii value is invalid";
te "ascii_tuple_to_str_invalid_tuple_nested_str" "ascii_tuple_to_str((97, \"hello\"))" "Given char ascii value is invalid";
te "ascii_tuple_to_str_invalid_tuple_nested_tuple" "ascii_tuple_to_str((97, (1, 2, 3)))" "Given char ascii value is invalid";
t "input_invalid_char" "input()" "é" "C)";
t "streqeqf" "\"asdf\" == \"asdf\"" "" "false";
t "streqeqt" "let a = \"asdf\" in a == a" "" "true";
t "streqeqt_2" "let a = \"asdf\" in 5 == a" "" "false";
t "streq_1" "equal(\"asdf\", \"asdf\")" "" "true";
t "streq_2" "equal(\"asdf\", \"asdh\")" "" "false";
t "streq_3" "equal(5, \"a\")" "" "false";
t "streq_4" "equal(\"a\", 5)" "" "false";
t "streq_5" "equal(\"false\", false)" "" "false";
t "streq_6" "equal(true, \"true\")" "" "false";
t "streq_7" "equal((0, 1), \"a\")" "" "false";
t "streq_8" "equal(\"a\", (0, 1))" "" "false";
t "streq_9" "equal(\"a\", \"b\")" "" "false";
t "string_edit" "let str = print(\"hello!\"), tup = print(str_to_ascii_tuple(str)), _ = tup[0] := 97, res = ascii_tuple_to_str(print(tup)) in res" ""
"hello!(104, 101, 108, 108, 111, 33)(97, 101, 108, 108, 111, 33)aello!";
t "many_conversions" "ascii_tuple_to_str(str_to_ascii_tuple(tostr(tobool(tonum(len(str_to_ascii_tuple(\"hello\" ^ \"world\")))))))" "" "true";
t "get_char" "get_ascii_char(\"a\", 0)" "" "97";
te "get_char_high" "get_ascii_char(\"a\", 1)" "index too large to get";
te "get_char_low" "get_ascii_char(\"a\", -1)" "index too small to get";
t "get_char_long" "get_ascii_char(\"abcd\", 3)" "" "100";
te "get_char_not_str" "get_ascii_char(false, 3)" "Value not a string";
te "get_char_not_num" "get_ascii_char(\"false\", \"a\")" "substring expected num";
t "print_newlines" "print(\"hello\\nworld\")" "" "hello\nworldhello\nworld"
]
let tconcat = [
terr "incorrect_type_1" "5 ^ \"\"" "" "Value not a string, got 5";
terr "incorrect_type_2" "\"\" ^ 15" "" "Value not a string, got 15";
terr "incorrect_type_both" "12 ^ 12" "" "Value not a string, got 12";
t "concat_empty" "\"\" ^ \"\"" "" "";
t "concat_first" "\"a\" ^ \"\"" "" "a";
t "concat_second" "\"\" ^ \"b\"" "" "b";
t "concat_both" "\"a\" ^ \"b\"" "" "ab";
t "concat_complex" "\"abc\" ^ \"def\" ^ \"ghijkl\"" "" "abcdefghijkl";
t "concat_let" "let a = \"abc\", b = \"def\", c = \"ghijkl\" in a ^ b ^ c" "" "abcdefghijkl";
t "concat_let_2" "let a = \"abc\", b = \"def\", c = \"ghijkl\" in let d = a ^ b ^ c in d ^ a" "" "abcdefghijklabc";
t "concat_equality" "let a = \"abc\" in equal(a ^ a, a ^ a)" "" "true";
t "concat_equality_2" "let a = \"abc\", b = \"abc\" in equal(a ^ b, b ^ a)" "" "true";
tgc "concat_gc" (builtins_size + 10) "let a = (lambda: print(\"123456\")) in (a(); \"abc\" ^ \"def\")" "" "123456abcdef";
]
let tsubstr = [
terr "substr_of_nonstring" "5[1:3]" "" "Value not a string, got 5";
terr "substr_of_backwards" "\"hi\"[1:0]" "" "substring index out of bounds of string \"hi\"";
terr "substr_oob_lower_low" "\"hi\"[-1:1]" "" "substring index out of bounds of string \"hi\"";
terr "substr_oob_lower_high" "\"hi\"[3:3]" "" "substring index out of bounds of string \"hi\"";
terr "substr_oob_higher_high" "\"hi\"[0:3]" "" "substring index out of bounds of string \"hi\"";
t "substr_same" "\"hi\"[0:2]" "" "hi";
t "substr_first" "\"hi\"[0:1]" "" "h";
t "substr_middle" "\"hello friends\"[1:5]" "" "ello";
t "substr_empty" "\"hello friends\"[1:1]" "" "";
t "substr_exprs" "\"hello friends\"[1 - 1:1 + 2]" "" "hel";
t "substr_let" "let a = \"hello friends\" in a[1 - 1: 1 + 2]" "" "hel";
t "substr_equality" "let a = \"hello friends\" in equal(a[0:2], a[0:2])" "" "true";
t "substr_eqeq" "let a = \"hello friends\" in a[0: 2] == a[0: 2]" "" "false";
te "substr_tuple_access" "\"hello\"[3]" "get expected tuple";
te "tuple_substr_access" "(1, 2, 3)[0:1]" "Value not a string";
tgc "substr_gc" (builtins_size + 8)
"let a = \"abcd\", b = (lambda: print(\"efgh\")), _ = b() in a[0:2]"
"" "efghab";
]
let format = [
t "format_empty" "format()" "" "";
t "format_smaller" "format(\"{}\", 1)" "" "1";
t "format_no_subst" "format(\"hello world\")" "" "hello world";
t "format_one_subst" "format(\"my name is {}\", \"conner nilsen\")" "" "my name is conner nilsen";
t "format_two_subst" "format(\"my name is {} {}\", \"kyle\", \"into\")" "" "my name is kyle into";
t "format_other_types" "format(\"{} {} {} {}\", true, false, 5, -3)" "" "true false 5 -3";
te "format_error_low" "format(\"{}\")" "incorrect arity for format replacement values";
te "format_error_low_2" "format(\"{}{}\", 5)" "incorrect arity for format replacement values";
te "format_error_high" "format(\"abcd\", 1)" "incorrect arity for format replacement values";
tgc "format_gc" (builtins_size + 16)
"let a = (lambda: print(\"efgh\")), _ = a() in format(\"{}\", 1)"
"" "efgh1";
]
let len = [
t "str_len_empty" "len(\"\")" "" "0";
t "tuple_len_1" "len((5, ))" "" "1";
t "str_len_1" "len(\"a\")" "" "1";
t "tuple_len_2" "len((5, 4))" "" "2";
t "str_len_2" "len(\"ab\")" "" "2";
te "len_bool" "len(true)" "len expected tuple or num, got true";
te "len_num" "len(5)" "len expected tuple or num, got 5";
]
let split_tests = [
t "split_empty_empty" "\"\".split(\"\")" "" "(\"\", )";
t "split_empty_not_there" "\"\".split(\"f\")" "" "(\"\", )";
t "split_miss" "\"hi\".split(\"f\")" "" "(\"hi\", )";
t "split_empty" "\"hi\".split(\"\")" "" "(\"h\", \"i\")";
t "split_space" "\"hi friends i'm kyle\".split(\" \")" "" "(\"hi\", \"friends\", \"i'm\", \"kyle\")";
t "split_multiple" "\"hiabcfriendsabci'mabckyle\".split(\"abc\")" "" "(\"hi\", \"friends\", \"i'm\", \"kyle\")";
t "split_lets" "let s1 = \"hiabcfriendsabci'mabckyle\", s2 = \"abc\" in s1.split(s2)" "" "(\"hi\", \"friends\", \"i'm\", \"kyle\")";
t "split_empty_char" "\"no\".split(\"n\")" "" "(\"\", \"o\")";
terr "split_nonstring" "5.split(\" .z\")" "" "unable to split non-string 5";
terr "split_nonstring_2" "\"\".split(5)" "" "unable to split non-string 5";
t "split_first_last" "\"abchelloabcworldabc\".split(\"abc\")" "" "(\"\", \"hello\", \"world\", \"\")";
t "split_first_almost_last" "\"abchelloabcworldabcn\".split(\"abc\")" "" "(\"\", \"hello\", \"world\", \"n\")";
t "split_almost_delim" "\"abcbacabbcabcacbbcaabc\".split(\"abc\")" "" "(\"\", \"bacabbc\", \"acbbca\", \"\")";
]
let join_tests = [
t "join_empty_empty" "\"\".join(())" "" "";
t "join_delim_empty" "\"f\".join(())" "" "";
t "join_empty_delim" "\"\".join((\"hello\", \"hi\"))" "" "hellohi";
t "join_single" "\" \".join((\"hello\", ))" "" "hello";
t "join_space" "\" \".join((\"hello\", \"hi\"))" "" "hello hi";
t "join_long" "\" \".join((\"hello\", \"hi\",\"hello\", \"hi\",\"hello\", \"hi\",\"hello\", \"hi\"))" "" "hello hi hello hi hello hi hello hi";
t "join_newline" "\"\\n\".join((\"hello\", \"hi\"))" "" "hello\nhi";
t "join_lets" "let delim = \" \", t = (\"hello\", \"hi\") in delim.join(t)" "" "hello hi";
terr "join_nonstring" "5.join((\"hello\", \"hi\"))" "" "unable to join non-string 5";
terr "join_nonstring_2" "5.join((5, ))" "" "unable to join non-string 5";
terr "join_nontuple" "\"\".join(5)" "" "unable to join non-tuple 5";
]
let integration_tests = [
terr "plus_string" "\"hello\" + 6" "" "arithmetic expected a number";
terr "plus_strings" "\"hello\" + \"hi\"" "" "arithmetic expected a number";
terr "g_strings" "\"hello\" > \"hi\"" "" "comparison expected a number";
terr "le_strings" "\"hello\" <= \"hi\"" "" "comparison expected a number";
terr "ge_strings" "\"hello\" >= \"hi\"" "" "comparison expected a number";
terr "l_strings" "\"hello\" < \"hi\"" "" "comparison expected a number";
terr "minus_strings" "\"hello\" - \"hi\"" "" "arithmetic expected a number";
terr "times_strings" "\"hello\" * \"hi\"" "" "arithmetic expected a number";
terr "add1_strings" "add1(\"hello\")" "" "arithmetic expected a number";
terr "sub1_strings" "sub1(\"hello\")" "" "arithmetic expected a number";
]
let contains_tests = [
te "contains_invalid_body" "contains(5, \"\")" "not a string";
te "contains_invalid_val" "contains(\"\", 5)" "not a string";
t "contains_empty" "contains(\"\", \"\")" "" "true";
t "contains_empty_2" "contains(\"\", \"a\")" "" "false";
t "contains_empty_3" "contains(\"abcd\", \"\")" "" "true";
t "contains_full" "contains(\"hello\", \"hello\")" "" "true";
t "contains_part" "contains(\"hello\", \"lo\")" "" "true";
t "contains_part_2" "contains(\"hello\", \"lll\")" "" "false";
t "contains_incr" "contains(\"a aa aaa aaaa aaaaa\", \"aaaaa\")" "" "true";
t "contains_incr_2" "contains(\"a aa aaa aaaa aaaaa\", \"aaaaaa\")" "" "false";
]
let input_tests = [
t "input_basic" "input()" "hello" "hello";
t "input_reserve_after" "let a = input(), b = \"abcd\" in a ^ b" "hello" "helloabcd";
t "input_long" "let a = input() in a" long_oneline long_oneline;
tgc "input_force_alloc" (builtins_size + 6)
"let a = (lambda: print(\"abcd\")), _ = a(), c = input() in c"
"efgh" "abcdefgh";
tgc "input_almost_too_long" (builtins_size + 2) "input()" "abcdef" "abcdef";
tgcerr "input_too_long" (builtins_size + 2) "input()" "abcdefg" "out of memory";
tgc "gc_after_input" (builtins_size + 6)
"let a = (lambda: print(input())), _ = a(), c = \"efgh\" in c"
"abcd" "abcdefgh";
]
let suite =
"unit_tests">:::
lexing_and_parsing
@ tstring
@ conversions_and_istype
@ tstring_wf
@ tstring_complex
@ tstring_gc
@ tconcat
@ tsubstr
@ format
@ len
@ split_tests
@ join_tests
@ integration_tests
@ contains_tests
@ input_tests
let () =
run_test_tt_main ("all_tests">:::[
suite;
old_tests;
])
;;