| ... | ... | @@ -5,6 +5,8 @@ const maxInt = std.math.maxInt; |
| 5 | 5 | const builtin = @import("builtin"); |
| 6 | 6 | |
| 7 | 7 | test "int to ptr cast" { |
| 8 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 9 | |
| 8 | 10 | const x = @as(usize, 13); |
| 9 | 11 | const y = @intToPtr(*u8, x); |
| 10 | 12 | const z = @ptrToInt(y); |
| ... | ... | @@ -12,11 +14,15 @@ test "int to ptr cast" { |
| 12 | 14 | } |
| 13 | 15 | |
| 14 | 16 | test "integer literal to pointer cast" { |
| 17 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 18 | |
| 15 | 19 | const vga_mem = @intToPtr(*u16, 0xB8000); |
| 16 | 20 | try expect(@ptrToInt(vga_mem) == 0xB8000); |
| 17 | 21 | } |
| 18 | 22 | |
| 19 | 23 | test "peer type resolution: ?T and T" { |
| 24 | if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 25 | |
| 20 | 26 | try expect(peerTypeTAndOptionalT(true, false).? == 0); |
| 21 | 27 | try expect(peerTypeTAndOptionalT(false, false).? == 3); |
| 22 | 28 | comptime { |
| ... | ... | @@ -33,6 +39,8 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { |
| 33 | 39 | } |
| 34 | 40 | |
| 35 | 41 | test "resolve undefined with integer" { |
| 42 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 43 | |
| 36 | 44 | try testResolveUndefWithInt(true, 1234); |
| 37 | 45 | comptime try testResolveUndefWithInt(true, 1234); |
| 38 | 46 | } |
| ... | ... | @@ -88,6 +96,8 @@ test "comptime_int @intToFloat" { |
| 88 | 96 | } |
| 89 | 97 | |
| 90 | 98 | test "@floatToInt" { |
| 99 | if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 100 | |
| 91 | 101 | try testFloatToInts(); |
| 92 | 102 | comptime try testFloatToInts(); |
| 93 | 103 | } |
| ... | ... | @@ -107,6 +117,8 @@ fn expectFloatToInt(comptime F: type, f: F, comptime I: type, i: I) !void { |
| 107 | 117 | } |
| 108 | 118 | |
| 109 | 119 | test "implicitly cast indirect pointer to maybe-indirect pointer" { |
| 120 | if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 121 | |
| 110 | 122 | const S = struct { |
| 111 | 123 | const Self = @This(); |
| 112 | 124 | x: u8, |
| ... | ... | @@ -163,6 +175,8 @@ test "@floatCast comptime_int and comptime_float" { |
| 163 | 175 | } |
| 164 | 176 | |
| 165 | 177 | test "coerce undefined to optional" { |
| 178 | if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 179 | |
| 166 | 180 | try expect(MakeType(void).getNull() == null); |
| 167 | 181 | try expect(MakeType(void).getNonNull() != null); |
| 168 | 182 | } |
| ... | ... | @@ -180,6 +194,8 @@ fn MakeType(comptime T: type) type { |
| 180 | 194 | } |
| 181 | 195 | |
| 182 | 196 | test "implicit cast from *[N]T to [*c]T" { |
| 197 | if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 198 | |
| 183 | 199 | var x: [4]u16 = [4]u16{ 0, 1, 2, 3 }; |
| 184 | 200 | var y: [*c]u16 = &x; |
| 185 | 201 | |
| ... | ... | @@ -190,6 +206,8 @@ test "implicit cast from *[N]T to [*c]T" { |
| 190 | 206 | } |
| 191 | 207 | |
| 192 | 208 | test "*usize to *void" { |
| 209 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 210 | |
| 193 | 211 | var i = @as(usize, 0); |
| 194 | 212 | var v = @ptrCast(*void, &i); |
| 195 | 213 | v.* = {}; |
| ... | ... | @@ -202,6 +220,8 @@ test "@intToEnum passed a comptime_int to an enum with one item" { |
| 202 | 220 | } |
| 203 | 221 | |
| 204 | 222 | test "@intCast to u0 and use the result" { |
| 223 | if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 224 | |
| 205 | 225 | const S = struct { |
| 206 | 226 | fn doTheTest(zero: u1, one: u1, bigzero: i32) !void { |
| 207 | 227 | try expect((one << @intCast(u0, bigzero)) == 1); |
| ... | ... | @@ -213,6 +233,8 @@ test "@intCast to u0 and use the result" { |
| 213 | 233 | } |
| 214 | 234 | |
| 215 | 235 | test "peer result null and comptime_int" { |
| 236 | if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 237 | |
| 216 | 238 | const S = struct { |
| 217 | 239 | fn blah(n: i32) ?i32 { |
| 218 | 240 | if (n == 0) { |
| ... | ... | @@ -234,6 +256,8 @@ test "peer result null and comptime_int" { |
| 234 | 256 | } |
| 235 | 257 | |
| 236 | 258 | test "*const ?[*]const T to [*c]const [*c]const T" { |
| 259 | if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 260 | |
| 237 | 261 | var array = [_]u8{ 'o', 'k' }; |
| 238 | 262 | const opt_array_ptr: ?[*]const u8 = &array; |
| 239 | 263 | const a: *const ?[*]const u8 = &opt_array_ptr; |
| ... | ... | @@ -243,6 +267,8 @@ test "*const ?[*]const T to [*c]const [*c]const T" { |
| 243 | 267 | } |
| 244 | 268 | |
| 245 | 269 | test "array coersion to undefined at runtime" { |
| 270 | if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 271 | |
| 246 | 272 | @setRuntimeSafety(true); |
| 247 | 273 | |
| 248 | 274 | // TODO implement @setRuntimeSafety in stage2 |
| ... | ... | @@ -270,6 +296,8 @@ fn implicitIntLitToOptional() void { |
| 270 | 296 | } |
| 271 | 297 | |
| 272 | 298 | test "return u8 coercing into ?u32 return type" { |
| 299 | if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 300 | |
| 273 | 301 | const S = struct { |
| 274 | 302 | fn doTheTest() !void { |
| 275 | 303 | try expect(foo(123).? == 123); |
| ... | ... | @@ -288,6 +316,8 @@ test "cast from ?[*]T to ??[*]T" { |
| 288 | 316 | } |
| 289 | 317 | |
| 290 | 318 | test "peer type unsigned int to signed" { |
| 319 | if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 320 | |
| 291 | 321 | var w: u31 = 5; |
| 292 | 322 | var x: u8 = 7; |
| 293 | 323 | var y: i32 = -5; |