-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcoverage_improvement_comprehensive_test.mbt
More file actions
475 lines (439 loc) · 11.6 KB
/
Copy pathcoverage_improvement_comprehensive_test.mbt
File metadata and controls
475 lines (439 loc) · 11.6 KB
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
///| Comprehensive coverage improvement tests for TOML parser
///| This file targets uncovered code paths to improve test coverage
///|
/// Test EOF handling in parser - covered by creating empty token arrays
test "parser_eof_handling" {
// Test empty parse input to exercise EOF conditions
let result = @toml.parse(
(
#|
),
)
debug_inspect(
result,
content=(
#|TomlTable({})
),
)
}
///|
/// Test integer keys in inline tables
test "inline_table_with_integer_key" {
let toml_input = "table = {123 = \"value\"}"
let result = @toml.parse(toml_input)
debug_inspect(
result,
content=(
#|TomlTable({ "table": TomlTable({ "123": TomlString("value") }) })
),
)
}
///|
/// Test string keys in table paths
test "table_path_with_string_key" {
let toml_input = "[\"section\".\"subsection\"]\nkey = \"value\""
let result = @toml.parse(toml_input)
debug_inspect(
result,
content=(
#|TomlTable({ "section": TomlTable({ "subsection": TomlTable({ "key": TomlString("value") }) }) })
),
)
}
///|
/// Test integer keys in table paths
test "table_path_with_integer_key" {
let toml_input = "[section.123]\nkey = \"value\""
let result = @toml.parse(toml_input)
debug_inspect(
result,
content=(
#|TomlTable({ "section": TomlTable({ "123": TomlTable({ "key": TomlString("value") }) }) })
),
)
}
///|
/// Test string keys in array of tables paths
test "array_of_tables_path_with_string_key" {
let toml_input = "[[\"products\"]]\nname = \"Hammer\""
let result = @toml.parse(toml_input)
debug_inspect(
result,
content=(
#|TomlTable({ "products": TomlArray([TomlTable({ "name": TomlString("Hammer") })]) })
),
)
}
///|
/// Test integer keys in array of tables paths
test "array_of_tables_path_with_integer_key" {
let toml_input = "[[section.123]]\nvalue = 42"
let result = @toml.parse(toml_input)
debug_inspect(
result,
content=(
#|TomlTable({ "section": TomlTable({ "123": TomlArray([TomlTable({ "value": TomlInteger(42) })]) }) })
),
)
}
///|
/// Test invalid Unicode escape sequences to trigger error paths
test "invalid_unicode_escapes" {
let result = try? @toml.parse(
(
#|key = "\uZZZZ"
),
)
debug_inspect(
result,
content=(
#|Err(Failure("internal/tokenize/tokenize.mbt:111:7-111:81@bobzhang/toml FAILED: Invalid Unicode escape sequence: expected 4 hex digits at line 1, column 10"))
),
) // Expected error
}
///|
/// Test invalid 8-byte Unicode escape
test "invalid_8byte_unicode_escape" {
let result = try? @toml.parse(
(
#|key = "\U00200000"
),
) // Invalid code point > 0x10FFFF
debug_inspect(
result,
content=(
#|Err(Failure("internal/tokenize/tokenize.mbt:158:5-158:60@bobzhang/toml FAILED: Invalid Unicode code point: 2097152 at line 1, column 18"))
),
) // Expected error
}
///|
/// Test unterminated multiline string
test "unterminated_multiline_string" {
let result = try? @toml.parse(
(
#|key = """This is unterminated
),
)
debug_inspect(
result,
content=(
#|Err(Failure("internal/tokenize/tokenize.mbt:416:11-416:60@bobzhang/toml FAILED: Unterminated multiline string at line 1, column 30"))
),
) // Expected error
}
///|
/// Test homogeneous array with TomlFloat
test "homogeneous_array_with_floats" {
let arr = [@toml.TomlFloat(1.0), @toml.TomlFloat(2.0)]
let result = @toml.TomlValue::is_homogeneous_array(arr)
debug_inspect(result, content="true")
}
///|
/// Test homogeneous array with TomlTable
test "homogeneous_array_with_tables" {
let table1 = Map::new()
let table2 = Map::new()
let arr = [@toml.TomlTable(table1), @toml.TomlTable(table2)]
let result = @toml.TomlValue::is_homogeneous_array(arr)
debug_inspect(result, content="true")
}
///|
/// Test homogeneous array type checking with TomlBoolean
test "homogeneous_array_type_check_boolean" {
let arr = [@toml.TomlBoolean(true), @toml.TomlInteger(42L)]
let result = @toml.TomlValue::is_homogeneous_array(arr)
debug_inspect(result, content="false")
}
///|
/// Test homogeneous array type checking with TomlTable vs other
test "homogeneous_array_type_check_table_vs_other" {
let table = Map::new()
let arr = [@toml.TomlTable(table), @toml.TomlInteger(42L)]
let result = @toml.TomlValue::is_homogeneous_array(arr)
debug_inspect(result, content="false")
}
///|
/// Test nested validation failure in arrays
test "nested_validation_failure_in_array" {
// Create a heterogeneous nested array (which should be invalid)
let nested_arr = [@toml.TomlInteger(1L), @toml.TomlString("test")]
let invalid_nested = @toml.TomlArray(nested_arr)
let outer_arr = [invalid_nested]
let outer_array_value = @toml.TomlArray(outer_arr)
let result = outer_array_value.validate()
debug_inspect(result, content="false")
}
///|
/// Test table path conflict error
test "table_path_conflict_error" {
let result = try? @toml.parse(
(
#|key = 42
#|[key]
),
)
debug_inspect(
result,
content=(
#|Err(Failure("parser.mbt:197:20-197:70@bobzhang/toml FAILED: ExpectedTable(\"key\", \"integer\") at { start: { line: 2, column: 6 }, end: { line: 2, column: 6 } }"))
),
) // Expected error
}
///|
/// Test array of tables path conflict error
test "array_of_tables_path_conflict_error" {
let result = try? @toml.parse(
(
#|key = 42
#|[[key]]
),
)
debug_inspect(
result,
content=(
#|Err(Failure("parser.mbt:197:20-197:70@bobzhang/toml FAILED: ExpectedArray(\"key\", \"integer\") at { start: { line: 2, column: 8 }, end: { line: 2, column: 8 } }"))
),
) // Expected error
}
///|
/// Test empty inline table
test "empty_inline_table" {
let toml_input = "table = {}"
let result = @toml.parse(toml_input)
debug_inspect(
result,
content=(
#|TomlTable({ "table": TomlTable({}) })
),
)
}
///|
/// Test empty array
test "empty_array" {
let toml_input = "arr = []"
let result = @toml.parse(toml_input)
debug_inspect(
result,
content=(
#|TomlTable({ "arr": TomlArray([]) })
),
)
}
///|
/// Test various TomlValue to_string methods to ensure coverage
test "toml_value_to_string_coverage" {
// Test float to_string
let float_val = @toml.TomlFloat(3.14)
let float_str = float_val.to_string()
debug_inspect(float_str.contains("3.14"), content="true")
// Test datetime to_string variants
let offset_dt = @toml.TomlDateTime(
@tokenize.OffsetDateTime("2023-05-15T10:30:00Z"),
)
let offset_str = offset_dt.to_string()
debug_inspect(
offset_str,
content=(
#|"2023-05-15T10:30:00Z"
),
)
let local_dt = @toml.TomlDateTime(
@tokenize.LocalDateTime("2023-05-15T10:30:00"),
)
let local_str = local_dt.to_string()
debug_inspect(
local_str,
content=(
#|"2023-05-15T10:30:00"
),
)
let local_date = @toml.TomlDateTime(@tokenize.LocalDate("2023-05-15"))
let date_str = local_date.to_string()
debug_inspect(
date_str,
content=(
#|"2023-05-15"
),
)
let local_time = @toml.TomlDateTime(@tokenize.LocalTime("10:30:00"))
let time_str = local_time.to_string()
debug_inspect(
time_str,
content=(
#|"10:30:00"
),
)
}
///|
/// Test float token parsing to ensure coverage
test "float_token_parsing" {
let toml_input = "pi = 3.14159"
let result = @toml.parse(toml_input)
debug_inspect(
result,
content=(
#|TomlTable({ "pi": TomlFloat(3.14159) })
),
)
}
///|
/// Test array with trailing comma
test "array_with_trailing_comma" {
let toml_input = "numbers = [1, 2, 3,]"
let result = @toml.parse(toml_input)
debug_inspect(
result,
content=(
#|TomlTable({ "numbers": TomlArray([TomlInteger(1), TomlInteger(2), TomlInteger(3)]) })
),
)
}
///|
/// Test to increase coverage of main function components
test "main_function_components_coverage" {
// This test exercises the same functions as main() to improve coverage
let str_val = @toml.TomlString("Hello, TOML!")
let int_val = @toml.TomlInteger(42L)
let bool_val = @toml.TomlBoolean(true)
// Call to_string methods to match main function behavior
debug_inspect(
str_val.to_string(),
content=(
#|"\"Hello, TOML!\""
),
)
debug_inspect(
int_val.to_string(),
content=(
#|"42"
),
)
debug_inspect(
bool_val.to_string(),
content=(
#|"true"
),
)
// Create and manipulate arrays like in main
let arr = Array::new()
arr.push(@toml.TomlInteger(1L))
arr.push(@toml.TomlInteger(2L))
arr.push(@toml.TomlInteger(3L))
let array_val = @toml.TomlArray(arr)
debug_inspect(
array_val.to_string(),
content=(
#|"[1, 2, 3]"
),
)
// Test parsing like in main function
let toml_input = "name = \"John Doe\"\nage = 30\nenabled = true"
let result1 = @toml.parse(toml_input)
debug_inspect(result1.to_string().contains("John Doe"), content="true")
// Test array parsing
let toml_array = "numbers = [1, 2, 3, 4, 5]"
let result2 = @toml.parse(toml_array)
debug_inspect(result2.to_string().contains("[1, 2, 3, 4, 5]"), content="true")
// Test inline table parsing
let toml_table = "person = {name = \"Alice\", age = 25}"
let result3 = @toml.parse(toml_table)
debug_inspect(result3.to_string().contains("Alice"), content="true")
}
///|
/// Test binary number parsing via hex format
test "hex_number_parsing_coverage" {
let toml_input = "hex_num = 0xDEADBEEF"
let result = @toml.parse(toml_input)
debug_inspect(
result,
content=(
#|TomlTable({ "hex_num": TomlInteger(3735928559) })
),
)
}
///|
/// Test octal number parsing
test "octal_number_parsing_coverage" {
let toml_input = "octal_num = 0o755"
let result = @toml.parse(toml_input)
debug_inspect(
result,
content=(
#|TomlTable({ "octal_num": TomlInteger(493) })
),
)
}
///|
/// Test binary number parsing
test "binary_number_parsing_coverage" {
let toml_input = "binary_num = 0b1010"
let result = @toml.parse(toml_input)
debug_inspect(
result,
content=(
#|TomlTable({ "binary_num": TomlInteger(10) })
),
)
}
///|
/// Test multiple array of tables to exercise array appending logic
test "multiple_array_of_tables" {
let toml_input = "[[products]]\nname = \"Hammer\"\n\n[[products]]\nname = \"Nail\""
let result = @toml.parse(toml_input)
debug_inspect(
result,
content=(
#|TomlTable(
#| {
#| "products": TomlArray(
#| [
#| TomlTable({ "name": TomlString("Hammer") }),
#| TomlTable({ "name": TomlString("Nail") }),
#| ],
#| ),
#| },
#|)
),
)
}
///|
/// Test negative number parsing
test "negative_number_parsing" {
let toml_input = "negative = -42"
let result = @toml.parse(toml_input)
debug_inspect(
result,
content=(
#|TomlTable({ "negative": TomlInteger(-42) })
),
)
}
///|
/// Test error handling with invalid characters
test "invalid_character_error" {
let result = try? @toml.parse(
(
#|key = @invalid
),
)
debug_inspect(
result,
content=(
#|Err(Failure("internal/tokenize/tokenize.mbt:1275:17-1275:54@bobzhang/toml FAILED: Unexpected character: '@'"))
),
) // Expected error
}
///|
/// Test multiline basic string with line ending backslash
test "multiline_string_line_ending_backslash" {
let toml_input = "multiline = \"\"\"\nLine 1 \\\n Line 2\"\"\""
let result = @toml.parse(toml_input)
guard result is TomlTable({ "multiline": TomlString(str), .. }) else {
fail("Expected table with multiline string")
}
// Should have whitespace trimmed after backslash
debug_inspect(
str.contains("Line 1") && str.contains("Line 2"),
content="true",
)
}