tests: fix TextInput test

This commit is contained in:
Tim Culverhouse 2024-04-30 09:02:32 -05:00
parent 5ad01f6a3a
commit 31b97f73d2
2 changed files with 11 additions and 3 deletions

View file

@ -27,5 +27,7 @@ pub fn init(alloc: std.mem.Allocator, opts: Vaxis.Options) !Vaxis {
test { test {
std.testing.refAllDecls(@This()); std.testing.refAllDecls(@This());
std.testing.refAllDecls(widgets);
_ = @import("Parser.zig"); _ = @import("Parser.zig");
_ = @import("Tty.zig");
} }

View file

@ -316,12 +316,15 @@ fn deleteAtCursor(self: *TextInput) !void {
} }
test "assertion" { test "assertion" {
const alloc = std.testing.allocator_instance.allocator();
const unicode = try Unicode.init(alloc);
defer unicode.deinit();
const astronaut = "👩‍🚀"; const astronaut = "👩‍🚀";
const astronaut_emoji: Key = .{ const astronaut_emoji: Key = .{
.text = astronaut, .text = astronaut,
.codepoint = try std.unicode.utf8Decode(astronaut[0..4]), .codepoint = try std.unicode.utf8Decode(astronaut[0..4]),
}; };
var input = TextInput.init(std.testing.allocator); var input = TextInput.init(std.testing.allocator, &unicode);
defer input.deinit(); defer input.deinit();
for (0..6) |_| { for (0..6) |_| {
try input.update(.{ .key_press = astronaut_emoji }); try input.update(.{ .key_press = astronaut_emoji });
@ -329,8 +332,11 @@ test "assertion" {
} }
test "sliceToCursor" { test "sliceToCursor" {
var alloc = std.testing.allocator_instance; const alloc = std.testing.allocator_instance.allocator();
var input = init(alloc.allocator()); const unicode = try Unicode.init(alloc);
defer unicode.deinit();
var input = init(alloc, &unicode);
defer input.deinit();
try input.insertSliceAtCursor("hello, world"); try input.insertSliceAtCursor("hello, world");
input.cursor_idx = 2; input.cursor_idx = 2;
var buf: [32]u8 = undefined; var buf: [32]u8 = undefined;