feature. See also
. The project being documented here (as the example) is the Zig library itself.
mem.moreReadIntTests
fn moreReadIntTests() !void
File
Code
fn moreReadIntTests() !void {
{
const bytes = [_]u8{
0x12,
0x34,
0x56,
0x78,
};
try testing.expect(readInt(u32, &bytes, .big) == 0x12345678);
try testing.expect(readInt(u32, &bytes, .big) == 0x12345678);
try testing.expect(readInt(i32, &bytes, .big) == 0x12345678);
try testing.expect(readInt(u32, &bytes, .little) == 0x78563412);
try testing.expect(readInt(u32, &bytes, .little) == 0x78563412);
try testing.expect(readInt(i32, &bytes, .little) == 0x78563412);
}
{
const buf = [_]u8{
0x00,
0x00,
0x12,
0x34,
};
const answer = readInt(u32, &buf, .big);
try testing.expect(answer == 0x00001234);
}
{
const buf = [_]u8{
0x12,
0x34,
0x00,
0x00,
};
const answer = readInt(u32, &buf, .little);
try testing.expect(answer == 0x00003412);
}
{
const bytes = [_]u8{
0xff,
0xfe,
};
try testing.expect(readInt(u16, &bytes, .big) == 0xfffe);
try testing.expect(readInt(i16, &bytes, .big) == -0x0002);
try testing.expect(readInt(u16, &bytes, .little) == 0xfeff);
try testing.expect(readInt(i16, &bytes, .little) == -0x0101);
}
}