authorgravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2023-10-07 22:46:35+02:00
committergravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2024-01-03 21:20:48+01:00
logd7b36503cad1de60cd0b6a115ef7ac336a03a09a
treeb4ae3fbe2147b223543dc5ac62d39a13b65248db
parent4c1da0912a474228750362a11db85799cac311b9

Remove some `@as` coercions from assertions

These are some spurious fixes to help illustrate the improved ergonomics of the `expectEqual` change. It is by no means complete.

4 files changed, 42 insertions(+), 42 deletions(-)

lib/std/debug.zig+2-2
...@@ -853,8 +853,8 @@ test "machoSearchSymbols" {...@@ -853,8 +853,8 @@ test "machoSearchSymbols" {
853 .{ .addr = 300, .strx = undefined, .size = undefined, .ofile = undefined },853 .{ .addr = 300, .strx = undefined, .size = undefined, .ofile = undefined },
854 };854 };
855855
856 try testing.expectEqual(@as(?*const MachoSymbol, null), machoSearchSymbols(&symbols, 0));856 try testing.expectEqual(null, machoSearchSymbols(&symbols, 0));
857 try testing.expectEqual(@as(?*const MachoSymbol, null), machoSearchSymbols(&symbols, 99));857 try testing.expectEqual(null, machoSearchSymbols(&symbols, 99));
858 try testing.expectEqual(&symbols[0], machoSearchSymbols(&symbols, 100).?);858 try testing.expectEqual(&symbols[0], machoSearchSymbols(&symbols, 100).?);
859 try testing.expectEqual(&symbols[0], machoSearchSymbols(&symbols, 150).?);859 try testing.expectEqual(&symbols[0], machoSearchSymbols(&symbols, 150).?);
860 try testing.expectEqual(&symbols[0], machoSearchSymbols(&symbols, 199).?);860 try testing.expectEqual(&symbols[0], machoSearchSymbols(&symbols, 199).?);
lib/std/http.zig+2-2
...@@ -283,8 +283,8 @@ pub const Status = enum(u10) {...@@ -283,8 +283,8 @@ pub const Status = enum(u10) {
283 }283 }
284284
285 test {285 test {
286 try std.testing.expectEqual(@as(?Status.Class, Status.Class.success), Status.ok.class());286 try std.testing.expectEqual(Status.Class.success, Status.ok.class());
287 try std.testing.expectEqual(@as(?Status.Class, Status.Class.client_error), Status.not_found.class());287 try std.testing.expectEqual(Status.Class.client_error, Status.not_found.class());
288 }288 }
289};289};
290290
lib/std/json/static_test.zig+13-13
...@@ -373,19 +373,19 @@ test "test all types" {...@@ -373,19 +373,19 @@ test "test all types" {
373test "parse" {373test "parse" {
374 try testing.expectEqual(false, try parseFromSliceLeaky(bool, testing.allocator, "false", .{}));374 try testing.expectEqual(false, try parseFromSliceLeaky(bool, testing.allocator, "false", .{}));
375 try testing.expectEqual(true, try parseFromSliceLeaky(bool, testing.allocator, "true", .{}));375 try testing.expectEqual(true, try parseFromSliceLeaky(bool, testing.allocator, "true", .{}));
376 try testing.expectEqual(@as(u1, 1), try parseFromSliceLeaky(u1, testing.allocator, "1", .{}));376 try testing.expectEqual(1, try parseFromSliceLeaky(u1, testing.allocator, "1", .{}));
377 try testing.expectError(error.Overflow, parseFromSliceLeaky(u1, testing.allocator, "50", .{}));377 try testing.expectError(error.Overflow, parseFromSliceLeaky(u1, testing.allocator, "50", .{}));
378 try testing.expectEqual(@as(u64, 42), try parseFromSliceLeaky(u64, testing.allocator, "42", .{}));378 try testing.expectEqual(42, try parseFromSliceLeaky(u64, testing.allocator, "42", .{}));
379 try testing.expectEqual(@as(f64, 42), try parseFromSliceLeaky(f64, testing.allocator, "42.0", .{}));379 try testing.expectEqual(42, try parseFromSliceLeaky(f64, testing.allocator, "42.0", .{}));
380 try testing.expectEqual(@as(?bool, null), try parseFromSliceLeaky(?bool, testing.allocator, "null", .{}));380 try testing.expectEqual(null, try parseFromSliceLeaky(?bool, testing.allocator, "null", .{}));
381 try testing.expectEqual(@as(?bool, true), try parseFromSliceLeaky(?bool, testing.allocator, "true", .{}));381 try testing.expectEqual(true, try parseFromSliceLeaky(?bool, testing.allocator, "true", .{}));
382382
383 try testing.expectEqual(@as([3]u8, "foo".*), try parseFromSliceLeaky([3]u8, testing.allocator, "\"foo\"", .{}));383 try testing.expectEqual("foo".*, try parseFromSliceLeaky([3]u8, testing.allocator, "\"foo\"", .{}));
384 try testing.expectEqual(@as([3]u8, "foo".*), try parseFromSliceLeaky([3]u8, testing.allocator, "[102, 111, 111]", .{}));384 try testing.expectEqual("foo".*, try parseFromSliceLeaky([3]u8, testing.allocator, "[102, 111, 111]", .{}));
385 try testing.expectEqual(@as([0]u8, undefined), try parseFromSliceLeaky([0]u8, testing.allocator, "[]", .{}));385 try testing.expectEqual(undefined, try parseFromSliceLeaky([0]u8, testing.allocator, "[]", .{}));
386386
387 try testing.expectEqual(@as(u64, 12345678901234567890), try parseFromSliceLeaky(u64, testing.allocator, "\"12345678901234567890\"", .{}));387 try testing.expectEqual(12345678901234567890, try parseFromSliceLeaky(u64, testing.allocator, "\"12345678901234567890\"", .{}));
388 try testing.expectEqual(@as(f64, 123.456), try parseFromSliceLeaky(f64, testing.allocator, "\"123.456\"", .{}));388 try testing.expectEqual(123.456, try parseFromSliceLeaky(f64, testing.allocator, "\"123.456\"", .{}));
389}389}
390390
391test "parse into enum" {391test "parse into enum" {
...@@ -394,9 +394,9 @@ test "parse into enum" {...@@ -394,9 +394,9 @@ test "parse into enum" {
394 Bar,394 Bar,
395 @"with\\escape",395 @"with\\escape",
396 };396 };
397 try testing.expectEqual(@as(T, .Foo), try parseFromSliceLeaky(T, testing.allocator, "\"Foo\"", .{}));397 try testing.expectEqual(.Foo, try parseFromSliceLeaky(T, testing.allocator, "\"Foo\"", .{}));
398 try testing.expectEqual(@as(T, .Foo), try parseFromSliceLeaky(T, testing.allocator, "42", .{}));398 try testing.expectEqual(.Foo, try parseFromSliceLeaky(T, testing.allocator, "42", .{}));
399 try testing.expectEqual(@as(T, .@"with\\escape"), try parseFromSliceLeaky(T, testing.allocator, "\"with\\\\escape\"", .{}));399 try testing.expectEqual(.@"with\\escape", try parseFromSliceLeaky(T, testing.allocator, "\"with\\\\escape\"", .{}));
400 try testing.expectError(error.InvalidEnumTag, parseFromSliceLeaky(T, testing.allocator, "5", .{}));400 try testing.expectError(error.InvalidEnumTag, parseFromSliceLeaky(T, testing.allocator, "5", .{}));
401 try testing.expectError(error.InvalidEnumTag, parseFromSliceLeaky(T, testing.allocator, "\"Qux\"", .{}));401 try testing.expectError(error.InvalidEnumTag, parseFromSliceLeaky(T, testing.allocator, "\"Qux\"", .{}));
402}402}
test/behavior/packed-struct.zig+25-25
...@@ -173,17 +173,17 @@ test "correct sizeOf and offsets in packed structs" {...@@ -173,17 +173,17 @@ test "correct sizeOf and offsets in packed structs" {
173 try expectEqual(true, s1.bool_d);173 try expectEqual(true, s1.bool_d);
174 try expectEqual(true, s1.bool_e);174 try expectEqual(true, s1.bool_e);
175 try expectEqual(true, s1.bool_f);175 try expectEqual(true, s1.bool_f);
176 try expectEqual(@as(u1, 1), s1.u1_a);176 try expectEqual(1, s1.u1_a);
177 try expectEqual(false, s1.bool_g);177 try expectEqual(false, s1.bool_g);
178 try expectEqual(@as(u1, 0), s1.u1_b);178 try expectEqual(0, s1.u1_b);
179 try expectEqual(@as(u3, 3), s1.u3_a);179 try expectEqual(3, s1.u3_a);
180 try expectEqual(@as(u10, 0b1101000101), s1.u10_a);180 try expectEqual(0b1101000101, s1.u10_a);
181 try expectEqual(@as(u10, 0b0001001000), s1.u10_b);181 try expectEqual(0b0001001000, s1.u10_b);
182182
183 const s2 = @as(packed struct { x: u1, y: u7, z: u24 }, @bitCast(@as(u32, 0xd5c71ff4)));183 const s2 = @as(packed struct { x: u1, y: u7, z: u24 }, @bitCast(@as(u32, 0xd5c71ff4)));
184 try expectEqual(@as(u1, 0), s2.x);184 try expectEqual(0, s2.x);
185 try expectEqual(@as(u7, 0b1111010), s2.y);185 try expectEqual(0b1111010, s2.y);
186 try expectEqual(@as(u24, 0xd5c71f), s2.z);186 try expectEqual(0xd5c71f, s2.z);
187 }187 }
188}188}
189189
...@@ -208,12 +208,12 @@ test "nested packed structs" {...@@ -208,12 +208,12 @@ test "nested packed structs" {
208208
209 if (native_endian == .little) {209 if (native_endian == .little) {
210 const s3 = @as(S3Padded, @bitCast(@as(u64, 0xe952d5c71ff4))).s3;210 const s3 = @as(S3Padded, @bitCast(@as(u64, 0xe952d5c71ff4))).s3;
211 try expectEqual(@as(u8, 0xf4), s3.x.a);211 try expectEqual(0xf4, s3.x.a);
212 try expectEqual(@as(u8, 0x1f), s3.x.b);212 try expectEqual(0x1f, s3.x.b);
213 try expectEqual(@as(u8, 0xc7), s3.x.c);213 try expectEqual(0xc7, s3.x.c);
214 try expectEqual(@as(u8, 0xd5), s3.y.d);214 try expectEqual(0xd5, s3.y.d);
215 try expectEqual(@as(u8, 0x52), s3.y.e);215 try expectEqual(0x52, s3.y.e);
216 try expectEqual(@as(u8, 0xe9), s3.y.f);216 try expectEqual(0xe9, s3.y.f);
217 }217 }
218218
219 const S4 = packed struct { a: i32, b: i8 };219 const S4 = packed struct { a: i32, b: i8 };
...@@ -249,8 +249,8 @@ test "regular in irregular packed struct" {...@@ -249,8 +249,8 @@ test "regular in irregular packed struct" {
249 foo.bar.a = 235;249 foo.bar.a = 235;
250 foo.bar.b = 42;250 foo.bar.b = 42;
251251
252 try expectEqual(@as(u16, 235), foo.bar.a);252 try expectEqual(235, foo.bar.a);
253 try expectEqual(@as(u8, 42), foo.bar.b);253 try expectEqual(42, foo.bar.b);
254}254}
255255
256test "nested packed struct unaligned" {256test "nested packed struct unaligned" {
...@@ -456,12 +456,12 @@ test "nested packed struct field pointers" {...@@ -456,12 +456,12 @@ test "nested packed struct field pointers" {
456 const ptr_p0_c = &S2.s.p0.c;456 const ptr_p0_c = &S2.s.p0.c;
457 const ptr_p1_a = &S2.s.p1.a;457 const ptr_p1_a = &S2.s.p1.a;
458 const ptr_p1_b = &S2.s.p1.b;458 const ptr_p1_b = &S2.s.p1.b;
459 try expectEqual(@as(u8, 1), ptr_base.*);459 try expectEqual(1, ptr_base.*);
460 try expectEqual(@as(u4, 2), ptr_p0_a.*);460 try expectEqual(2, ptr_p0_a.*);
461 try expectEqual(@as(u4, 3), ptr_p0_b.*);461 try expectEqual(3, ptr_p0_b.*);
462 try expectEqual(@as(u8, 4), ptr_p0_c.*);462 try expectEqual(4, ptr_p0_c.*);
463 try expectEqual(@as(u7, 5), ptr_p1_a.*);463 try expectEqual(5, ptr_p1_a.*);
464 try expectEqual(@as(u8, 6), ptr_p1_b.*);464 try expectEqual(6, ptr_p1_b.*);
465}465}
466466
467test "load pointer from packed struct" {467test "load pointer from packed struct" {
...@@ -1033,12 +1033,12 @@ test "modify nested packed struct aligned field" {...@@ -1033,12 +1033,12 @@ test "modify nested packed struct aligned field" {
10331033
1034 var opts = Options{};1034 var opts = Options{};
1035 opts.pretty_print.indent += 1;1035 opts.pretty_print.indent += 1;
1036 try std.testing.expectEqual(@as(u17, 0b00000000100100000), @as(u17, @bitCast(opts)));1036 try std.testing.expectEqual(0b00000000100100000, @as(u17, @bitCast(opts)));
1037 try std.testing.expect(!opts.foo);1037 try std.testing.expect(!opts.foo);
1038 try std.testing.expect(!opts.bar);1038 try std.testing.expect(!opts.bar);
1039 try std.testing.expect(!opts.pretty_print.enabled);1039 try std.testing.expect(!opts.pretty_print.enabled);
1040 try std.testing.expectEqual(@as(u4, 4), opts.pretty_print.num_spaces);1040 try std.testing.expectEqual(4, opts.pretty_print.num_spaces);
1041 try std.testing.expectEqual(@as(u8, 1), opts.pretty_print.indent);1041 try std.testing.expectEqual(1, opts.pretty_print.indent);
1042 try std.testing.expect(!opts.baz);1042 try std.testing.expect(!opts.baz);
1043}1043}
10441044