diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-12-16 11:39:13 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-12-16 11:39:13 -0500 |
| commit | 496f271d179fac0ce05dc68eb3fddad12384fd68 (patch) | |
| tree | 615f80e03f2bfdf021cc387956b0f38e2a5ba32f /test | |
| parent | fe0e8c87b762aba6eb5ff1fad8ad7d37404476f1 (diff) | |
| parent | 1cad0acc7e4450d2f114ea87da2fd88b81694332 (diff) | |
| download | zig-496f271d179fac0ce05dc68eb3fddad12384fd68.tar.gz zig-496f271d179fac0ce05dc68eb3fddad12384fd68.zip | |
Merge branch 'shawnl-lessThan'
* always allow integer comparison operations no matter the
bit width, signedness, or comptime-ness of operands.
closes #2133
* implement comparisons for vectors, which returns vector of
bools.
closes #3001
Diffstat (limited to 'test')
| -rw-r--r-- | test/compile_errors.zig | 58 | ||||
| -rw-r--r-- | test/stage1/behavior/math.zig | 18 |
2 files changed, 43 insertions, 33 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig index d48aaa1125..c826d45cea 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -4174,58 +4174,50 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", }); - cases.add("equal on undefined value", + cases.add("comparison operators with undefined value", + \\// operator == \\comptime { \\ var a: i64 = undefined; - \\ _ = a == a; + \\ var x: i32 = 0; + \\ if (a == a) x += 1; \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - cases.add("not equal on undefined value", + \\// operator != \\comptime { \\ var a: i64 = undefined; - \\ _ = a != a; + \\ var x: i32 = 0; + \\ if (a != a) x += 1; \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - cases.add("greater than on undefined value", + \\// operator > \\comptime { \\ var a: i64 = undefined; - \\ _ = a > a; + \\ var x: i32 = 0; + \\ if (a > a) x += 1; \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - cases.add("greater than equal on undefined value", + \\// operator < \\comptime { \\ var a: i64 = undefined; - \\ _ = a >= a; + \\ var x: i32 = 0; + \\ if (a < a) x += 1; \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - cases.add("less than on undefined value", + \\// operator >= \\comptime { \\ var a: i64 = undefined; - \\ _ = a < a; + \\ var x: i32 = 0; + \\ if (a >= a) x += 1; \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - cases.add("less than equal on undefined value", + \\// operator <= \\comptime { \\ var a: i64 = undefined; - \\ _ = a <= a; + \\ var x: i32 = 0; + \\ if (a <= a) x += 1; \\} , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", + "tmp.zig:5:11: error: use of undefined value here causes undefined behavior", + "tmp.zig:11:11: error: use of undefined value here causes undefined behavior", + "tmp.zig:17:11: error: use of undefined value here causes undefined behavior", + "tmp.zig:23:11: error: use of undefined value here causes undefined behavior", + "tmp.zig:29:11: error: use of undefined value here causes undefined behavior", + "tmp.zig:35:11: error: use of undefined value here causes undefined behavior", }); cases.add("and on undefined value", diff --git a/test/stage1/behavior/math.zig b/test/stage1/behavior/math.zig index 751275aeb6..3a73e776eb 100644 --- a/test/stage1/behavior/math.zig +++ b/test/stage1/behavior/math.zig @@ -4,6 +4,7 @@ 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 "division" { if (@import("builtin").arch == .riscv64) { @@ -653,3 +654,20 @@ test "128-bit multiplication" { var c = a * b; expect(c == 6); } + +test "vector comparison" { + const S = struct { + fn doTheTest() void { + var a: @Vector(6, i32) = [_]i32{1, 3, -1, 5, 7, 9}; + var b: @Vector(6, i32) = [_]i32{-1, 3, 0, 6, 10, -10}; + expect(mem.eql(bool, &@as([6]bool, a < b), &[_]bool{false, false, true, true, true, false})); + expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{false, true, true, true, true, false})); + expect(mem.eql(bool, &@as([6]bool, a == b), &[_]bool{false, true, false, false, false, false})); + expect(mem.eql(bool, &@as([6]bool, a != b), &[_]bool{true, false, true, true, true, true})); + expect(mem.eql(bool, &@as([6]bool, a > b), &[_]bool{true, false, false, false, false, true})); + expect(mem.eql(bool, &@as([6]bool, a >= b), &[_]bool{true, true, false, false, false, true})); + } + }; + S.doTheTest(); + comptime S.doTheTest(); +} |
