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" {...@@ -805,7 +805,7 @@ test "zig fmt: doc comments before struct field" {
805 \\pub const Allocator = struct {805 \\pub const Allocator = struct {
806 \\ /// Allocate byte_count bytes and return them in a slice, with the806 \\ /// Allocate byte_count bytes and return them in a slice, with the
807 \\ /// slice's pointer aligned at least to alignment bytes.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,10 +1710,10 @@ test "zig fmt: fn type" {
1710 \\ return i + 1;1710 \\ return i + 1;
1711 \\}1711 \\}
1712 \\1712 \\
1713 \\const a: fn(u8) u8 = undefined;1713 \\const a: fn (u8) u8 = undefined;
1714 \\const b: extern fn(u8) u8 = undefined;1714 \\const b: extern fn (u8) u8 = undefined;
1715 \\const c: nakedcc fn(u8) u8 = undefined;1715 \\const c: nakedcc fn (u8) u8 = undefined;
1716 \\const ap: fn(u8) u8 = a;1716 \\const ap: fn (u8) u8 = a;
1717 \\1717 \\
1718 );1718 );
1719}1719}
...@@ -1801,7 +1801,7 @@ const io = std.io;...@@ -1801,7 +1801,7 @@ const io = std.io;
18011801
1802var fixed_buffer_mem: [100 * 1024]u8 = undefined;1802var 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 {
1805 var stderr_file = try io.getStdErr();1805 var stderr_file = try io.getStdErr();
1806 var stderr = &io.FileOutStream.init(&stderr_file).stream;1806 var stderr = &io.FileOutStream.init(&stderr_file).stream;
18071807
...@@ -1838,18 +1838,17 @@ fn testParse(source: []const u8, allocator: &mem.Allocator, changes_expected: bo...@@ -1838,18 +1838,17 @@ fn testParse(source: []const u8, allocator: &mem.Allocator, changes_expected: bo
1838 errdefer buffer.deinit();1838 errdefer buffer.deinit();
18391839
1840 var buffer_out_stream = io.BufferOutStream.init(&buffer);1840 var buffer_out_stream = io.BufferOutStream.init(&buffer);
1841 const anything_changed = try std.zig.render(allocator, &buffer_out_stream.stream, &tree);1841 anything_changed.* = try std.zig.render(allocator, &buffer_out_stream.stream, &tree);
1842 std.debug.assert(anything_changed == changes_expected);
1843 return buffer.toOwnedSlice();1842 return buffer.toOwnedSlice();
1844}1843}
18451844
1846fn testTransform(source: []const u8, expected_source: []const u8) !void {1845fn testTransform(source: []const u8, expected_source: []const u8) !void {
1847 const changes_expected = source.ptr != expected_source.ptr;
1848 const needed_alloc_count = x: {1846 const needed_alloc_count = x: {
1849 // Try it once with unlimited memory, make sure it works1847 // Try it once with unlimited memory, make sure it works
1850 var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);1848 var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
1851 var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, @maxValue(usize));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 if (!mem.eql(u8, result_source, expected_source)) {1852 if (!mem.eql(u8, result_source, expected_source)) {
1854 warn("\n====== expected this output: =========\n");1853 warn("\n====== expected this output: =========\n");
1855 warn("{}", expected_source);1854 warn("{}", expected_source);
...@@ -1858,6 +1857,12 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {...@@ -1858,6 +1857,12 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
1858 warn("\n======================================\n");1857 warn("\n======================================\n");
1859 return error.TestFailed;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 failing_allocator.allocator.free(result_source);1866 failing_allocator.allocator.free(result_source);
1862 break :x failing_allocator.index;1867 break :x failing_allocator.index;
1863 };1868 };
...@@ -1866,7 +1871,8 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {...@@ -1866,7 +1871,8 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
1866 while (fail_index < needed_alloc_count) : (fail_index += 1) {1871 while (fail_index < needed_alloc_count) : (fail_index += 1) {
1867 var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);1872 var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
1868 var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, fail_index);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 return error.NondeterministicMemoryUsage;1876 return error.NondeterministicMemoryUsage;
1871 } else |err| switch (err) {1877 } else |err| switch (err) {
1872 error.OutOfMemory => {1878 error.OutOfMemory => {
std/zig/render.zig+1-1
...@@ -1058,7 +1058,7 @@ fn renderExpression(...@@ -1058,7 +1058,7 @@ fn renderExpression(
1058 try renderToken(tree, stream, name_token, indent, start_col, Space.None); // name1058 try renderToken(tree, stream, name_token, indent, start_col, Space.None); // name
1059 break :blk tree.nextToken(name_token);1059 break :blk tree.nextToken(name_token);
1060 } else blk: {1060 } else blk: {
1061 try renderToken(tree, stream, fn_proto.fn_token, indent, start_col, Space.None); // fn1061 try renderToken(tree, stream, fn_proto.fn_token, indent, start_col, Space.Space); // fn
1062 break :blk tree.nextToken(fn_proto.fn_token);1062 break :blk tree.nextToken(fn_proto.fn_token);
1063 };1063 };
10641064