| ... | ... | @@ -805,7 +805,7 @@ test "zig fmt: doc comments before struct field" { |
| 805 | 805 | \\pub const Allocator = struct { |
| 806 | 806 | \\ /// Allocate byte_count bytes and return them in a slice, with the |
| 807 | 807 | \\ /// slice's pointer aligned at least to alignment bytes. |
| 808 | | \\ allocFn: fn() void, |
| 808 | \\ allocFn: fn () void, |
| 809 | 809 | \\}; |
| 810 | 810 | \\ |
| 811 | 811 | ); |
| ... | ... | @@ -1710,10 +1710,10 @@ test "zig fmt: fn type" { |
| 1710 | 1710 | \\ return i + 1; |
| 1711 | 1711 | \\} |
| 1712 | 1712 | \\ |
| 1713 | | \\const a: fn(u8) u8 = undefined; |
| 1714 | | \\const b: extern fn(u8) u8 = undefined; |
| 1715 | | \\const c: nakedcc fn(u8) u8 = undefined; |
| 1716 | | \\const ap: fn(u8) u8 = a; |
| 1713 | \\const a: fn (u8) u8 = undefined; |
| 1714 | \\const b: extern fn (u8) u8 = undefined; |
| 1715 | \\const c: nakedcc fn (u8) u8 = undefined; |
| 1716 | \\const ap: fn (u8) u8 = a; |
| 1717 | 1717 | \\ |
| 1718 | 1718 | ); |
| 1719 | 1719 | } |
| ... | ... | @@ -1801,7 +1801,7 @@ const io = std.io; |
| 1801 | 1801 | |
| 1802 | 1802 | var fixed_buffer_mem: [100 * 1024]u8 = undefined; |
| 1803 | 1803 | |
| 1804 | | fn testParse(source: []const u8, allocator: &mem.Allocator, changes_expected: bool) ![]u8 { |
| 1804 | fn testParse(source: []const u8, allocator: &mem.Allocator, anything_changed: &bool) ![]u8 { |
| 1805 | 1805 | var stderr_file = try io.getStdErr(); |
| 1806 | 1806 | var stderr = &io.FileOutStream.init(&stderr_file).stream; |
| 1807 | 1807 | |
| ... | ... | @@ -1838,18 +1838,17 @@ fn testParse(source: []const u8, allocator: &mem.Allocator, changes_expected: bo |
| 1838 | 1838 | errdefer buffer.deinit(); |
| 1839 | 1839 | |
| 1840 | 1840 | var buffer_out_stream = io.BufferOutStream.init(&buffer); |
| 1841 | | const anything_changed = try std.zig.render(allocator, &buffer_out_stream.stream, &tree); |
| 1842 | | std.debug.assert(anything_changed == changes_expected); |
| 1841 | anything_changed.* = try std.zig.render(allocator, &buffer_out_stream.stream, &tree); |
| 1843 | 1842 | return buffer.toOwnedSlice(); |
| 1844 | 1843 | } |
| 1845 | 1844 | |
| 1846 | 1845 | fn testTransform(source: []const u8, expected_source: []const u8) !void { |
| 1847 | | const changes_expected = source.ptr != expected_source.ptr; |
| 1848 | 1846 | const needed_alloc_count = x: { |
| 1849 | 1847 | // Try it once with unlimited memory, make sure it works |
| 1850 | 1848 | var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]); |
| 1851 | 1849 | var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, @maxValue(usize)); |
| 1852 | | const result_source = try testParse(source, &failing_allocator.allocator, changes_expected); |
| 1850 | var anything_changed: bool = undefined; |
| 1851 | const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed); |
| 1853 | 1852 | if (!mem.eql(u8, result_source, expected_source)) { |
| 1854 | 1853 | warn("\n====== expected this output: =========\n"); |
| 1855 | 1854 | warn("{}", expected_source); |
| ... | ... | @@ -1858,6 +1857,12 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void { |
| 1858 | 1857 | warn("\n======================================\n"); |
| 1859 | 1858 | return error.TestFailed; |
| 1860 | 1859 | } |
| 1860 | const changes_expected = source.ptr != expected_source.ptr; |
| 1861 | if (anything_changed != changes_expected) { |
| 1862 | warn("std.zig.render returned {} instead of {}\n", anything_changed, changes_expected); |
| 1863 | return error.TestFailed; |
| 1864 | } |
| 1865 | std.debug.assert(anything_changed == changes_expected); |
| 1861 | 1866 | failing_allocator.allocator.free(result_source); |
| 1862 | 1867 | break :x failing_allocator.index; |
| 1863 | 1868 | }; |
| ... | ... | @@ -1866,7 +1871,8 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void { |
| 1866 | 1871 | while (fail_index < needed_alloc_count) : (fail_index += 1) { |
| 1867 | 1872 | var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]); |
| 1868 | 1873 | var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, fail_index); |
| 1869 | | if (testParse(source, &failing_allocator.allocator, changes_expected)) |_| { |
| 1874 | var anything_changed: bool = undefined; |
| 1875 | if (testParse(source, &failing_allocator.allocator, &anything_changed)) |_| { |
| 1870 | 1876 | return error.NondeterministicMemoryUsage; |
| 1871 | 1877 | } else |err| switch (err) { |
| 1872 | 1878 | error.OutOfMemory => { |