diff options
| author | LemonBoy <thatlemon@gmail.com> | 2020-04-13 12:49:42 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-04-13 17:35:14 -0400 |
| commit | ce21a784a4bccc66d555b337ebdf98454aaa652f (patch) | |
| tree | ea84e562d1009ae2ee6121fe190760a8d1dd2543 /test | |
| parent | cf750a58d517c03b38509d9d3189c7b7af41820d (diff) | |
| download | zig-ce21a784a4bccc66d555b337ebdf98454aaa652f.tar.gz zig-ce21a784a4bccc66d555b337ebdf98454aaa652f.zip | |
stage1: More fixes for BE targets
* Fix packed struct alignment
* Adjust some tests
Diffstat (limited to 'test')
| -rw-r--r-- | test/stage1/behavior/ptrcast.zig | 10 | ||||
| -rw-r--r-- | test/stage1/behavior/struct.zig | 7 |
2 files changed, 12 insertions, 5 deletions
diff --git a/test/stage1/behavior/ptrcast.zig b/test/stage1/behavior/ptrcast.zig index 3925325e61..26e9545248 100644 --- a/test/stage1/behavior/ptrcast.zig +++ b/test/stage1/behavior/ptrcast.zig @@ -1,5 +1,5 @@ -const builtin = @import("builtin"); const std = @import("std"); +const builtin = std.builtin; const expect = std.testing.expect; test "reinterpret bytes as integer with nonzero offset" { @@ -36,8 +36,12 @@ fn testReinterpretBytesAsExternStruct() void { } test "reinterpret struct field at comptime" { - const numLittle = comptime Bytes.init(0x12345678); - expect(std.mem.eql(u8, &[_]u8{ 0x78, 0x56, 0x34, 0x12 }, &numLittle.bytes)); + const numNative = comptime Bytes.init(0x12345678); + if (builtin.endian != .Little) { + expect(std.mem.eql(u8, &[_]u8{ 0x12, 0x34, 0x56, 0x78 }, &numNative.bytes)); + } else { + expect(std.mem.eql(u8, &[_]u8{ 0x78, 0x56, 0x34, 0x12 }, &numNative.bytes)); + } } const Bytes = struct { diff --git a/test/stage1/behavior/struct.zig b/test/stage1/behavior/struct.zig index 0365991ed3..1203399a24 100644 --- a/test/stage1/behavior/struct.zig +++ b/test/stage1/behavior/struct.zig @@ -1,8 +1,8 @@ const std = @import("std"); +const builtin = std.builtin; const expect = std.testing.expect; const expectEqual = std.testing.expectEqual; const expectEqualSlices = std.testing.expectEqualSlices; -const builtin = @import("builtin"); const maxInt = std.math.maxInt; const StructWithNoFields = struct { fn add(a: i32, b: i32) i32 { @@ -407,7 +407,10 @@ const Bitfields = packed struct { }; test "native bit field understands endianness" { - var all: u64 = 0x7765443322221111; + var all: u64 = if (builtin.endian != .Little) + 0x1111222233445677 + else + 0x7765443322221111; var bytes: [8]u8 = undefined; @memcpy(&bytes, @ptrCast([*]u8, &all), 8); var bitfields = @ptrCast(*Bitfields, &bytes).*; |
