From 31b97f73d2c49616fe1ec11bc27a8dbbc629ff2f Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 30 Apr 2024 09:02:32 -0500 Subject: [PATCH] tests: fix TextInput test --- src/main.zig | 2 ++ src/widgets/TextInput.zig | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main.zig b/src/main.zig index d0a7fbb..78ad6ce 100644 --- a/src/main.zig +++ b/src/main.zig @@ -27,5 +27,7 @@ pub fn init(alloc: std.mem.Allocator, opts: Vaxis.Options) !Vaxis { test { std.testing.refAllDecls(@This()); + std.testing.refAllDecls(widgets); _ = @import("Parser.zig"); + _ = @import("Tty.zig"); } diff --git a/src/widgets/TextInput.zig b/src/widgets/TextInput.zig index 9fee297..03421d2 100644 --- a/src/widgets/TextInput.zig +++ b/src/widgets/TextInput.zig @@ -316,12 +316,15 @@ fn deleteAtCursor(self: *TextInput) !void { } test "assertion" { + const alloc = std.testing.allocator_instance.allocator(); + const unicode = try Unicode.init(alloc); + defer unicode.deinit(); const astronaut = "👩‍🚀"; const astronaut_emoji: Key = .{ .text = astronaut, .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(); for (0..6) |_| { try input.update(.{ .key_press = astronaut_emoji }); @@ -329,8 +332,11 @@ test "assertion" { } test "sliceToCursor" { - var alloc = std.testing.allocator_instance; - var input = init(alloc.allocator()); + const alloc = std.testing.allocator_instance.allocator(); + const unicode = try Unicode.init(alloc); + defer unicode.deinit(); + var input = init(alloc, &unicode); + defer input.deinit(); try input.insertSliceAtCursor("hello, world"); input.cursor_idx = 2; var buf: [32]u8 = undefined;