authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-30 15:50:01-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-30 15:50:01-04:00
log84b1842026053197cdd8afe0c436ded55f352949
treeb1ace2406e9b79d35cf0fa9fe3d5019e6d3f1838
parent93b51b0e4023c05f1ef40371b8e72004cb55f046

zig fmt: space after fn in fn prototypes

See #1003

2 files changed, 18 insertions(+), 12 deletions(-)

std/zig/parser_test.zig+17-11
......@@ -805,7 +805,7 @@ test "zig fmt: doc comments before struct field" {
805805 \\pub const Allocator = struct {
806806 \\ /// Allocate byte_count bytes and return them in a slice, with the
807807 \\ /// slice's pointer aligned at least to alignment bytes.
808 \\ allocFn: fn() void,
808 \\ allocFn: fn () void,
809809 \\};
810810 \\
811811 );
......@@ -1710,10 +1710,10 @@ test "zig fmt: fn type" {
17101710 \\ return i + 1;
17111711 \\}
17121712 \\
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;
17171717 \\
17181718 );
17191719}
......@@ -1801,7 +1801,7 @@ const io = std.io;
18011801
18021802var fixed_buffer_mem: [100 * 1024]u8 = undefined;
18031803
1804fn testParse(source: []const u8, allocator: &mem.Allocator, changes_expected: bool) ![]u8 {
1804fn testParse(source: []const u8, allocator: &mem.Allocator, anything_changed: &bool) ![]u8 {
18051805 var stderr_file = try io.getStdErr();
18061806 var stderr = &io.FileOutStream.init(&stderr_file).stream;
18071807
......@@ -1838,18 +1838,17 @@ fn testParse(source: []const u8, allocator: &mem.Allocator, changes_expected: bo
18381838 errdefer buffer.deinit();
18391839
18401840 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);
18431842 return buffer.toOwnedSlice();
18441843}
18451844
18461845fn testTransform(source: []const u8, expected_source: []const u8) !void {
1847 const changes_expected = source.ptr != expected_source.ptr;
18481846 const needed_alloc_count = x: {
18491847 // Try it once with unlimited memory, make sure it works
18501848 var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
18511849 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);
18531852 if (!mem.eql(u8, result_source, expected_source)) {
18541853 warn("\n====== expected this output: =========\n");
18551854 warn("{}", expected_source);
......@@ -1858,6 +1857,12 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
18581857 warn("\n======================================\n");
18591858 return error.TestFailed;
18601859 }
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);
18611866 failing_allocator.allocator.free(result_source);
18621867 break :x failing_allocator.index;
18631868 };
......@@ -1866,7 +1871,8 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
18661871 while (fail_index < needed_alloc_count) : (fail_index += 1) {
18671872 var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
18681873 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)) |_| {
18701876 return error.NondeterministicMemoryUsage;
18711877 } else |err| switch (err) {
18721878 error.OutOfMemory => {
std/zig/render.zig+1-1
......@@ -1058,7 +1058,7 @@ fn renderExpression(
10581058 try renderToken(tree, stream, name_token, indent, start_col, Space.None); // name
10591059 break :blk tree.nextToken(name_token);
10601060 } else blk: {
1061 try renderToken(tree, stream, fn_proto.fn_token, indent, start_col, Space.None); // fn
1061 try renderToken(tree, stream, fn_proto.fn_token, indent, start_col, Space.Space); // fn
10621062 break :blk tree.nextToken(fn_proto.fn_token);
10631063 };
10641064