| author | |
| committer | |
| log | 1c8ac2a0c140ba2406f1dc164dc4eeb99a8b6b5b |
| tree | 065ab639f01439fed7c678b494eccf304192bb92 |
| parent | 3038290a469fdac84e4a2a22e0e0926cd8c8448f |
4 files changed, 85 insertions(+), 2 deletions(-)
test/stage1/behavior/for.zig+28| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const expect = std.testing.expect; |
| 3 | const expectEqual = std.testing.expectEqual; | |
| 3 | 4 | const mem = std.mem; |
| 4 | 5 | |
| 5 | 6 | test "continue in for loop" { |
| ... | ... | @@ -142,3 +143,30 @@ test "for with null and T peer types and inferred result location type" { |
| 142 | 143 | S.doTheTest(&[_]u8{ 1, 2 }); |
| 143 | 144 | comptime S.doTheTest(&[_]u8{ 1, 2 }); |
| 144 | 145 | } |
| 146 | ||
| 147 | test "for copies its payload" { | |
| 148 | const S = struct { | |
| 149 | fn doTheTest() void { | |
| 150 | var x = [_]usize{ 1, 2, 3 }; | |
| 151 | for (x) |value, i| { | |
| 152 | // Modify the original array | |
| 153 | x[i] += 99; | |
| 154 | expectEqual(value, i + 1); | |
| 155 | } | |
| 156 | } | |
| 157 | }; | |
| 158 | S.doTheTest(); | |
| 159 | comptime S.doTheTest(); | |
| 160 | } | |
| 161 | ||
| 162 | test "for on slice with allowzero ptr" { | |
| 163 | const S = struct { | |
| 164 | fn doTheTest(slice: []u8) void { | |
| 165 | var ptr = @ptrCast([*]allowzero u8, slice.ptr)[0..slice.len]; | |
| 166 | for (ptr) |x, i| expect(x == i + 1); | |
| 167 | for (ptr) |*x, i| expect(x.* == i + 1); | |
| 168 | } | |
| 169 | }; | |
| 170 | S.doTheTest(&[_]u8{ 1, 2, 3, 4 }); | |
| 171 | comptime S.doTheTest(&[_]u8{ 1, 2, 3, 4 }); | |
| 172 | } |
test/stage1/behavior/if.zig+18-1| ... | ... | @@ -1,4 +1,6 @@ |
| 1 | const expect = @import("std").testing.expect; | |
| 1 | const std = @import("std"); | |
| 2 | const expect = std.testing.expect; | |
| 3 | const expectEqual = std.testing.expectEqual; | |
| 2 | 4 | |
| 3 | 5 | test "if statements" { |
| 4 | 6 | shouldBeEqual(1, 1); |
| ... | ... | @@ -90,3 +92,18 @@ test "if prongs cast to expected type instead of peer type resolution" { |
| 90 | 92 | S.doTheTest(false); |
| 91 | 93 | comptime S.doTheTest(false); |
| 92 | 94 | } |
| 95 | ||
| 96 | test "while copies its payload" { | |
| 97 | const S = struct { | |
| 98 | fn doTheTest() void { | |
| 99 | var tmp: ?i32 = 10; | |
| 100 | if (tmp) |value| { | |
| 101 | // Modify the original variable | |
| 102 | tmp = null; | |
| 103 | expectEqual(@as(i32, 10), value); | |
| 104 | } else unreachable; | |
| 105 | } | |
| 106 | }; | |
| 107 | S.doTheTest(); | |
| 108 | comptime S.doTheTest(); | |
| 109 | } |
test/stage1/behavior/switch.zig+22| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const expect = std.testing.expect; |
| 3 | 3 | const expectError = std.testing.expectError; |
| 4 | const expectEqual = std.testing.expectEqual; | |
| 4 | 5 | |
| 5 | 6 | test "switch with numbers" { |
| 6 | 7 | testSwitchWithNumbers(13); |
| ... | ... | @@ -493,3 +494,24 @@ test "switch on error set with single else" { |
| 493 | 494 | S.doTheTest(); |
| 494 | 495 | comptime S.doTheTest(); |
| 495 | 496 | } |
| 497 | ||
| 498 | test "while copies its payload" { | |
| 499 | const S = struct { | |
| 500 | fn doTheTest() void { | |
| 501 | var tmp: union(enum) { | |
| 502 | A: u8, | |
| 503 | B: u32, | |
| 504 | } = .{ .A = 42 }; | |
| 505 | switch (tmp) { | |
| 506 | .A => |value| { | |
| 507 | // Modify the original union | |
| 508 | tmp = .{ .B = 0x10101010 }; | |
| 509 | expectEqual(@as(u8, 42), value); | |
| 510 | }, | |
| 511 | else => unreachable, | |
| 512 | } | |
| 513 | } | |
| 514 | }; | |
| 515 | S.doTheTest(); | |
| 516 | comptime S.doTheTest(); | |
| 517 | } |
test/stage1/behavior/while.zig+17-1| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | const expect = @import("std").testing.expect; | |
| 1 | const std = @import("std"); | |
| 2 | const expect = std.testing.expect; | |
| 2 | 3 | |
| 3 | 4 | test "while loop" { |
| 4 | 5 | var i: i32 = 0; |
| ... | ... | @@ -271,3 +272,18 @@ test "while error 2 break statements and an else" { |
| 271 | 272 | S.entry(true, false); |
| 272 | 273 | comptime S.entry(true, false); |
| 273 | 274 | } |
| 275 | ||
| 276 | test "while copies its payload" { | |
| 277 | const S = struct { | |
| 278 | fn doTheTest() void { | |
| 279 | var tmp: ?i32 = 10; | |
| 280 | while (tmp) |value| { | |
| 281 | // Modify the original variable | |
| 282 | tmp = null; | |
| 283 | expect(value == 10); | |
| 284 | } | |
| 285 | } | |
| 286 | }; | |
| 287 | S.doTheTest(); | |
| 288 | comptime S.doTheTest(); | |
| 289 | } |