authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-01 00:18:10-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-01 00:18:10-04:00
log2a7c8c5b1076667f5b50748c8153fe64ec5b9f13
treea34d2813903a638c3b9cb42a8a8a11d742c294f7
parent019217d7a23bee69bd5ceb38aeeb5f689d5c2a9c

add test case for pointer to type and slice of type

closes #588

1 files changed, 34 insertions(+), 0 deletions(-)

test/cases/eval.zig+34
...@@ -576,3 +576,37 @@ test "comptime modification of const struct field" {...@@ -576,3 +576,37 @@ test "comptime modification of const struct field" {
576 assert(res.version == 1);576 assert(res.version == 1);
577 }577 }
578}578}
579
580test "pointer to type" {
581 comptime {
582 var T: type = i32;
583 assert(T == i32);
584 var ptr = &T;
585 assert(@typeOf(ptr) == *type);
586 ptr.* = f32;
587 assert(T == f32);
588 assert(*T == *f32);
589 }
590}
591
592test "slice of type" {
593 comptime {
594 var types_array = []type{ i32, f64, type };
595 for (types_array) |T, i| {
596 switch (i) {
597 0 => assert(T == i32),
598 1 => assert(T == f64),
599 2 => assert(T == type),
600 else => unreachable,
601 }
602 }
603 for (types_array[0..]) |T, i| {
604 switch (i) {
605 0 => assert(T == i32),
606 1 => assert(T == f64),
607 2 => assert(T == type),
608 else => unreachable,
609 }
610 }
611 }
612}