const std = @import("std"); const expect = std.testing.expect; const expectEqual = std.testing.expectEqual; const expectEqualSlices = std.testing.expectEqualSlices; const maxInt = std.math.maxInt; const minInt = std.math.minInt; const mem = std.mem; test "assignment operators" { var i: u32 = 0; i += 5; try expect(i == 5); i -= 2; try expect(i == 3); i *= 20; try expect(i == 60); i /= 3; try expect(i == 20); i %= 11; try expect(i == 9); i <<= 1; try expect(i == 18); i >>= 2; try expect(i == 4); i = 6; i &= 5; try expect(i == 4); i ^= 6; try expect(i == 2); i = 6; i |= 3; try expect(i == 7); } test "three expr in a row" { try testThreeExprInARow(false, true); comptime try testThreeExprInARow(false, true); } fn testThreeExprInARow(f: bool, t: bool) !void { try assertFalse(f or f or f); try assertFalse(t and t and f); try assertFalse(1 | 2 | 4 != 7); try assertFalse(3 ^ 6 ^ 8 != 13); try assertFalse(7 & 14 & 28 != 4); try assertFalse(9 << 1 << 2 != 9 << 3); try assertFalse(90 >> 1 >> 2 != 90 >> 3); try assertFalse(100 - 1 + 1000 != 1099); try assertFalse(5 * 4 / 2 % 3 != 1); try assertFalse(@as(i32, @as(i32, 5)) != 5); try assertFalse(!!false); try assertFalse(@as(i32, 7) != --(@as(i32, 7))); } fn assertFalse(b: bool) !void { try expect(!b); }