From c7b46856bb1f4fedff30484ce8e569071980ab8c Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Fri, 10 Oct 2025 09:32:20 +0200 Subject: [PATCH] refactor: explicity publish internal helix functions for unittests only We don't want internal functions in the mode specific extention modules becoming shared code. To avoid this, mark the functions as private and publish only through a structure marked clearly as for testing only. If these functions are useful as shared code they can be moved to the editor module or else where. --- src/tui/mode/helix.zig | 20 +++++++++++++++----- test/tests_helix.zig | 10 +++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/tui/mode/helix.zig b/src/tui/mode/helix.zig index 19f05a9..ad20003 100644 --- a/src/tui/mode/helix.zig +++ b/src/tui/mode/helix.zig @@ -454,7 +454,7 @@ const cmds_ = struct { pub const paste_after_meta: Meta = .{ .description = "Paste from clipboard after selection" }; }; -pub fn move_cursor_word_left_helix(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void { +fn move_cursor_word_left_helix(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void { try Editor.move_cursor_left(root, cursor, metrics); // Consume " " @@ -479,7 +479,7 @@ pub fn move_cursor_word_left_helix(root: Buffer.Root, cursor: *Cursor, metrics: fn move_noop(_: Buffer.Root, _: *Cursor, _: Buffer.Metrics) error{Stop}!void {} -pub fn move_cursor_word_right_end_helix(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void { +fn move_cursor_word_right_end_helix(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void { try Editor.move_cursor_right(root, cursor, metrics); Editor.move_cursor_right_until(root, cursor, Editor.is_word_boundary_right_vim, metrics); try cursor.move_right(root, metrics); @@ -535,7 +535,7 @@ fn is_long_word_boundary_left(root: Buffer.Root, cursor: *const Cursor, metrics: return curr_is_non_word != next_is_non_word; } -pub fn move_cursor_long_word_left(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void { +fn move_cursor_long_word_left(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void { try Editor.move_cursor_left(root, cursor, metrics); // Consume " " @@ -571,7 +571,7 @@ fn is_word_boundary_right(root: Buffer.Root, cursor: *const Cursor, metrics: Buf return curr_is_non_word != next_is_non_word; } -pub fn move_cursor_long_word_right(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void { +fn move_cursor_long_word_right(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void { try cursor.move_right(root, metrics); Editor.move_cursor_right_until(root, cursor, is_long_word_boundary_left, metrics); } @@ -589,8 +589,18 @@ fn is_long_word_boundary_right(root: Buffer.Root, cursor: *const Cursor, metrics return curr_is_non_word != next_is_non_word; } -pub fn move_cursor_long_word_right_end(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void { +fn move_cursor_long_word_right_end(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void { // try Editor.move_cursor_right(root, cursor, metrics); Editor.move_cursor_right_until(root, cursor, is_long_word_boundary_right, metrics); try cursor.move_right(root, metrics); } + +const private = @This(); +// exports for unittests +pub const test_internal = struct { + pub const move_cursor_long_word_right = private.move_cursor_long_word_right; + pub const move_cursor_long_word_left = private.move_cursor_long_word_left; + pub const move_cursor_long_word_right_end = private.move_cursor_long_word_right_end; + pub const move_cursor_word_left_helix = private.move_cursor_word_left_helix; + pub const move_cursor_word_right_end_helix = private.move_cursor_word_right_end_helix; +}; \ No newline at end of file diff --git a/test/tests_helix.zig b/test/tests_helix.zig index ca09a08..f94e63a 100644 --- a/test/tests_helix.zig +++ b/test/tests_helix.zig @@ -12,22 +12,22 @@ fn apply_movements(movements: []const u8, root: Buffer.Root, cursor: *Cursor, th for (movements) |move| { switch (move) { 'W' => { - try helix.move_cursor_long_word_right(root, cursor, the_metrics); + try helix.test_internal.move_cursor_long_word_right(root, cursor, the_metrics); }, 'B' => { - try helix.move_cursor_long_word_left(root, cursor, the_metrics); + try helix.test_internal.move_cursor_long_word_left(root, cursor, the_metrics); }, 'E' => { - try helix.move_cursor_long_word_right_end(root, cursor, the_metrics); + try helix.test_internal.move_cursor_long_word_right_end(root, cursor, the_metrics); }, 'w' => { try Editor.move_cursor_word_right_vim(root, cursor, the_metrics); }, 'b' => { - try helix.move_cursor_word_left_helix(root, cursor, the_metrics); + try helix.test_internal.move_cursor_word_left_helix(root, cursor, the_metrics); }, 'e' => { - try helix.move_cursor_word_right_end_helix(root, cursor, the_metrics); + try helix.test_internal.move_cursor_word_right_end_helix(root, cursor, the_metrics); }, else => {}, }