master
 1const std = @import("std");
 2const expect = std.testing.expect;
 3
 4const ComplexTypeTag = enum {
 5    ok,
 6    not_ok,
 7};
 8const ComplexType = union(ComplexTypeTag) {
 9    ok: u8,
10    not_ok: void,
11};
12
13test "switch on tagged union" {
14    const c = ComplexType{ .ok = 42 };
15    try expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok);
16
17    switch (c) {
18        .ok => |value| try expect(value == 42),
19        .not_ok => unreachable,
20    }
21}
22
23test "get tag type" {
24    try expect(std.meta.Tag(ComplexType) == ComplexTypeTag);
25}
26
27// test