| author | |
| committer | |
| log | 5a3eca5d4ca42f92abe60040e21ffd8e307d8466 |
| tree | a69d1c9ccff1feeb63f6117658695703f682ccd4 |
| parent | bac3a28214d07f761e25fcc12a6708f70c8ccc01 |
| signature |
15 files changed, 158 insertions(+), 125 deletions(-)
lib/std/fmt.zig+37-38| ... | @@ -2244,8 +2244,8 @@ test "struct" { | ... | @@ -2244,8 +2244,8 @@ test "struct" { |
| 2244 | field: u8, | 2244 | field: u8, |
| 2245 | }; | 2245 | }; |
| 2246 | const value = Struct{ .field = 42 }; | 2246 | const value = Struct{ .field = 42 }; |
| 2247 | try expectFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", .{value}); | 2247 | try expectFmt("struct: fmt.test.struct.Struct{ .field = 42 }\n", "struct: {}\n", .{value}); |
| 2248 | try expectFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", .{&value}); | 2248 | try expectFmt("struct: fmt.test.struct.Struct{ .field = 42 }\n", "struct: {}\n", .{&value}); |
| 2249 | } | 2249 | } |
| 2250 | { | 2250 | { |
| 2251 | const Struct = struct { | 2251 | const Struct = struct { |
| ... | @@ -2253,8 +2253,24 @@ test "struct" { | ... | @@ -2253,8 +2253,24 @@ test "struct" { |
| 2253 | b: u1, | 2253 | b: u1, |
| 2254 | }; | 2254 | }; |
| 2255 | const value = Struct{ .a = 0, .b = 1 }; | 2255 | const value = Struct{ .a = 0, .b = 1 }; |
| 2256 | try expectFmt("struct: Struct{ .a = 0, .b = 1 }\n", "struct: {}\n", .{value}); | 2256 | try expectFmt("struct: fmt.test.struct.Struct{ .a = 0, .b = 1 }\n", "struct: {}\n", .{value}); |
| 2257 | } | 2257 | } |
| 2258 | |||
| 2259 | const S = struct { | ||
| 2260 | a: u32, | ||
| 2261 | b: anyerror, | ||
| 2262 | }; | ||
| 2263 | |||
| 2264 | const inst = S{ | ||
| 2265 | .a = 456, | ||
| 2266 | .b = error.Unused, | ||
| 2267 | }; | ||
| 2268 | |||
| 2269 | try expectFmt("fmt.test.struct.S{ .a = 456, .b = error.Unused }", "{}", .{inst}); | ||
| 2270 | // Tuples | ||
| 2271 | try expectFmt("{ }", "{}", .{.{}}); | ||
| 2272 | try expectFmt("{ -1 }", "{}", .{.{-1}}); | ||
| 2273 | try expectFmt("{ -1, 42, 2.5e+04 }", "{}", .{.{ -1, 42, 0.25e5 }}); | ||
| 2258 | } | 2274 | } |
| 2259 | 2275 | ||
| 2260 | test "enum" { | 2276 | test "enum" { |
| ... | @@ -2263,13 +2279,26 @@ test "enum" { | ... | @@ -2263,13 +2279,26 @@ test "enum" { |
| 2263 | Two, | 2279 | Two, |
| 2264 | }; | 2280 | }; |
| 2265 | const value = Enum.Two; | 2281 | const value = Enum.Two; |
| 2266 | try expectFmt("enum: Enum.Two\n", "enum: {}\n", .{value}); | 2282 | try expectFmt("enum: fmt.test.enum.Enum.Two\n", "enum: {}\n", .{value}); |
| 2267 | try expectFmt("enum: Enum.Two\n", "enum: {}\n", .{&value}); | 2283 | try expectFmt("enum: fmt.test.enum.Enum.Two\n", "enum: {}\n", .{&value}); |
| 2268 | try expectFmt("enum: Enum.One\n", "enum: {}\n", .{Enum.One}); | 2284 | try expectFmt("enum: fmt.test.enum.Enum.One\n", "enum: {}\n", .{Enum.One}); |
| 2269 | try expectFmt("enum: Enum.Two\n", "enum: {}\n", .{Enum.Two}); | 2285 | try expectFmt("enum: fmt.test.enum.Enum.Two\n", "enum: {}\n", .{Enum.Two}); |
| 2270 | 2286 | ||
| 2271 | // test very large enum to verify ct branch quota is large enough | 2287 | // test very large enum to verify ct branch quota is large enough |
| 2272 | try expectFmt("enum: os.windows.win32error.Win32Error.INVALID_FUNCTION\n", "enum: {}\n", .{std.os.windows.Win32Error.INVALID_FUNCTION}); | 2288 | // TODO: https://github.com/ziglang/zig/issues/15609 |
| 2289 | if (!((builtin.cpu.arch == .wasm32) and builtin.mode == .Debug)) { | ||
| 2290 | try expectFmt("enum: os.windows.win32error.Win32Error.INVALID_FUNCTION\n", "enum: {}\n", .{std.os.windows.Win32Error.INVALID_FUNCTION}); | ||
| 2291 | } | ||
| 2292 | |||
| 2293 | const E = enum { | ||
| 2294 | One, | ||
| 2295 | Two, | ||
| 2296 | Three, | ||
| 2297 | }; | ||
| 2298 | |||
| 2299 | const inst = E.Two; | ||
| 2300 | |||
| 2301 | try expectFmt("fmt.test.enum.E.Two", "{}", .{inst}); | ||
| 2273 | } | 2302 | } |
| 2274 | 2303 | ||
| 2275 | test "non-exhaustive enum" { | 2304 | test "non-exhaustive enum" { |
| ... | @@ -2445,24 +2474,6 @@ test "custom" { | ... | @@ -2445,24 +2474,6 @@ test "custom" { |
| 2445 | try expectFmt("dim: 10.200x2.220\n", "dim: {d}\n", .{value}); | 2474 | try expectFmt("dim: 10.200x2.220\n", "dim: {d}\n", .{value}); |
| 2446 | } | 2475 | } |
| 2447 | 2476 | ||
| 2448 | test "struct" { | ||
| 2449 | const S = struct { | ||
| 2450 | a: u32, | ||
| 2451 | b: anyerror, | ||
| 2452 | }; | ||
| 2453 | |||
| 2454 | const inst = S{ | ||
| 2455 | .a = 456, | ||
| 2456 | .b = error.Unused, | ||
| 2457 | }; | ||
| 2458 | |||
| 2459 | try expectFmt("fmt.test.struct.S{ .a = 456, .b = error.Unused }", "{}", .{inst}); | ||
| 2460 | // Tuples | ||
| 2461 | try expectFmt("{ }", "{}", .{.{}}); | ||
| 2462 | try expectFmt("{ -1 }", "{}", .{.{-1}}); | ||
| 2463 | try expectFmt("{ -1, 42, 2.5e+04 }", "{}", .{.{ -1, 42, 0.25e5 }}); | ||
| 2464 | } | ||
| 2465 | |||
| 2466 | test "union" { | 2477 | test "union" { |
| 2467 | const TU = union(enum) { | 2478 | const TU = union(enum) { |
| 2468 | float: f32, | 2479 | float: f32, |
| ... | @@ -2493,18 +2504,6 @@ test "union" { | ... | @@ -2493,18 +2504,6 @@ test "union" { |
| 2493 | try std.testing.expect(mem.eql(u8, eu_result[0..18], "fmt.test.union.EU@")); | 2504 | try std.testing.expect(mem.eql(u8, eu_result[0..18], "fmt.test.union.EU@")); |
| 2494 | } | 2505 | } |
| 2495 | 2506 | ||
| 2496 | test "enum" { | ||
| 2497 | const E = enum { | ||
| 2498 | One, | ||
| 2499 | Two, | ||
| 2500 | Three, | ||
| 2501 | }; | ||
| 2502 | |||
| 2503 | const inst = E.Two; | ||
| 2504 | |||
| 2505 | try expectFmt("fmt.test.enum.E.Two", "{}", .{inst}); | ||
| 2506 | } | ||
| 2507 | |||
| 2508 | test "struct.self-referential" { | 2507 | test "struct.self-referential" { |
| 2509 | const S = struct { | 2508 | const S = struct { |
| 2510 | const SelfType = @This(); | 2509 | const SelfType = @This(); |
lib/std/hash_map.zig+16-18| ... | @@ -1741,6 +1741,22 @@ test "std.hash_map clone" { | ... | @@ -1741,6 +1741,22 @@ test "std.hash_map clone" { |
| 1741 | try expectEqual(b.get(1).?, 1); | 1741 | try expectEqual(b.get(1).?, 1); |
| 1742 | try expectEqual(b.get(2).?, 2); | 1742 | try expectEqual(b.get(2).?, 2); |
| 1743 | try expectEqual(b.get(3).?, 3); | 1743 | try expectEqual(b.get(3).?, 3); |
| 1744 | |||
| 1745 | var original = AutoHashMap(i32, i32).init(std.testing.allocator); | ||
| 1746 | defer original.deinit(); | ||
| 1747 | |||
| 1748 | var i: u8 = 0; | ||
| 1749 | while (i < 10) : (i += 1) { | ||
| 1750 | try original.putNoClobber(i, i * 10); | ||
| 1751 | } | ||
| 1752 | |||
| 1753 | var copy = try original.clone(); | ||
| 1754 | defer copy.deinit(); | ||
| 1755 | |||
| 1756 | i = 0; | ||
| 1757 | while (i < 10) : (i += 1) { | ||
| 1758 | try testing.expect(copy.get(i).? == i * 10); | ||
| 1759 | } | ||
| 1744 | } | 1760 | } |
| 1745 | 1761 | ||
| 1746 | test "std.hash_map ensureTotalCapacity with existing elements" { | 1762 | test "std.hash_map ensureTotalCapacity with existing elements" { |
| ... | @@ -2072,24 +2088,6 @@ test "std.hash_map basic hash map usage" { | ... | @@ -2072,24 +2088,6 @@ test "std.hash_map basic hash map usage" { |
| 2072 | try testing.expect(map.remove(3) == true); | 2088 | try testing.expect(map.remove(3) == true); |
| 2073 | } | 2089 | } |
| 2074 | 2090 | ||
| 2075 | test "std.hash_map clone" { | ||
| 2076 | var original = AutoHashMap(i32, i32).init(std.testing.allocator); | ||
| 2077 | defer original.deinit(); | ||
| 2078 | |||
| 2079 | var i: u8 = 0; | ||
| 2080 | while (i < 10) : (i += 1) { | ||
| 2081 | try original.putNoClobber(i, i * 10); | ||
| 2082 | } | ||
| 2083 | |||
| 2084 | var copy = try original.clone(); | ||
| 2085 | defer copy.deinit(); | ||
| 2086 | |||
| 2087 | i = 0; | ||
| 2088 | while (i < 10) : (i += 1) { | ||
| 2089 | try testing.expect(copy.get(i).? == i * 10); | ||
| 2090 | } | ||
| 2091 | } | ||
| 2092 | |||
| 2093 | test "std.hash_map getOrPutAdapted" { | 2091 | test "std.hash_map getOrPutAdapted" { |
| 2094 | const AdaptedContext = struct { | 2092 | const AdaptedContext = struct { |
| 2095 | fn eql(self: @This(), adapted_key: []const u8, test_key: u64) bool { | 2093 | fn eql(self: @This(), adapted_key: []const u8, test_key: u64) bool { |
lib/std/io/reader.zig+12-11| ... | @@ -553,10 +553,18 @@ test "Reader.readUntilDelimiter returns StreamTooLong, then bytes read until the | ... | @@ -553,10 +553,18 @@ test "Reader.readUntilDelimiter returns StreamTooLong, then bytes read until the |
| 553 | } | 553 | } |
| 554 | 554 | ||
| 555 | test "Reader.readUntilDelimiter returns EndOfStream" { | 555 | test "Reader.readUntilDelimiter returns EndOfStream" { |
| 556 | var buf: [5]u8 = undefined; | 556 | { |
| 557 | var fis = std.io.fixedBufferStream(""); | 557 | var buf: [5]u8 = undefined; |
| 558 | const reader = fis.reader(); | 558 | var fis = std.io.fixedBufferStream(""); |
| 559 | try std.testing.expectError(error.EndOfStream, reader.readUntilDelimiter(&buf, '\n')); | 559 | const reader = fis.reader(); |
| 560 | try std.testing.expectError(error.EndOfStream, reader.readUntilDelimiter(&buf, '\n')); | ||
| 561 | } | ||
| 562 | { | ||
| 563 | var buf: [5]u8 = undefined; | ||
| 564 | var fis = std.io.fixedBufferStream("1234"); | ||
| 565 | const reader = fis.reader(); | ||
| 566 | try std.testing.expectError(error.EndOfStream, reader.readUntilDelimiter(&buf, '\n')); | ||
| 567 | } | ||
| 560 | } | 568 | } |
| 561 | 569 | ||
| 562 | test "Reader.readUntilDelimiter returns bytes read until delimiter, then EndOfStream" { | 570 | test "Reader.readUntilDelimiter returns bytes read until delimiter, then EndOfStream" { |
| ... | @@ -567,13 +575,6 @@ test "Reader.readUntilDelimiter returns bytes read until delimiter, then EndOfSt | ... | @@ -567,13 +575,6 @@ test "Reader.readUntilDelimiter returns bytes read until delimiter, then EndOfSt |
| 567 | try std.testing.expectError(error.EndOfStream, reader.readUntilDelimiter(&buf, '\n')); | 575 | try std.testing.expectError(error.EndOfStream, reader.readUntilDelimiter(&buf, '\n')); |
| 568 | } | 576 | } |
| 569 | 577 | ||
| 570 | test "Reader.readUntilDelimiter returns EndOfStream" { | ||
| 571 | var buf: [5]u8 = undefined; | ||
| 572 | var fis = std.io.fixedBufferStream("1234"); | ||
| 573 | const reader = fis.reader(); | ||
| 574 | try std.testing.expectError(error.EndOfStream, reader.readUntilDelimiter(&buf, '\n')); | ||
| 575 | } | ||
| 576 | |||
| 577 | test "Reader.readUntilDelimiter returns StreamTooLong, then EndOfStream" { | 578 | test "Reader.readUntilDelimiter returns StreamTooLong, then EndOfStream" { |
| 578 | var buf: [5]u8 = undefined; | 579 | var buf: [5]u8 = undefined; |
| 579 | var fis = std.io.fixedBufferStream("12345"); | 580 | var fis = std.io.fixedBufferStream("12345"); |
lib/std/math/big/int_test.zig+4-9| ... | @@ -2012,15 +2012,10 @@ test "big.int shift-right negative" { | ... | @@ -2012,15 +2012,10 @@ test "big.int shift-right negative" { |
| 2012 | defer arg2.deinit(); | 2012 | defer arg2.deinit(); |
| 2013 | try a.shiftRight(&arg2, 10); | 2013 | try a.shiftRight(&arg2, 10); |
| 2014 | try testing.expect((try a.to(i32)) == -1); // -5 >> 10 == -1 | 2014 | try testing.expect((try a.to(i32)) == -1); // -5 >> 10 == -1 |
| 2015 | } | ||
| 2016 | 2015 | ||
| 2017 | test "big.int shift-right negative" { | 2016 | var arg3 = try Managed.initSet(testing.allocator, -10); |
| 2018 | var a = try Managed.init(testing.allocator); | 2017 | defer arg3.deinit(); |
| 2019 | defer a.deinit(); | 2018 | try a.shiftRight(&arg3, 1232); |
| 2020 | |||
| 2021 | var arg = try Managed.initSet(testing.allocator, -10); | ||
| 2022 | defer arg.deinit(); | ||
| 2023 | try a.shiftRight(&arg, 1232); | ||
| 2024 | try testing.expect((try a.to(i32)) == -1); // -10 >> 1232 == -1 | 2019 | try testing.expect((try a.to(i32)) == -1); // -10 >> 1232 == -1 |
| 2025 | } | 2020 | } |
| 2026 | 2021 | ||
| ... | @@ -2483,7 +2478,7 @@ test "big.int gcd non-one small" { | ... | @@ -2483,7 +2478,7 @@ test "big.int gcd non-one small" { |
| 2483 | try testing.expect((try r.to(u32)) == 1); | 2478 | try testing.expect((try r.to(u32)) == 1); |
| 2484 | } | 2479 | } |
| 2485 | 2480 | ||
| 2486 | test "big.int gcd non-one small" { | 2481 | test "big.int gcd non-one medium" { |
| 2487 | var a = try Managed.initSet(testing.allocator, 4864); | 2482 | var a = try Managed.initSet(testing.allocator, 4864); |
| 2488 | defer a.deinit(); | 2483 | defer a.deinit(); |
| 2489 | var b = try Managed.initSet(testing.allocator, 3458); | 2484 | var b = try Managed.initSet(testing.allocator, 3458); |
lib/std/math/big/rational.zig+27-25| ... | @@ -782,36 +782,38 @@ test "big.rational mul" { | ... | @@ -782,36 +782,38 @@ test "big.rational mul" { |
| 782 | } | 782 | } |
| 783 | 783 | ||
| 784 | test "big.rational div" { | 784 | test "big.rational div" { |
| 785 | var a = try Rational.init(testing.allocator); | 785 | { |
| 786 | defer a.deinit(); | 786 | var a = try Rational.init(testing.allocator); |
| 787 | var b = try Rational.init(testing.allocator); | 787 | defer a.deinit(); |
| 788 | defer b.deinit(); | 788 | var b = try Rational.init(testing.allocator); |
| 789 | var r = try Rational.init(testing.allocator); | 789 | defer b.deinit(); |
| 790 | defer r.deinit(); | 790 | var r = try Rational.init(testing.allocator); |
| 791 | defer r.deinit(); | ||
| 791 | 792 | ||
| 792 | try a.setRatio(78923, 23341); | 793 | try a.setRatio(78923, 23341); |
| 793 | try b.setRatio(123097, 12441414); | 794 | try b.setRatio(123097, 12441414); |
| 794 | try a.div(a, b); | 795 | try a.div(a, b); |
| 795 | 796 | ||
| 796 | try r.setRatio(75531824394, 221015929); | 797 | try r.setRatio(75531824394, 221015929); |
| 797 | try testing.expect((try a.order(r)) == .eq); | 798 | try testing.expect((try a.order(r)) == .eq); |
| 798 | } | 799 | } |
| 799 | 800 | ||
| 800 | test "big.rational div" { | 801 | { |
| 801 | var a = try Rational.init(testing.allocator); | 802 | var a = try Rational.init(testing.allocator); |
| 802 | defer a.deinit(); | 803 | defer a.deinit(); |
| 803 | var r = try Rational.init(testing.allocator); | 804 | var r = try Rational.init(testing.allocator); |
| 804 | defer r.deinit(); | 805 | defer r.deinit(); |
| 805 | 806 | ||
| 806 | try a.setRatio(78923, 23341); | 807 | try a.setRatio(78923, 23341); |
| 807 | a.invert(); | 808 | a.invert(); |
| 808 | 809 | ||
| 809 | try r.setRatio(23341, 78923); | 810 | try r.setRatio(23341, 78923); |
| 810 | try testing.expect((try a.order(r)) == .eq); | 811 | try testing.expect((try a.order(r)) == .eq); |
| 811 | 812 | ||
| 812 | try a.setRatio(-78923, 23341); | 813 | try a.setRatio(-78923, 23341); |
| 813 | a.invert(); | 814 | a.invert(); |
| 814 | 815 | ||
| 815 | try r.setRatio(-23341, 78923); | 816 | try r.setRatio(-23341, 78923); |
| 816 | try testing.expect((try a.order(r)) == .eq); | 817 | try testing.expect((try a.order(r)) == .eq); |
| 818 | } | ||
| 817 | } | 819 | } |
lib/std/net/test.zig+1-1| ... | @@ -182,7 +182,7 @@ test "listen on a port, send bytes, receive bytes" { | ... | @@ -182,7 +182,7 @@ test "listen on a port, send bytes, receive bytes" { |
| 182 | try testing.expectEqualSlices(u8, "Hello world!", buf[0..n]); | 182 | try testing.expectEqualSlices(u8, "Hello world!", buf[0..n]); |
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | test "listen on a port, send bytes, receive bytes" { | 185 | test "listen on a port, send bytes, receive bytes, async-only" { |
| 186 | if (!std.io.is_async) return error.SkipZigTest; | 186 | if (!std.io.is_async) return error.SkipZigTest; |
| 187 | 187 | ||
| 188 | if (builtin.os.tag != .linux and !builtin.os.tag.isDarwin()) { | 188 | if (builtin.os.tag != .linux and !builtin.os.tag.isDarwin()) { |
lib/std/priority_dequeue.zig+2-2| ... | @@ -633,7 +633,7 @@ test "std.PriorityDequeue: peekMax" { | ... | @@ -633,7 +633,7 @@ test "std.PriorityDequeue: peekMax" { |
| 633 | try expect(queue.peekMax().? == 9); | 633 | try expect(queue.peekMax().? == 9); |
| 634 | } | 634 | } |
| 635 | 635 | ||
| 636 | test "std.PriorityDequeue: sift up with odd indices" { | 636 | test "std.PriorityDequeue: sift up with odd indices, removeMin" { |
| 637 | var queue = PDQ.init(testing.allocator, {}); | 637 | var queue = PDQ.init(testing.allocator, {}); |
| 638 | defer queue.deinit(); | 638 | defer queue.deinit(); |
| 639 | const items = [_]u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 }; | 639 | const items = [_]u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 }; |
| ... | @@ -647,7 +647,7 @@ test "std.PriorityDequeue: sift up with odd indices" { | ... | @@ -647,7 +647,7 @@ test "std.PriorityDequeue: sift up with odd indices" { |
| 647 | } | 647 | } |
| 648 | } | 648 | } |
| 649 | 649 | ||
| 650 | test "std.PriorityDequeue: sift up with odd indices" { | 650 | test "std.PriorityDequeue: sift up with odd indices, removeMax" { |
| 651 | var queue = PDQ.init(testing.allocator, {}); | 651 | var queue = PDQ.init(testing.allocator, {}); |
| 652 | defer queue.deinit(); | 652 | defer queue.deinit(); |
| 653 | const items = [_]u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 }; | 653 | const items = [_]u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 }; |
lib/std/zig/parser_test.zig+4-4| ... | @@ -1240,7 +1240,7 @@ test "zig fmt: infix operator and then multiline string literal" { | ... | @@ -1240,7 +1240,7 @@ test "zig fmt: infix operator and then multiline string literal" { |
| 1240 | ); | 1240 | ); |
| 1241 | } | 1241 | } |
| 1242 | 1242 | ||
| 1243 | test "zig fmt: infix operator and then multiline string literal" { | 1243 | test "zig fmt: infix operator and then multiline string literal over multiple lines" { |
| 1244 | try testCanonical( | 1244 | try testCanonical( |
| 1245 | \\const x = "" ++ | 1245 | \\const x = "" ++ |
| 1246 | \\ \\ hi0 | 1246 | \\ \\ hi0 |
| ... | @@ -4310,7 +4310,7 @@ test "zig fmt: comptime before comptime field" { | ... | @@ -4310,7 +4310,7 @@ test "zig fmt: comptime before comptime field" { |
| 4310 | }); | 4310 | }); |
| 4311 | } | 4311 | } |
| 4312 | 4312 | ||
| 4313 | test "zig fmt: invalid else branch statement" { | 4313 | test "zig fmt: invalid doc comments on comptime and test blocks" { |
| 4314 | try testError( | 4314 | try testError( |
| 4315 | \\/// This is a doc comment for a comptime block. | 4315 | \\/// This is a doc comment for a comptime block. |
| 4316 | \\comptime {} | 4316 | \\comptime {} |
| ... | @@ -5191,7 +5191,7 @@ test "zig fmt: preserve container doc comment in container without trailing comm | ... | @@ -5191,7 +5191,7 @@ test "zig fmt: preserve container doc comment in container without trailing comm |
| 5191 | ); | 5191 | ); |
| 5192 | } | 5192 | } |
| 5193 | 5193 | ||
| 5194 | test "zig fmt: make single-line if no trailing comma" { | 5194 | test "zig fmt: make single-line if no trailing comma, fmt: off" { |
| 5195 | try testCanonical( | 5195 | try testCanonical( |
| 5196 | \\// Test trailing comma syntax | 5196 | \\// Test trailing comma syntax |
| 5197 | \\// zig fmt: off | 5197 | \\// zig fmt: off |
| ... | @@ -5270,7 +5270,7 @@ test "zig fmt: variable initialized with ==" { | ... | @@ -5270,7 +5270,7 @@ test "zig fmt: variable initialized with ==" { |
| 5270 | , &.{.wrong_equal_var_decl}); | 5270 | , &.{.wrong_equal_var_decl}); |
| 5271 | } | 5271 | } |
| 5272 | 5272 | ||
| 5273 | test "zig fmt: missing const/var before local variable" { | 5273 | test "zig fmt: missing const/var before local variable in comptime block" { |
| 5274 | try testError( | 5274 | try testError( |
| 5275 | \\comptime { | 5275 | \\comptime { |
| 5276 | \\ z: u32; | 5276 | \\ z: u32; |
src/Module.zig+25-1| ... | @@ -5280,6 +5280,9 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err | ... | @@ -5280,6 +5280,9 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err |
| 5280 | } | 5280 | } |
| 5281 | }, | 5281 | }, |
| 5282 | }; | 5282 | }; |
| 5283 | var must_free_decl_name = true; | ||
| 5284 | defer if (must_free_decl_name) gpa.free(decl_name); | ||
| 5285 | |||
| 5283 | const is_exported = export_bit and decl_name_index != 0; | 5286 | const is_exported = export_bit and decl_name_index != 0; |
| 5284 | if (kind == .@"usingnamespace") try namespace.usingnamespace_set.ensureUnusedCapacity(gpa, 1); | 5287 | if (kind == .@"usingnamespace") try namespace.usingnamespace_set.ensureUnusedCapacity(gpa, 1); |
| 5285 | 5288 | ||
| ... | @@ -5296,6 +5299,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err | ... | @@ -5296,6 +5299,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err |
| 5296 | const new_decl = mod.declPtr(new_decl_index); | 5299 | const new_decl = mod.declPtr(new_decl_index); |
| 5297 | new_decl.kind = kind; | 5300 | new_decl.kind = kind; |
| 5298 | new_decl.name = decl_name; | 5301 | new_decl.name = decl_name; |
| 5302 | must_free_decl_name = false; | ||
| 5299 | if (kind == .@"usingnamespace") { | 5303 | if (kind == .@"usingnamespace") { |
| 5300 | namespace.usingnamespace_set.putAssumeCapacity(new_decl_index, is_pub); | 5304 | namespace.usingnamespace_set.putAssumeCapacity(new_decl_index, is_pub); |
| 5301 | } | 5305 | } |
| ... | @@ -5339,9 +5343,29 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err | ... | @@ -5339,9 +5343,29 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err |
| 5339 | new_decl.alive = true; // This Decl corresponds to an AST node and therefore always alive. | 5343 | new_decl.alive = true; // This Decl corresponds to an AST node and therefore always alive. |
| 5340 | return; | 5344 | return; |
| 5341 | } | 5345 | } |
| 5342 | gpa.free(decl_name); | ||
| 5343 | const decl_index = gop.key_ptr.*; | 5346 | const decl_index = gop.key_ptr.*; |
| 5344 | const decl = mod.declPtr(decl_index); | 5347 | const decl = mod.declPtr(decl_index); |
| 5348 | if (kind == .@"test") { | ||
| 5349 | const src_loc = SrcLoc{ | ||
| 5350 | .file_scope = decl.getFileScope(), | ||
| 5351 | .parent_decl_node = decl.src_node, | ||
| 5352 | .lazy = .{ .token_offset = 1 }, | ||
| 5353 | }; | ||
| 5354 | const msg = try ErrorMsg.create( | ||
| 5355 | gpa, | ||
| 5356 | src_loc, | ||
| 5357 | "found test declaration with duplicate name: {s}", | ||
| 5358 | .{decl_name}, | ||
| 5359 | ); | ||
| 5360 | errdefer msg.destroy(gpa); | ||
| 5361 | try mod.failed_decls.putNoClobber(gpa, decl_index, msg); | ||
| 5362 | const other_src_loc = SrcLoc{ | ||
| 5363 | .file_scope = namespace.file_scope, | ||
| 5364 | .parent_decl_node = decl_node, | ||
| 5365 | .lazy = .{ .token_offset = 1 }, | ||
| 5366 | }; | ||
| 5367 | try mod.errNoteNonLazy(other_src_loc, msg, "other test here", .{}); | ||
| 5368 | } | ||
| 5345 | log.debug("scan existing {*} ({s}) of {*}", .{ decl, decl.name, namespace }); | 5369 | log.debug("scan existing {*} ({s}) of {*}", .{ decl, decl.name, namespace }); |
| 5346 | // Update the AST node of the decl; even if its contents are unchanged, it may | 5370 | // Update the AST node of the decl; even if its contents are unchanged, it may |
| 5347 | // have been re-ordered. | 5371 | // have been re-ordered. |
test/behavior.zig+1| ... | @@ -150,6 +150,7 @@ test { | ... | @@ -150,6 +150,7 @@ test { |
| 150 | _ = @import("behavior/comptime_memory.zig"); | 150 | _ = @import("behavior/comptime_memory.zig"); |
| 151 | _ = @import("behavior/const_slice_child.zig"); | 151 | _ = @import("behavior/const_slice_child.zig"); |
| 152 | _ = @import("behavior/decltest.zig"); | 152 | _ = @import("behavior/decltest.zig"); |
| 153 | _ = @import("behavior/duplicated_test_names.zig"); | ||
| 153 | _ = @import("behavior/defer.zig"); | 154 | _ = @import("behavior/defer.zig"); |
| 154 | _ = @import("behavior/empty_tuple_fields.zig"); | 155 | _ = @import("behavior/empty_tuple_fields.zig"); |
| 155 | _ = @import("behavior/empty_union.zig"); | 156 | _ = @import("behavior/empty_union.zig"); |
test/behavior/basic.zig+1-1| ... | @@ -203,7 +203,7 @@ test "multiline string comments at multiple places" { | ... | @@ -203,7 +203,7 @@ test "multiline string comments at multiple places" { |
| 203 | try expect(mem.eql(u8, s1, s2)); | 203 | try expect(mem.eql(u8, s1, s2)); |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | test "string concatenation" { | 206 | test "string concatenation simple" { |
| 207 | try expect(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED")); | 207 | try expect(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED")); |
| 208 | } | 208 | } |
| 209 | 209 |
test/behavior/comptime_memory.zig+1-1| ... | @@ -45,7 +45,7 @@ test "type pun signed and unsigned as offset many pointer" { | ... | @@ -45,7 +45,7 @@ test "type pun signed and unsigned as offset many pointer" { |
| 45 | } | 45 | } |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | test "type pun signed and unsigned as array pointer" { | 48 | test "type pun signed and unsigned as array pointer with pointer arithemtic" { |
| 49 | if (true) { | 49 | if (true) { |
| 50 | // TODO https://github.com/ziglang/zig/issues/9646 | 50 | // TODO https://github.com/ziglang/zig/issues/9646 |
| 51 | return error.SkipZigTest; | 51 | return error.SkipZigTest; |
test/behavior/duplicated_test_names.zig created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | const Namespace = struct { | ||
| 2 | test "thingy" {} | ||
| 3 | }; | ||
| 4 | |||
| 5 | fn thingy(a: usize, b: usize) usize { | ||
| 6 | return a + b; | ||
| 7 | } | ||
| 8 | |||
| 9 | comptime { | ||
| 10 | _ = Namespace; | ||
| 11 | } | ||
| 12 | |||
| 13 | test "thingy" {} | ||
| 14 | |||
| 15 | test thingy { | ||
| 16 | if (thingy(1, 2) != 3) unreachable; | ||
| 17 | } | ||
test/behavior/vector.zig-14| ... | @@ -1129,20 +1129,6 @@ test "array of vectors is copied" { | ... | @@ -1129,20 +1129,6 @@ test "array of vectors is copied" { |
| 1129 | try std.testing.expectEqual(points2[6], Vec3{ -345, -311, 381 }); | 1129 | try std.testing.expectEqual(points2[6], Vec3{ -345, -311, 381 }); |
| 1130 | } | 1130 | } |
| 1131 | 1131 | ||
| 1132 | test "byte vector initialized in inline function" { | ||
| 1133 | const S = struct { | ||
| 1134 | inline fn boolx4(e0: bool, e1: bool, e2: bool, e3: bool) @Vector(4, bool) { | ||
| 1135 | return .{ e0, e1, e2, e3 }; | ||
| 1136 | } | ||
| 1137 | |||
| 1138 | fn all(vb: @Vector(4, bool)) bool { | ||
| 1139 | return @reduce(.And, vb); | ||
| 1140 | } | ||
| 1141 | }; | ||
| 1142 | |||
| 1143 | try expect(S.all(S.boolx4(true, true, true, true))); | ||
| 1144 | } | ||
| 1145 | |||
| 1146 | test "byte vector initialized in inline function" { | 1132 | test "byte vector initialized in inline function" { |
| 1147 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | 1133 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 1148 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 1134 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
test/cases/compile_errors/invalid_duplicate_test_decl_name.zig created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | test "thingy" {} | ||
| 2 | test "thingy" {} | ||
| 3 | |||
| 4 | // error | ||
| 5 | // backend=stage2 | ||
| 6 | // target=native | ||
| 7 | // is_test=1 | ||
| 8 | // | ||
| 9 | // :1:6: error: found test declaration with duplicate name: test.thingy | ||
| 10 | // :2:6: note: other test here | ||