aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-08-23 08:25:26 -0400
committerGitHub <noreply@github.com>2018-08-23 08:25:26 -0400
commit68dcdf1c867a918aa0bb7b5c4cb42df185e1c8f9 (patch)
tree6bac6ca779a392c5fec4dcf29f18608763d6ddab /std
parent4b68ef45af54abd7ba56878f93132ca608891cf1 (diff)
parente95345b3dce204c4c463294b3dfdb09f9f6d9795 (diff)
downloadzig-68dcdf1c867a918aa0bb7b5c4cb42df185e1c8f9.tar.gz
zig-68dcdf1c867a918aa0bb7b5c4cb42df185e1c8f9.zip
Merge pull request #1401 from kristate/mem-testWriteIntImpl-u64
std/mem.zig: test writing u64 integers;
Diffstat (limited to 'std')
-rw-r--r--std/mem.zig42
1 files changed, 41 insertions, 1 deletions
diff --git a/std/mem.zig b/std/mem.zig
index 1ba5b3b73e..4390f8ad5b 100644
--- a/std/mem.zig
+++ b/std/mem.zig
@@ -679,10 +679,38 @@ test "testWriteInt" {
comptime testWriteIntImpl();
}
fn testWriteIntImpl() void {
- var bytes: [4]u8 = undefined;
+ var bytes: [8]u8 = undefined;
+
+ writeInt(bytes[0..], u64(0x12345678CAFEBABE), builtin.Endian.Big);
+ assert(eql(u8, bytes, []u8{
+ 0x12,
+ 0x34,
+ 0x56,
+ 0x78,
+ 0xCA,
+ 0xFE,
+ 0xBA,
+ 0xBE,
+ }));
+
+ writeInt(bytes[0..], u64(0xBEBAFECA78563412), builtin.Endian.Little);
+ assert(eql(u8, bytes, []u8{
+ 0x12,
+ 0x34,
+ 0x56,
+ 0x78,
+ 0xCA,
+ 0xFE,
+ 0xBA,
+ 0xBE,
+ }));
writeInt(bytes[0..], u32(0x12345678), builtin.Endian.Big);
assert(eql(u8, bytes, []u8{
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
0x12,
0x34,
0x56,
@@ -695,12 +723,20 @@ fn testWriteIntImpl() void {
0x34,
0x56,
0x78,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
}));
writeInt(bytes[0..], u16(0x1234), builtin.Endian.Big);
assert(eql(u8, bytes, []u8{
0x00,
0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
0x12,
0x34,
}));
@@ -711,6 +747,10 @@ fn testWriteIntImpl() void {
0x12,
0x00,
0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
}));
}