aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/bugs/13664.zig
blob: 828408510ddcfe2aaa1217b85662a5aa0681f2ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const std = @import("std");
const builtin = @import("builtin");

const Fields = packed struct {
    timestamp: u50,
    random_bits: u13,
};
const ID = packed union {
    value: u63,
    fields: Fields,
};
fn value() i64 {
    return 1341;
}
test {
    if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
    if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
    if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
    if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;

    const timestamp: i64 = value();
    const id = ID{ .fields = Fields{
        .timestamp = @as(u50, @intCast(timestamp)),
        .random_bits = 420,
    } };
    try std.testing.expect((ID{ .value = id.value }).fields.timestamp == timestamp);
}