aboutsummaryrefslogtreecommitdiff
path: root/test/self_hosted.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-02-07 15:43:19 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-02-07 15:43:19 -0700
commit42fe4e3cc8a05206e86a5b4cc2edb0dc4871a2c0 (patch)
tree1d830201fa2b24d9b0c2ebaadc7b4cfce74784b6 /test/self_hosted.zig
parent36cf9f0c721a9b1be04490d06dffae9e070fd724 (diff)
downloadzig-42fe4e3cc8a05206e86a5b4cc2edb0dc4871a2c0.tar.gz
zig-42fe4e3cc8a05206e86a5b4cc2edb0dc4871a2c0.zip
remove ptr field access of arrays
use &array[0] instead
Diffstat (limited to 'test/self_hosted.zig')
-rw-r--r--test/self_hosted.zig29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/self_hosted.zig b/test/self_hosted.zig
index 2ea44adaaa..663daf6827 100644
--- a/test/self_hosted.zig
+++ b/test/self_hosted.zig
@@ -240,3 +240,32 @@ fn builtin_const_eval() {
const x : i32 = @const_eval(1 + 2 + 3);
if (x != @const_eval(6)) unreachable{};
}
+
+#attribute("test")
+fn slicing() {
+ var array : [20]i32 = undefined;
+
+ array[5] = 1234;
+
+ var slice = array[5...10];
+
+ if (slice.len != 5) unreachable{};
+
+ const ptr = &slice[0];
+ if (ptr[0] != 1234) unreachable{};
+
+ var slice_rest = array[10...];
+ if (slice_rest.len != 10) unreachable{};
+}
+
+
+#attribute("test")
+fn memcpy_and_memset_intrinsics() {
+ var foo : [20]u8 = undefined;
+ var bar : [20]u8 = undefined;
+
+ @memset(&foo[0], 'A', foo.len);
+ @memcpy(&bar[0], &foo[0], bar.len);
+
+ if (bar[11] != 'A') unreachable{};
+}