mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 11:52:19 +00:00
fix RocStr.capacity() in zig
This commit is contained in:
parent
5904934887
commit
4f965ec263
1 changed files with 21 additions and 1 deletions
|
@ -228,7 +228,11 @@ pub const RocStr = extern struct {
|
|||
}
|
||||
|
||||
pub fn capacity(self: RocStr) usize {
|
||||
return self.str_capacity ^ MASK;
|
||||
if (self.isSmallStr()) {
|
||||
return SMALL_STR_MAX_LENGTH;
|
||||
} else {
|
||||
return self.str_capacity;
|
||||
}
|
||||
}
|
||||
|
||||
// This does a small string check, but no bounds checking whatsoever!
|
||||
|
@ -2350,3 +2354,19 @@ test "ReverseUtf8View: empty" {
|
|||
try expect(false);
|
||||
}
|
||||
}
|
||||
|
||||
test "capacity: small string" {
|
||||
const data_bytes = "foobar";
|
||||
var data = RocStr.init(data_bytes, data_bytes.len);
|
||||
defer data.deinit();
|
||||
|
||||
try expectEqual(data.capacity(), SMALL_STR_MAX_LENGTH);
|
||||
}
|
||||
|
||||
test "capacity: big string" {
|
||||
const data_bytes = "a string so large that it must be heap-allocated";
|
||||
var data = RocStr.init(data_bytes, data_bytes.len);
|
||||
defer data.deinit();
|
||||
|
||||
try expectEqual(data.capacity(), data_bytes.len);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue