generated from mg/zig-template
38 lines
1 KiB
Zig
38 lines
1 KiB
Zig
const std = @import("std");
|
|
|
|
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());
|
|
}
|