summaryrefslogtreecommitdiff
path: root/test/hxdiff.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-09 00:52:52 -0300
committerGabriel Schneider <[email protected]>2026-11-09 01:28:28 -0300
commit5157579ff7f9ae0cfc3c7629e953da05bce340fc (patch)
tree02147789efdcea998981efcfe05d4bcb3e9bb7b0 /test/hxdiff.zig
parent4c4b9bf54d77dbc0f9f4e2619746908e501c6001 (diff)
downloadpardes-5157579ff7f9ae0cfc3c7629e953da05bce340fc.tar.gz
pardes-5157579ff7f9ae0cfc3c7629e953da05bce340fc.zip
tests: at the end of their files: every top-level test block of the 46 files that had one mid-file (the locality analysis's 45 and test/hxdiff.zig; gui.zig, macos.zig, look, host_io, 9p_io, terminal, tui, mouse, fs, replica, layout among them, 11,429 test lines), with the functions only tests call, moved after the file's code in their order, a mechanical move (.scratch/suites/tests_to_end.py), zig fmt'd; the unit suites pass as before (tui 1486/1487, gui 1536/1537, core 956/956 on both), macos.zig only parse-checked here
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/hxdiff.zig')
-rw-r--r--test/hxdiff.zig178
1 files changed, 89 insertions, 89 deletions
diff --git a/test/hxdiff.zig b/test/hxdiff.zig
index 90d486eb..5c1bc04e 100644
--- a/test/hxdiff.zig
+++ b/test/hxdiff.zig
@@ -262,60 +262,6 @@ fn validatePosition(text: []const u8, position: Pos) !void {
return error.InvalidPosition;
}
-test "differential result positions include byte-length gaps and the empty EOF row" {
- const cases = [_]struct { text: []const u8, position: Pos, valid: bool }{
- .{ .text = "", .position = .{ .row = 0, .col = 0 }, .valid = true },
- .{ .text = "", .position = .{ .row = 0, .col = 1 }, .valid = false },
- .{ .text = "abc", .position = .{ .row = 0, .col = 3 }, .valid = true },
- .{ .text = "abc", .position = .{ .row = 1, .col = 0 }, .valid = false },
- .{ .text = "abc\n", .position = .{ .row = 0, .col = 3 }, .valid = true },
- .{ .text = "abc\n", .position = .{ .row = 1, .col = 0 }, .valid = true },
- .{ .text = "abc\n", .position = .{ .row = 1, .col = 1 }, .valid = false },
- .{ .text = "abc\n", .position = .{ .row = 2, .col = 0 }, .valid = false },
- .{ .text = "λ界😀\n", .position = .{ .row = 0, .col = 9 }, .valid = true },
- .{ .text = "λ界😀\n", .position = .{ .row = 0, .col = 10 }, .valid = false },
- .{ .text = "abc\n", .position = .{ .row = -1, .col = 0 }, .valid = false },
- .{ .text = "abc\n", .position = .{ .row = 0, .col = -1 }, .valid = false },
- };
- for (cases) |case| {
- const result: Result = .{
- .name = "position",
- .text = case.text,
- .mode = "normal",
- .cursor = case.position,
- .anchor = case.position,
- };
- if (case.valid) try validateResult(result) else try std.testing.expectError(error.InvalidPosition, validateResult(result));
- }
-}
-
-test "differential result positions validate secondary selections and anchors" {
- const start: Pos = .{ .row = 0, .col = 0 };
- const end: Pos = .{ .row = 1, .col = 0 };
- var selections = [_]Sel{
- .{ .cursor = start, .anchor = start },
- .{ .cursor = end, .anchor = start },
- };
- var result: Result = .{
- .name = "multiple-positions",
- .text = "λ界😀\n",
- .mode = "normal",
- .cursor = start,
- .anchor = start,
- .sels = &selections,
- .primary = 0,
- };
- try validateResult(result);
- selections[1].cursor.col = 1;
- try std.testing.expectError(error.InvalidPosition, validateResult(result));
- selections[1].cursor = end;
- selections[1].anchor.row = -1;
- try std.testing.expectError(error.InvalidPosition, validateResult(result));
- selections[1].anchor = start;
- result.anchor.col = 10;
- try std.testing.expectError(error.InvalidPosition, validateResult(result));
-}
-
fn diffResult(allocator: std.mem.Allocator, want: Result, got: Result, wl: []const u8, gl: []const u8) ![]u8 {
var out: std.Io.Writer.Allocating = .init(allocator);
defer out.deinit();
@@ -341,41 +287,6 @@ fn diffResult(allocator: std.mem.Allocator, want: Result, got: Result, wl: []con
return out.toOwnedSlice();
}
-test "differential reports compare values and report every changed field" {
- const allocator = std.testing.allocator;
- const want: Result = .{
- .name = "case",
- .text = "one\n",
- .mode = "normal",
- .cursor = .{ .row = 0, .col = 0 },
- .anchor = .{ .row = 0, .col = 1 },
- };
- var got = want;
- got.text = try allocator.dupe(u8, want.text);
- defer allocator.free(got.text);
- const same = try diffResult(allocator, want, got, "want", "got");
- defer allocator.free(same);
- try std.testing.expectEqualStrings("", same);
-
- const changed: Result = .{
- .name = "case",
- .text = "two\n",
- .mode = "insert",
- .cursor = .{ .row = 1, .col = 2 },
- .anchor = .{ .row = 1, .col = 0 },
- .sels = &.{.{ .cursor = .{ .row = 1, .col = 2 }, .anchor = .{ .row = 1, .col = 0 } }},
- };
- const Check = struct {
- fn run(a: std.mem.Allocator, before: Result, after: Result) !void {
- const difference = try diffResult(a, before, after, "want", "got");
- defer a.free(difference);
- for ([_][]const u8{ "text:", "mode:", "cursor:", "anchor:", "sels:" }) |field|
- try std.testing.expect(std.mem.indexOf(u8, difference, field) != null);
- }
- };
- try std.testing.checkAllAllocationFailures(allocator, Check.run, .{ want, changed });
-}
-
/// The text rows of hx-harness's one view (80x24 less its two lines).
const helix_view_rows = 22;
@@ -588,6 +499,95 @@ fn fatal(comptime fmt: []const u8, args: anytype) noreturn {
std.process.exit(1);
}
+test "differential result positions include byte-length gaps and the empty EOF row" {
+ const cases = [_]struct { text: []const u8, position: Pos, valid: bool }{
+ .{ .text = "", .position = .{ .row = 0, .col = 0 }, .valid = true },
+ .{ .text = "", .position = .{ .row = 0, .col = 1 }, .valid = false },
+ .{ .text = "abc", .position = .{ .row = 0, .col = 3 }, .valid = true },
+ .{ .text = "abc", .position = .{ .row = 1, .col = 0 }, .valid = false },
+ .{ .text = "abc\n", .position = .{ .row = 0, .col = 3 }, .valid = true },
+ .{ .text = "abc\n", .position = .{ .row = 1, .col = 0 }, .valid = true },
+ .{ .text = "abc\n", .position = .{ .row = 1, .col = 1 }, .valid = false },
+ .{ .text = "abc\n", .position = .{ .row = 2, .col = 0 }, .valid = false },
+ .{ .text = "λ界😀\n", .position = .{ .row = 0, .col = 9 }, .valid = true },
+ .{ .text = "λ界😀\n", .position = .{ .row = 0, .col = 10 }, .valid = false },
+ .{ .text = "abc\n", .position = .{ .row = -1, .col = 0 }, .valid = false },
+ .{ .text = "abc\n", .position = .{ .row = 0, .col = -1 }, .valid = false },
+ };
+ for (cases) |case| {
+ const result: Result = .{
+ .name = "position",
+ .text = case.text,
+ .mode = "normal",
+ .cursor = case.position,
+ .anchor = case.position,
+ };
+ if (case.valid) try validateResult(result) else try std.testing.expectError(error.InvalidPosition, validateResult(result));
+ }
+}
+
+test "differential result positions validate secondary selections and anchors" {
+ const start: Pos = .{ .row = 0, .col = 0 };
+ const end: Pos = .{ .row = 1, .col = 0 };
+ var selections = [_]Sel{
+ .{ .cursor = start, .anchor = start },
+ .{ .cursor = end, .anchor = start },
+ };
+ var result: Result = .{
+ .name = "multiple-positions",
+ .text = "λ界😀\n",
+ .mode = "normal",
+ .cursor = start,
+ .anchor = start,
+ .sels = &selections,
+ .primary = 0,
+ };
+ try validateResult(result);
+ selections[1].cursor.col = 1;
+ try std.testing.expectError(error.InvalidPosition, validateResult(result));
+ selections[1].cursor = end;
+ selections[1].anchor.row = -1;
+ try std.testing.expectError(error.InvalidPosition, validateResult(result));
+ selections[1].anchor = start;
+ result.anchor.col = 10;
+ try std.testing.expectError(error.InvalidPosition, validateResult(result));
+}
+
+test "differential reports compare values and report every changed field" {
+ const allocator = std.testing.allocator;
+ const want: Result = .{
+ .name = "case",
+ .text = "one\n",
+ .mode = "normal",
+ .cursor = .{ .row = 0, .col = 0 },
+ .anchor = .{ .row = 0, .col = 1 },
+ };
+ var got = want;
+ got.text = try allocator.dupe(u8, want.text);
+ defer allocator.free(got.text);
+ const same = try diffResult(allocator, want, got, "want", "got");
+ defer allocator.free(same);
+ try std.testing.expectEqualStrings("", same);
+
+ const changed: Result = .{
+ .name = "case",
+ .text = "two\n",
+ .mode = "insert",
+ .cursor = .{ .row = 1, .col = 2 },
+ .anchor = .{ .row = 1, .col = 0 },
+ .sels = &.{.{ .cursor = .{ .row = 1, .col = 2 }, .anchor = .{ .row = 1, .col = 0 } }},
+ };
+ const Check = struct {
+ fn run(a: std.mem.Allocator, before: Result, after: Result) !void {
+ const difference = try diffResult(a, before, after, "want", "got");
+ defer a.free(difference);
+ for ([_][]const u8{ "text:", "mode:", "cursor:", "anchor:", "sels:" }) |field|
+ try std.testing.expect(std.mem.indexOf(u8, difference, field) != null);
+ }
+ };
+ try std.testing.checkAllAllocationFailures(allocator, Check.run, .{ want, changed });
+}
+
test "differential cases deliver each Unicode scalar as one key event" {
var arena_state: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena_state.deinit();