| ... | ... | @@ -431,33 +431,6 @@ test "skipValue" { |
| 431 | 431 | try std.testing.expectError(error.SyntaxError, testSkipValue("[102, 111, 111}")); |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | | fn testEnsureStackCapacity(do_ensure: bool) !void { |
| 435 | | var fail_alloc = std.testing.FailingAllocator.init(std.testing.allocator, .{ .fail_index = 1 }); |
| 436 | | const failing_allocator = fail_alloc.allocator(); |
| 437 | | |
| 438 | | const nestings = 2049; // intentionally not a power of 2. |
| 439 | | var input_string: std.ArrayListUnmanaged(u8) = .empty; |
| 440 | | try input_string.appendNTimes(std.testing.allocator, '[', nestings); |
| 441 | | try input_string.appendNTimes(std.testing.allocator, ']', nestings); |
| 442 | | defer input_string.deinit(std.testing.allocator); |
| 443 | | |
| 444 | | var scanner = Scanner.initCompleteInput(failing_allocator, input_string.items); |
| 445 | | defer scanner.deinit(); |
| 446 | | |
| 447 | | if (do_ensure) { |
| 448 | | try scanner.ensureTotalStackCapacity(nestings); |
| 449 | | } |
| 450 | | |
| 451 | | try scanner.skipValue(); |
| 452 | | try std.testing.expectEqual(Token.end_of_document, try scanner.next()); |
| 453 | | } |
| 454 | | test "ensureTotalStackCapacity" { |
| 455 | | // Once to demonstrate failure. |
| 456 | | try std.testing.expectError(error.OutOfMemory, testEnsureStackCapacity(false)); |
| 457 | | // Then to demonstrate it works. |
| 458 | | try testEnsureStackCapacity(true); |
| 459 | | } |
| 460 | | |
| 461 | 434 | fn testDiagnosticsFromSource(expected_error: ?anyerror, line: u64, col: u64, byte_offset: u64, source: anytype) !void { |
| 462 | 435 | var diagnostics = Diagnostics{}; |
| 463 | 436 | source.enableDiagnostics(&diagnostics); |