zig/test/cases/optional.zig
Jimmi Holst Christensen 378d3e4403
Solve the return type ambiguity (#1628)
Changed container and initializer syntax
* <container> { ... } -> <container> . { ... }
* <exrp> { ... } -> <expr> . { ...}
2018-10-15 09:51:15 -04:00

31 lines
621 B
Zig

const assert = @import("std").debug.assert;
pub const EmptyStruct = struct.{};
test "optional pointer to size zero struct" {
var e = EmptyStruct.{};
var o: ?*EmptyStruct = &e;
assert(o != null);
}
test "equality compare nullable pointers" {
testNullPtrsEql();
comptime testNullPtrsEql();
}
fn testNullPtrsEql() void {
var number: i32 = 1234;
var x: ?*i32 = null;
var y: ?*i32 = null;
assert(x == y);
y = &number;
assert(x != y);
assert(x != &number);
assert(&number != x);
x = &number;
assert(x == y);
assert(x == &number);
assert(&number == x);
}