aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/enum_llvm.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-01-26 19:59:39 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-01-26 20:02:01 -0700
commit82bd0ac572f14d1e3a13737f4daf00a1ee8041a2 (patch)
tree38efbcea86e28b16a65d36c8866f4870085f9e44 /test/behavior/enum_llvm.zig
parentdb55f469c12c01831bd393c6701c26c15ffe726c (diff)
downloadzig-82bd0ac572f14d1e3a13737f4daf00a1ee8041a2.tar.gz
zig-82bd0ac572f14d1e3a13737f4daf00a1ee8041a2.zip
Sema: implement struct init is_ref=true
Takes advantage of the pattern already established with array_init_anon. Also upgrades array_init (non-anon) to the pattern. Implements comptime struct value equality and pointer value hashing.
Diffstat (limited to 'test/behavior/enum_llvm.zig')
-rw-r--r--test/behavior/enum_llvm.zig105
1 files changed, 0 insertions, 105 deletions
diff --git a/test/behavior/enum_llvm.zig b/test/behavior/enum_llvm.zig
deleted file mode 100644
index 81a1c72e59..0000000000
--- a/test/behavior/enum_llvm.zig
+++ /dev/null
@@ -1,105 +0,0 @@
-const std = @import("std");
-const expect = std.testing.expect;
-const mem = std.mem;
-const Tag = std.meta.Tag;
-
-test "@tagName" {
- try expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
- comptime try expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
-}
-
-fn testEnumTagNameBare(n: anytype) []const u8 {
- return @tagName(n);
-}
-
-const BareNumber = enum { One, Two, Three };
-
-test "@tagName non-exhaustive enum" {
- try expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));
- comptime try expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));
-}
-const NonExhaustive = enum(u8) { A, B, _ };
-
-test "@tagName is null-terminated" {
- const S = struct {
- fn doTheTest(n: BareNumber) !void {
- try expect(@tagName(n)[3] == 0);
- }
- };
- try S.doTheTest(.Two);
- try comptime S.doTheTest(.Two);
-}
-
-test "tag name with assigned enum values" {
- const LocalFoo = enum(u8) {
- A = 1,
- B = 0,
- };
- var b = LocalFoo.B;
- try expect(mem.eql(u8, @tagName(b), "B"));
-}
-
-test "@tagName on enum literals" {
- try expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
- comptime try expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
-}
-
-const Bar = enum { A, B, C, D };
-
-test "enum literal casting to optional" {
- var bar: ?Bar = undefined;
- bar = .B;
-
- try expect(bar.? == Bar.B);
-}
-
-const A = enum(u3) { One, Two, Three, Four, One2, Two2, Three2, Four2 };
-const B = enum(u3) { One3, Two3, Three3, Four3, One23, Two23, Three23, Four23 };
-const C = enum(u2) { One4, Two4, Three4, Four4 };
-
-const BitFieldOfEnums = packed struct {
- a: A,
- b: B,
- c: C,
-};
-
-const bit_field_1 = BitFieldOfEnums{
- .a = A.Two,
- .b = B.Three3,
- .c = C.Four4,
-};
-
-test "bit field access with enum fields" {
- var data = bit_field_1;
- try expect(getA(&data) == A.Two);
- try expect(getB(&data) == B.Three3);
- try expect(getC(&data) == C.Four4);
- comptime try expect(@sizeOf(BitFieldOfEnums) == 1);
-
- data.b = B.Four3;
- try expect(data.b == B.Four3);
-
- data.a = A.Three;
- try expect(data.a == A.Three);
- try expect(data.b == B.Four3);
-}
-
-fn getA(data: *const BitFieldOfEnums) A {
- return data.a;
-}
-
-fn getB(data: *const BitFieldOfEnums) B {
- return data.b;
-}
-
-fn getC(data: *const BitFieldOfEnums) C {
- return data.c;
-}
-
-test "enum literal in array literal" {
- const Items = enum { one, two };
- const array = [_]Items{ .one, .two };
-
- try expect(array[0] == .one);
- try expect(array[1] == .two);
-}