mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
7ea8f842bc
Before: * test-zigc: run libzigc unit tests (part of test-modules) * test-libc: run libc-test cases Now: * test-libc: run libc API unit tests (part of test-modules) * test-libc-nsz: run libc-test cases libc API unit tests (previously referred to as libzigc unit tests) now run for all supported targets, even those we don't provide libzigc for. The idea is that this will help us catch bad assumptions in the unit tests, as well as bugs in other libcs. I considered this setup: * test-c: run libc API unit tests (part of test-modules) * test-libc-nsz: run libc-test cases * test-libc: both of the above However, I do not like it because it gives a false sense of security; the full module and C ABI test suites are still liable to catch libzigc bugs that test-c and test-libc-nsz might not. So contributors should just run the test steps outlined in https://codeberg.org/ziglang/zig/issues/30978. Co-authored-by: rpkak <rpkak@noreply.codeberg.org>
58 lines
1.9 KiB
Zig
58 lines
1.9 KiB
Zig
const builtin = @import("builtin");
|
|
const std = @import("std");
|
|
|
|
const c = std.c;
|
|
const mem = std.mem;
|
|
const testing = std.testing;
|
|
|
|
test "bzero" {
|
|
var array: [10]u8 = [_]u8{ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
|
|
var a = mem.zeroes([array.len]u8);
|
|
a[9] = '0';
|
|
c.bzero(&array[0], 9);
|
|
try testing.expect(mem.eql(u8, &array, &a));
|
|
}
|
|
|
|
fn testFfs(comptime T: type) !void {
|
|
const ffs = switch (T) {
|
|
c_int => c.ffs,
|
|
c_long => c.ffsl,
|
|
c_longlong => c.ffsll,
|
|
else => unreachable,
|
|
};
|
|
|
|
try testing.expectEqual(0, ffs(0));
|
|
|
|
for (0..@bitSizeOf(T)) |i| {
|
|
const bit = @as(T, 1) << @intCast(i);
|
|
|
|
try testing.expectEqual(@as(T, @intCast(i + 1)), ffs(bit));
|
|
}
|
|
}
|
|
|
|
test "ffs" {
|
|
try testFfs(c_int);
|
|
try testFfs(c_long);
|
|
try testFfs(c_longlong);
|
|
}
|
|
|
|
test "strcasecmp" {
|
|
try testing.expect(c.strcasecmp(@ptrCast("a"), @ptrCast("b")) < 0);
|
|
try testing.expect(c.strcasecmp(@ptrCast("b"), @ptrCast("a")) > 0);
|
|
try testing.expect(c.strcasecmp(@ptrCast("A"), @ptrCast("b")) < 0);
|
|
try testing.expect(c.strcasecmp(@ptrCast("b"), @ptrCast("A")) > 0);
|
|
try testing.expect(c.strcasecmp(@ptrCast("A"), @ptrCast("A")) == 0);
|
|
try testing.expect(c.strcasecmp(@ptrCast("B"), @ptrCast("b")) == 0);
|
|
try testing.expect(c.strcasecmp(@ptrCast("bb"), @ptrCast("AA")) > 0);
|
|
}
|
|
|
|
test "strncasecmp" {
|
|
try testing.expect(c.strncasecmp(@ptrCast("a"), @ptrCast("b"), 1) < 0);
|
|
try testing.expect(c.strncasecmp(@ptrCast("b"), @ptrCast("a"), 1) > 0);
|
|
try testing.expect(c.strncasecmp(@ptrCast("A"), @ptrCast("b"), 1) < 0);
|
|
try testing.expect(c.strncasecmp(@ptrCast("b"), @ptrCast("A"), 1) > 0);
|
|
try testing.expect(c.strncasecmp(@ptrCast("A"), @ptrCast("A"), 1) == 0);
|
|
try testing.expect(c.strncasecmp(@ptrCast("B"), @ptrCast("b"), 1) == 0);
|
|
try testing.expect(c.strncasecmp(@ptrCast("bb"), @ptrCast("AA"), 2) > 0);
|
|
}
|