From fe671e7ba9138250e3435e40ac36460d89c0f67b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Thu, 25 Jun 2026 13:32:40 +0200 Subject: [PATCH] behavior: delete tests containing illegal behavior They're also of questionable value anyway. --- test/behavior/cast_int.zig | 116 ------------------------------------- 1 file changed, 116 deletions(-) diff --git a/test/behavior/cast_int.zig b/test/behavior/cast_int.zig index 8564d2197727971c04badcb728847dd52bb5e9e2..34adedf7267030379ee573cb519ce6dbe29c95e3 100644 --- a/test/behavior/cast_int.zig +++ b/test/behavior/cast_int.zig @@ -213,119 +213,3 @@ test "@intCast > 128 bits" { try testIntCast(u64, maxInt(u64), i255, maxInt(u64)); try testIntCast(u128, maxInt(u128), i255, maxInt(u128)); } - -const Piece = packed struct { - color: Color, - type: Type, - - const Type = enum(u3) { KING, QUEEN, BISHOP, KNIGHT, ROOK, PAWN }; - const Color = enum(u1) { WHITE, BLACK }; - - fn charToPiece(c: u8) !@This() { - return .{ - .type = try charToPieceType(c), - .color = if (std.ascii.isUpper(c)) Color.WHITE else Color.BLACK, - }; - } - - fn charToPieceType(c: u8) !Type { - return switch (std.ascii.toLower(c)) { - 'p' => .PAWN, - 'k' => .KING, - 'q' => .QUEEN, - 'b' => .BISHOP, - 'n' => .KNIGHT, - 'r' => .ROOK, - else => error.UnexpectedCharError, - }; - } -}; - -// Originally reported at https://github.com/ziglang/zig/issues/14200 -test "load non byte-sized optional value" { - if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; - if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; - if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; // TODO - - // note: this bug is triggered by the == operator, expectEqual will hide it - const opt: ?Piece = try Piece.charToPiece('p'); - try expect(opt.?.type == .PAWN); - try expect(opt.?.color == .BLACK); - - var p: Piece = undefined; - @as(*u8, @ptrCast(&p)).* = 0b11111011; - try expect(p.type == .PAWN); - try expect(p.color == .BLACK); -} - -test "load non byte-sized value in struct" { - if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; - if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; - if (builtin.cpu.arch.endian() != .little) return error.SkipZigTest; // packed struct TODO - if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; // TODO - - // note: this bug is triggered by the == operator, expectEqual will hide it - // using ptrCast not to depend on unitialised memory state - - var struct0: struct { - p: Piece, - int: u8, - } = undefined; - @as(*u8, @ptrCast(&struct0.p)).* = 0b11111011; - try expect(struct0.p.type == .PAWN); - try expect(struct0.p.color == .BLACK); - - var struct1: packed struct { - p0: Piece, - p1: Piece, - pad: u1, - p2: Piece, - } = undefined; - @as(*u8, @ptrCast(&struct1.p0)).* = 0b11111011; - struct1.p1 = try Piece.charToPiece('p'); - struct1.p2 = try Piece.charToPiece('p'); - try expect(struct1.p0.type == .PAWN); - try expect(struct1.p0.color == .BLACK); - try expect(struct1.p1.type == .PAWN); - try expect(struct1.p1.color == .BLACK); - try expect(struct1.p2.type == .PAWN); - try expect(struct1.p2.color == .BLACK); -} - -test "load non byte-sized value in union" { - if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; - if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; - if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; - if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; - if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; - - // note: this bug is triggered by the == operator, expectEqual will hide it - // using ptrCast not to depend on unitialised memory state - - var union0: packed union { - p: packed struct(u8) { - a: Piece, - b: u4, - }, - int: u8, - } = .{ .int = 0 }; - union0.int = 0b11111011; - try expect(union0.p.a.type == .PAWN); - try expect(union0.p.a.color == .BLACK); - - var union1: union { - p: packed struct(u8) { - a: Piece, - b: u4, - }, - int: u8, - } = .{ .p = .{ .a = .{ .color = .WHITE, .type = .KING }, .b = 0 } }; - @as(*u8, @ptrCast(&union1.p.a)).* = 0b11111011; - try expect(union1.p.a.type == .PAWN); - try expect(union1.p.a.color == .BLACK); - - var pieces: [3]Piece = undefined; - @as(*u8, @ptrCast(&pieces[1])).* = 0b11111011; - try expect(pieces[1].type == .PAWN); - try expect(pieces[1].color == .BLACK); -} -- 2.54.0