commit 2a7c8c5b1076667f5b50748c8153fe64ec5b9f13 (tree)
parent 019217d7a23bee69bd5ceb38aeeb5f689d5c2a9c
Author: Andrew Kelley <superjoe30@gmail.com>
Date: Fri, 1 Jun 2018 00:18:10 -0400
add test case for pointer to type and slice of type
closes #588
Diffstat:
1 file changed, 34 insertions(+), 0 deletions(-)
diff --git a/test/cases/eval.zig b/test/cases/eval.zig
@@ -576,3 +576,37 @@ test "comptime modification of const struct field" {
assert(res.version == 1);
}
}
+
+test "pointer to type" {
+ comptime {
+ var T: type = i32;
+ assert(T == i32);
+ var ptr = &T;
+ assert(@typeOf(ptr) == *type);
+ ptr.* = f32;
+ assert(T == f32);
+ assert(*T == *f32);
+ }
+}
+
+test "slice of type" {
+ comptime {
+ var types_array = []type{ i32, f64, type };
+ for (types_array) |T, i| {
+ switch (i) {
+ 0 => assert(T == i32),
+ 1 => assert(T == f64),
+ 2 => assert(T == type),
+ else => unreachable,
+ }
+ }
+ for (types_array[0..]) |T, i| {
+ switch (i) {
+ 0 => assert(T == i32),
+ 1 => assert(T == f64),
+ 2 => assert(T == type),
+ else => unreachable,
+ }
+ }
+ }
+}