zig-smolstr/tests/root.zig

38 lines
1 KiB
Zig
Raw Normal View History

2025-04-07 22:23:32 +00:00
const std = @import("std");
2025-04-08 00:33:12 +02:00
const SmolStr = @import("smolstr").SmolStr;
test "inline" {
const alloc = std.testing.allocator;
const s = "abcdefghijklmnopqrstuvwxyz";
for (1..SmolStr.max_inline_len + 1) |i| {
const sub_s: []const u8 = s[0..i];
const str = try SmolStr.init(alloc, sub_s);
defer str.deinit(alloc);
try std.testing.expectEqual(i, str.inner.inl.len);
try std.testing.expectEqualStrings(s[0..i], str.inner.inl.data[0..str.inner.inl.len]);
try std.testing.expectEqual(i, str.len());
try std.testing.expectEqualStrings(s[0..i], str.str());
try std.testing.expectEqual(s[0], str.str()[0]);
}
}
test "heap" {
const alloc = std.testing.allocator;
const s = "abcdefghijklmnopqrstuvwxyz";
const str = try SmolStr.init(alloc, s);
defer str.deinit(alloc);
try std.testing.expectEqualStrings(s, str.inner.heap);
try std.testing.expectEqual(s.len, str.len());
try std.testing.expectEqualStrings(s, str.str());
}