generated from mg/zig-template
added SmolStr
This commit is contained in:
parent
650a824b16
commit
bdac05d5ac
6 changed files with 132 additions and 50 deletions
|
|
@ -1 +1,38 @@
|
|||
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());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue