test: valid string slices for ghostty_string_s
parent
dc03a47558
commit
d79441edd1
|
|
@ -155,3 +155,43 @@ pub export fn ghostty_translate(msgid: [*:0]const u8) [*:0]const u8 {
|
|||
pub export fn ghostty_string_free(str: String) void {
|
||||
str.deinit();
|
||||
}
|
||||
|
||||
test "ghostty_string_s empty string" {
|
||||
const testing = std.testing;
|
||||
const empty_string = String.empty;
|
||||
defer empty_string.deinit();
|
||||
|
||||
try testing.expect(empty_string.len == 0);
|
||||
try testing.expect(empty_string.sentinel == false);
|
||||
}
|
||||
|
||||
test "ghostty_string_s c string" {
|
||||
const testing = std.testing;
|
||||
state.alloc = testing.allocator;
|
||||
|
||||
const slice: [:0]const u8 = "hello";
|
||||
const allocated_slice = try testing.allocator.dupeZ(u8, slice);
|
||||
const c_null_string = String.fromSlice(allocated_slice);
|
||||
defer c_null_string.deinit();
|
||||
|
||||
try testing.expect(allocated_slice[5] == 0);
|
||||
try testing.expect(@TypeOf(slice) == [:0]const u8);
|
||||
try testing.expect(@TypeOf(allocated_slice) == [:0]u8);
|
||||
try testing.expect(c_null_string.len == 5);
|
||||
try testing.expect(c_null_string.sentinel == true);
|
||||
}
|
||||
|
||||
test "ghostty_string_s zig string" {
|
||||
const testing = std.testing;
|
||||
state.alloc = testing.allocator;
|
||||
|
||||
const slice: []const u8 = "hello";
|
||||
const allocated_slice = try testing.allocator.dupe(u8, slice);
|
||||
const zig_string = String.fromSlice(allocated_slice);
|
||||
defer zig_string.deinit();
|
||||
|
||||
try testing.expect(@TypeOf(slice) == []const u8);
|
||||
try testing.expect(@TypeOf(allocated_slice) == []u8);
|
||||
try testing.expect(zig_string.len == 5);
|
||||
try testing.expect(zig_string.sentinel == false);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue