aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-08-25 21:57:28 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-08-25 21:57:28 -0400
commit7109035b78ee05302bbdaadc52013b430a030b69 (patch)
treeae6d7202dc75f2c799f5fbcad72ccf8b02a954a4 /test
parent6cf248ec0824c746fc796905144c8077ccab99cf (diff)
parent526338b00fbe1cac19f64832176af3bdf2108a56 (diff)
downloadzig-7109035b78ee05302bbdaadc52013b430a030b69.tar.gz
zig-7109035b78ee05302bbdaadc52013b430a030b69.zip
Merge remote-tracking branch 'origin/master' into llvm7
Diffstat (limited to 'test')
-rw-r--r--test/behavior.zig1
-rw-r--r--test/cases/bugs/1277.zig15
-rw-r--r--test/cases/cast.zig11
-rw-r--r--test/cases/merge_error_sets.zig4
-rw-r--r--test/translate_c.zig45
5 files changed, 74 insertions, 2 deletions
diff --git a/test/behavior.zig b/test/behavior.zig
index e993d7e0dc..5a26e206bf 100644
--- a/test/behavior.zig
+++ b/test/behavior.zig
@@ -10,6 +10,7 @@ comptime {
_ = @import("cases/bool.zig");
_ = @import("cases/bugs/1111.zig");
_ = @import("cases/bugs/1230.zig");
+ _ = @import("cases/bugs/1277.zig");
_ = @import("cases/bugs/394.zig");
_ = @import("cases/bugs/655.zig");
_ = @import("cases/bugs/656.zig");
diff --git a/test/cases/bugs/1277.zig b/test/cases/bugs/1277.zig
new file mode 100644
index 0000000000..a83e7653e2
--- /dev/null
+++ b/test/cases/bugs/1277.zig
@@ -0,0 +1,15 @@
+const std = @import("std");
+
+const S = struct {
+ f: ?fn () i32,
+};
+
+const s = S{ .f = f };
+
+fn f() i32 {
+ return 1234;
+}
+
+test "don't emit an LLVM global for a const function when it's in an optional in a struct" {
+ std.debug.assertOrPanic(s.f.?() == 1234);
+}
diff --git a/test/cases/cast.zig b/test/cases/cast.zig
index 63cc6313e1..df37bd1dd9 100644
--- a/test/cases/cast.zig
+++ b/test/cases/cast.zig
@@ -485,3 +485,14 @@ fn MakeType(comptime T: type) type {
}
};
}
+
+test "implicit cast from *[N]T to ?[*]T" {
+ var x: ?[*]u16 = null;
+ var y: [4]u16 = [4]u16 {0, 1, 2, 3};
+
+ x = &y;
+ assert(std.mem.eql(u16, x.?[0..4], y[0..4]));
+ x.?[0] = 8;
+ y[3] = 6;
+ assert(std.mem.eql(u16, x.?[0..4], y[0..4]));
+} \ No newline at end of file
diff --git a/test/cases/merge_error_sets.zig b/test/cases/merge_error_sets.zig
index 189bd16a4d..147b580232 100644
--- a/test/cases/merge_error_sets.zig
+++ b/test/cases/merge_error_sets.zig
@@ -1,5 +1,5 @@
const A = error{
- PathNotFound,
+ FileNotFound,
NotDir,
};
const B = error{OutOfMemory};
@@ -15,7 +15,7 @@ test "merge error sets" {
@panic("unexpected");
} else |err| switch (err) {
error.OutOfMemory => @panic("unexpected"),
- error.PathNotFound => @panic("unexpected"),
+ error.FileNotFound => @panic("unexpected"),
error.NotDir => {},
}
}
diff --git a/test/translate_c.zig b/test/translate_c.zig
index 417171d2c2..b31e515aa2 100644
--- a/test/translate_c.zig
+++ b/test/translate_c.zig
@@ -1,6 +1,51 @@
const tests = @import("tests.zig");
pub fn addCases(cases: *tests.TranslateCContext) void {
+ cases.add("for loop with var init but empty body",
+ \\void foo(void) {
+ \\ for (int x = 0; x < 10; x++);
+ \\}
+ ,
+ \\pub fn foo() void {
+ \\ {
+ \\ var x: c_int = 0;
+ \\ while (x < 10) : (x += 1) {}
+ \\ }
+ \\}
+ );
+
+ cases.add("do while with empty body",
+ \\void foo(void) {
+ \\ do ; while (1);
+ \\}
+ , // TODO this should be if (1 != 0) break
+ \\pub fn foo() void {
+ \\ while (true) {
+ \\ if (!1) break;
+ \\ }
+ \\}
+ );
+
+ cases.add("for with empty body",
+ \\void foo(void) {
+ \\ for (;;);
+ \\}
+ ,
+ \\pub fn foo() void {
+ \\ while (true) {}
+ \\}
+ );
+
+ cases.add("while with empty body",
+ \\void foo(void) {
+ \\ while (1);
+ \\}
+ ,
+ \\pub fn foo() void {
+ \\ while (1 != 0) {}
+ \\}
+ );
+
cases.add("double define struct",
\\typedef struct Bar Bar;
\\typedef struct Foo Foo;