builtins: Remove old incorrect comment about isSmallStr and add a test to make sure

This commit is contained in:
Brian Carroll 2022-09-02 23:18:34 +01:00
parent bfc00a4b94
commit 32b815847e
No known key found for this signature in database
GPG key ID: 5C7B2EC4101703C0

View file

@ -215,11 +215,14 @@ pub const RocStr = extern struct {
return result;
}
// NOTE: returns false for empty string!
pub fn isSmallStr(self: RocStr) bool {
return @bitCast(isize, self.str_capacity) < 0;
}
test "isSmallStr: returns true for empty string" {
try expect(isSmallStr(RocStr.empty()));
}
fn asArray(self: RocStr) [@sizeOf(RocStr)]u8 {
const as_ptr = @ptrCast([*]const u8, &self);
const slice = as_ptr[0..@sizeOf(RocStr)];