zig/lib/compiler_rt/ucmpdi2_test.zig
Andrew Kelley ec95e00e28 flatten lib/std/special and improve "pkg inside another" logic
stage2: change logic for detecting whether the main package is inside
the std package. Previously it relied on realpath() which is not portable.
This uses resolve() which is how imports already work.

 * stage2: fix cleanup bug when creating Module
 * flatten lib/std/special/* to lib/*
   - this was motivated by making main_pkg_is_inside_std false for
     compiler_rt & friends.
 * rename "mini libc" to "universal libc"
2022-05-06 22:41:00 -07:00

50 lines
2.1 KiB
Zig

const cmp = @import("cmp.zig");
const testing = @import("std").testing;
fn test__ucmpdi2(a: u64, b: u64, expected: i32) !void {
var result = cmp.__ucmpdi2(a, b);
try testing.expectEqual(expected, result);
}
test "ucmpdi2" {
// minInt == 0
// maxInt == 18446744073709551615
// minInt/2 == 0
// maxInt/2 == 9223372036854775807
// 1. equality minInt, minInt/2, 0, maxInt/2, maxInt
try test__ucmpdi2(0, 0, 1);
try test__ucmpdi2(1, 1, 1);
try test__ucmpdi2(9223372036854775807, 9223372036854775807, 1);
try test__ucmpdi2(18446744073709551614, 18446744073709551614, 1);
try test__ucmpdi2(18446744073709551615, 18446744073709551615, 1);
// 2. cmp minInt, {minInt + 1, maxInt/2, maxInt-1, maxInt}
try test__ucmpdi2(0, 1, 0);
try test__ucmpdi2(0, 9223372036854775807, 0);
try test__ucmpdi2(0, 18446744073709551614, 0);
try test__ucmpdi2(0, 18446744073709551615, 0);
// 3. cmp minInt+1, {minInt, maxInt/2, maxInt-1, maxInt}
try test__ucmpdi2(1, 0, 2);
try test__ucmpdi2(1, 9223372036854775807, 0);
try test__ucmpdi2(1, 18446744073709551614, 0);
try test__ucmpdi2(1, 18446744073709551615, 0);
// 4. cmp minInt/2, {}
// 5. cmp -1, {}
// 6. cmp 0, {}
// 7. cmp 1, {}
// 8. cmp maxInt/2, {minInt, minInt+1, maxInt-1, maxInt}
try test__ucmpdi2(9223372036854775807, 0, 2);
try test__ucmpdi2(9223372036854775807, 1, 2);
try test__ucmpdi2(9223372036854775807, 18446744073709551614, 0);
try test__ucmpdi2(9223372036854775807, 18446744073709551615, 0);
// 9. cmp maxInt-1, {minInt, minInt + 1, maxInt/2, maxInt}
try test__ucmpdi2(18446744073709551614, 0, 2);
try test__ucmpdi2(18446744073709551614, 1, 2);
try test__ucmpdi2(18446744073709551614, 9223372036854775807, 2);
try test__ucmpdi2(18446744073709551614, 18446744073709551615, 0);
// 10.cmp maxInt, {minInt, 1, maxInt/2, maxInt-1}
try test__ucmpdi2(18446744073709551615, 0, 2);
try test__ucmpdi2(18446744073709551615, 1, 2);
try test__ucmpdi2(18446744073709551615, 9223372036854775807, 2);
try test__ucmpdi2(18446744073709551615, 18446744073709551614, 2);
}