mirror of
https://github.com/ziglang/zig.git
synced 2024-11-24 13:20:14 +00:00
use expectEqual for packed struct equality in tests
This commit is contained in:
parent
decfa371b5
commit
98c4e6ea45
@ -379,12 +379,12 @@ test "readStructEndian reads packed structs without padding and in correct field
|
|||||||
|
|
||||||
const PackedStruct = packed struct(u24) { a: u8, b: u8, c: u8 };
|
const PackedStruct = packed struct(u24) { a: u8, b: u8, c: u8 };
|
||||||
|
|
||||||
try testing.expectEqualDeep(
|
try testing.expectEqual(
|
||||||
PackedStruct{ .a = 11, .b = 12, .c = 13 },
|
PackedStruct{ .a = 11, .b = 12, .c = 13 },
|
||||||
reader.readStructEndian(PackedStruct, .little),
|
reader.readStructEndian(PackedStruct, .little),
|
||||||
);
|
);
|
||||||
fis.reset();
|
fis.reset();
|
||||||
try testing.expectEqualDeep(
|
try testing.expectEqual(
|
||||||
PackedStruct{ .a = 13, .b = 12, .c = 11 },
|
PackedStruct{ .a = 13, .b = 12, .c = 11 },
|
||||||
reader.readStructEndian(PackedStruct, .big),
|
reader.readStructEndian(PackedStruct, .big),
|
||||||
);
|
);
|
||||||
@ -399,13 +399,13 @@ test "readStruct reads packed structs without padding and in correct field order
|
|||||||
|
|
||||||
switch (native_endian) {
|
switch (native_endian) {
|
||||||
.little => {
|
.little => {
|
||||||
try testing.expectEqualDeep(
|
try testing.expectEqual(
|
||||||
PackedStruct{ .a = 11, .b = 12, .c = 13 },
|
PackedStruct{ .a = 11, .b = 12, .c = 13 },
|
||||||
reader.readStruct(PackedStruct),
|
reader.readStruct(PackedStruct),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
.big => {
|
.big => {
|
||||||
try testing.expectEqualDeep(
|
try testing.expectEqual(
|
||||||
PackedStruct{ .a = 13, .b = 12, .c = 11 },
|
PackedStruct{ .a = 13, .b = 12, .c = 11 },
|
||||||
reader.readStruct(PackedStruct),
|
reader.readStruct(PackedStruct),
|
||||||
);
|
);
|
||||||
@ -430,7 +430,7 @@ test "readStruct writeStruct round-trip with packed structs" {
|
|||||||
const expected_packed_struct = PackedStruct{};
|
const expected_packed_struct = PackedStruct{};
|
||||||
try writer.writeStruct(expected_packed_struct);
|
try writer.writeStruct(expected_packed_struct);
|
||||||
fis.reset();
|
fis.reset();
|
||||||
try testing.expectEqualDeep(expected_packed_struct, try reader.readStruct(PackedStruct));
|
try testing.expectEqual(expected_packed_struct, try reader.readStruct(PackedStruct));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "readStructEndian writeStructEndian round-trip with packed structs" {
|
test "readStructEndian writeStructEndian round-trip with packed structs" {
|
||||||
@ -450,12 +450,12 @@ test "readStructEndian writeStructEndian round-trip with packed structs" {
|
|||||||
// round-trip little endian
|
// round-trip little endian
|
||||||
try writer.writeStructEndian(expected_packed_struct, .big);
|
try writer.writeStructEndian(expected_packed_struct, .big);
|
||||||
fis.reset();
|
fis.reset();
|
||||||
try testing.expectEqualDeep(expected_packed_struct, try reader.readStructEndian(PackedStruct, .big));
|
try testing.expectEqual(expected_packed_struct, try reader.readStructEndian(PackedStruct, .big));
|
||||||
// round-trip big endian
|
// round-trip big endian
|
||||||
fis.reset();
|
fis.reset();
|
||||||
try writer.writeStructEndian(expected_packed_struct, .little);
|
try writer.writeStructEndian(expected_packed_struct, .little);
|
||||||
fis.reset();
|
fis.reset();
|
||||||
try testing.expectEqualDeep(expected_packed_struct, try reader.readStructEndian(PackedStruct, .little));
|
try testing.expectEqual(expected_packed_struct, try reader.readStructEndian(PackedStruct, .little));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "readStruct a packed struct with endianness-affected types" {
|
test "readStruct a packed struct with endianness-affected types" {
|
||||||
@ -467,13 +467,13 @@ test "readStruct a packed struct with endianness-affected types" {
|
|||||||
|
|
||||||
switch (native_endian) {
|
switch (native_endian) {
|
||||||
.little => {
|
.little => {
|
||||||
try testing.expectEqualDeep(
|
try testing.expectEqual(
|
||||||
PackedStruct{ .a = 0x3412, .b = 0x7856 },
|
PackedStruct{ .a = 0x3412, .b = 0x7856 },
|
||||||
reader.readStruct(PackedStruct),
|
reader.readStruct(PackedStruct),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
.big => {
|
.big => {
|
||||||
try testing.expectEqualDeep(
|
try testing.expectEqual(
|
||||||
PackedStruct{ .a = 0x5678, .b = 0x1234 },
|
PackedStruct{ .a = 0x5678, .b = 0x1234 },
|
||||||
reader.readStruct(PackedStruct),
|
reader.readStruct(PackedStruct),
|
||||||
);
|
);
|
||||||
@ -488,12 +488,12 @@ test "readStructEndian a packed struct with endianness-affected types" {
|
|||||||
|
|
||||||
const PackedStruct = packed struct(u32) { a: u16, b: u16 };
|
const PackedStruct = packed struct(u32) { a: u16, b: u16 };
|
||||||
|
|
||||||
try testing.expectEqualDeep(
|
try testing.expectEqual(
|
||||||
PackedStruct{ .a = 0x3412, .b = 0x7856 },
|
PackedStruct{ .a = 0x3412, .b = 0x7856 },
|
||||||
reader.readStructEndian(PackedStruct, .little),
|
reader.readStructEndian(PackedStruct, .little),
|
||||||
);
|
);
|
||||||
fis.reset();
|
fis.reset();
|
||||||
try testing.expectEqualDeep(
|
try testing.expectEqual(
|
||||||
PackedStruct{ .a = 0x5678, .b = 0x1234 },
|
PackedStruct{ .a = 0x5678, .b = 0x1234 },
|
||||||
reader.readStructEndian(PackedStruct, .big),
|
reader.readStructEndian(PackedStruct, .big),
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user