aboutsummaryrefslogtreecommitdiff
path: root/test/behavior
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-10-17 17:02:20 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-10-17 17:02:20 -0700
commite9d1e5e533d12abe14582736d90e4cb173addc56 (patch)
treecb284bafd08c6287cb2ea50312d2cb13f4c91091 /test/behavior
parent07691db3ae061d8122f6c53c1f34c2fb0df2f7ef (diff)
downloadzig-e9d1e5e533d12abe14582736d90e4cb173addc56.tar.gz
zig-e9d1e5e533d12abe14582736d90e4cb173addc56.zip
stage2: LLVM backend: lower constant field/elem ptrs
Diffstat (limited to 'test/behavior')
-rw-r--r--test/behavior/null.zig39
-rw-r--r--test/behavior/null_stage1.zig37
2 files changed, 39 insertions, 37 deletions
diff --git a/test/behavior/null.zig b/test/behavior/null.zig
index 3bd652772b..98018c79bc 100644
--- a/test/behavior/null.zig
+++ b/test/behavior/null.zig
@@ -1,4 +1,5 @@
-const expect = @import("std").testing.expect;
+const std = @import("std");
+const expect = std.testing.expect;
test "optional type" {
const x: ?bool = true;
@@ -58,31 +59,6 @@ fn foo(x: ?i32) ?bool {
return value > 1234;
}
-test "if var maybe pointer" {
- try expect(shouldBeAPlus1(Particle{
- .a = 14,
- .b = 1,
- .c = 1,
- .d = 1,
- }) == 15);
-}
-fn shouldBeAPlus1(p: Particle) u64 {
- var maybe_particle: ?Particle = p;
- if (maybe_particle) |*particle| {
- particle.a += 1;
- }
- if (maybe_particle) |particle| {
- return particle.a;
- }
- return 0;
-}
-const Particle = struct {
- a: u64,
- b: u64,
- c: u64,
- d: u64,
-};
-
test "null literal outside function" {
const is_null = here_is_a_null_literal.context == null;
try expect(is_null);
@@ -146,17 +122,6 @@ test "null with default unwrap" {
try expect(x == 1);
}
-test "optional types" {
- comptime {
- const opt_type_struct = StructWithOptionalType{ .t = u8 };
- try expect(opt_type_struct.t != null and opt_type_struct.t.? == u8);
- }
-}
-
-const StructWithOptionalType = struct {
- t: ?type,
-};
-
test "optional pointer to 0 bit type null value at runtime" {
const EmptyStruct = struct {};
var x: ?*EmptyStruct = null;
diff --git a/test/behavior/null_stage1.zig b/test/behavior/null_stage1.zig
new file mode 100644
index 0000000000..2b8feea242
--- /dev/null
+++ b/test/behavior/null_stage1.zig
@@ -0,0 +1,37 @@
+const expect = @import("std").testing.expect;
+
+test "if var maybe pointer" {
+ try expect(shouldBeAPlus1(Particle{
+ .a = 14,
+ .b = 1,
+ .c = 1,
+ .d = 1,
+ }) == 15);
+}
+fn shouldBeAPlus1(p: Particle) u64 {
+ var maybe_particle: ?Particle = p;
+ if (maybe_particle) |*particle| {
+ particle.a += 1;
+ }
+ if (maybe_particle) |particle| {
+ return particle.a;
+ }
+ return 0;
+}
+const Particle = struct {
+ a: u64,
+ b: u64,
+ c: u64,
+ d: u64,
+};
+
+test "optional types" {
+ comptime {
+ const opt_type_struct = StructWithOptionalType{ .t = u8 };
+ try expect(opt_type_struct.t != null and opt_type_struct.t.? == u8);
+ }
+}
+
+const StructWithOptionalType = struct {
+ t: ?type,
+};