summaryrefslogtreecommitdiff
path: root/src/sam_edit.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 /src/sam_edit.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 'src/sam_edit.zig')
-rw-r--r--src/sam_edit.zig122
1 files changed, 61 insertions, 61 deletions
diff --git a/src/sam_edit.zig b/src/sam_edit.zig
index 3886f9eb..173a559b 100644
--- a/src/sam_edit.zig
+++ b/src/sam_edit.zig
@@ -1075,6 +1075,67 @@ pub fn moveDot(dot: Range, ops: []const Op) Range {
return .{ .q0 = q0, .q1 = q1 };
}
+/// Three files and a +Errors, the way the editor hands them over, and a
+/// world whose disk holds /src/new.c and /src/data.
+const Fixture = struct {
+ arena_state: std.heap.ArenaAllocator,
+ why: Why = .{},
+
+ const files = [_]File{
+ .{ .name = "/src/a.c", .text = "int foo;\nint bar;\n", .id = 0 },
+ .{ .name = "/src/b.h", .text = "foo bar foo\n", .id = 1, .dirty = true },
+ .{ .name = "/src/c.c", .text = "bar\n", .id = 2 },
+ .{ .name = "/src/+Errors", .text = "foo\n", .id = 3, .scratch = true },
+ };
+
+ var opened: usize = 0;
+
+ fn check(_: *anyopaque, path: []const u8, why: *Why) bool {
+ if (std.mem.eql(u8, path, "/src/new.c")) return true;
+ why.len = if (std.fmt.bufPrint(&why.buf, "B: cannot open {s}", .{path})) |said| said.len else |_| 0;
+ return false;
+ }
+
+ /// The edited file, b.h, is asked about: refused.
+ fn refuseGet(_: *anyopaque, id: usize, why: *Why) bool {
+ if (id != 1) return false;
+ why.len = (std.fmt.bufPrint(&why.buf, "/src/b.h: Modified (e again to discard)", .{}) catch unreachable).len;
+ return true;
+ }
+
+ fn open(_: *anyopaque, path: []const u8, why: *Why) ?File {
+ opened += 1;
+ if (std.mem.eql(u8, path, "/src/new.c")) return .{ .name = "/src/new.c", .text = "new foo\n", .id = 9 };
+ why.len = if (std.fmt.bufPrint(&why.buf, "B: cannot open {s}", .{path})) |said| said.len else |_| 0;
+ return null;
+ }
+
+ fn read(_: *anyopaque, arena: std.mem.Allocator, path: []const u8, why: *Why) ?[]const u8 {
+ if (std.mem.eql(u8, path, "/src/data")) return arena.dupe(u8, "DATA\n") catch null;
+ why.len = if (std.fmt.bufPrint(&why.buf, "can't open {s}: file does not exist", .{path})) |said| said.len else |_| 0;
+ return null;
+ }
+
+ fn init() Fixture {
+ return .{ .arena_state = .init(std.testing.allocator) };
+ }
+
+ fn deinit(fx: *Fixture) void {
+ fx.arena_state.deinit();
+ }
+
+ fn edit(fx: *Fixture, from: usize, command: []const u8) !Result {
+ var ctx: u8 = 0;
+ const world: World = .{ .ctx = &ctx, .check = check, .open = open, .read = read, .refuseGet = refuseGet };
+ return run(fx.arena_state.allocator(), &files, from, command, world, &fx.why);
+ }
+
+ /// File `i`'s text after the Edit.
+ fn after(fx: *Fixture, res: Result, i: usize) ![]const u8 {
+ return apply(fx.arena_state.allocator(), res.files[i].text, res.files[i].ops.items);
+ }
+};
+
fn edited(text: []const u8, command: []const u8) ![]u8 {
var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena_state.deinit();
@@ -1199,67 +1260,6 @@ test "x, y and s match whole runes: a byte pattern never splits one" {
try expectEdit("\u{e9}", ",s/$/!/", "\u{e9}!");
}
-/// Three files and a +Errors, the way the editor hands them over, and a
-/// world whose disk holds /src/new.c and /src/data.
-const Fixture = struct {
- arena_state: std.heap.ArenaAllocator,
- why: Why = .{},
-
- const files = [_]File{
- .{ .name = "/src/a.c", .text = "int foo;\nint bar;\n", .id = 0 },
- .{ .name = "/src/b.h", .text = "foo bar foo\n", .id = 1, .dirty = true },
- .{ .name = "/src/c.c", .text = "bar\n", .id = 2 },
- .{ .name = "/src/+Errors", .text = "foo\n", .id = 3, .scratch = true },
- };
-
- var opened: usize = 0;
-
- fn check(_: *anyopaque, path: []const u8, why: *Why) bool {
- if (std.mem.eql(u8, path, "/src/new.c")) return true;
- why.len = if (std.fmt.bufPrint(&why.buf, "B: cannot open {s}", .{path})) |said| said.len else |_| 0;
- return false;
- }
-
- /// The edited file, b.h, is asked about: refused.
- fn refuseGet(_: *anyopaque, id: usize, why: *Why) bool {
- if (id != 1) return false;
- why.len = (std.fmt.bufPrint(&why.buf, "/src/b.h: Modified (e again to discard)", .{}) catch unreachable).len;
- return true;
- }
-
- fn open(_: *anyopaque, path: []const u8, why: *Why) ?File {
- opened += 1;
- if (std.mem.eql(u8, path, "/src/new.c")) return .{ .name = "/src/new.c", .text = "new foo\n", .id = 9 };
- why.len = if (std.fmt.bufPrint(&why.buf, "B: cannot open {s}", .{path})) |said| said.len else |_| 0;
- return null;
- }
-
- fn read(_: *anyopaque, arena: std.mem.Allocator, path: []const u8, why: *Why) ?[]const u8 {
- if (std.mem.eql(u8, path, "/src/data")) return arena.dupe(u8, "DATA\n") catch null;
- why.len = if (std.fmt.bufPrint(&why.buf, "can't open {s}: file does not exist", .{path})) |said| said.len else |_| 0;
- return null;
- }
-
- fn init() Fixture {
- return .{ .arena_state = .init(std.testing.allocator) };
- }
-
- fn deinit(fx: *Fixture) void {
- fx.arena_state.deinit();
- }
-
- fn edit(fx: *Fixture, from: usize, command: []const u8) !Result {
- var ctx: u8 = 0;
- const world: World = .{ .ctx = &ctx, .check = check, .open = open, .read = read, .refuseGet = refuseGet };
- return run(fx.arena_state.allocator(), &files, from, command, world, &fx.why);
- }
-
- /// File `i`'s text after the Edit.
- fn after(fx: *Fixture, res: Result, i: usize) ![]const u8 {
- return apply(fx.arena_state.allocator(), res.files[i].text, res.files[i].ops.items);
- }
-};
-
test "X and Y run a command in each open file whose line matches, or does not" {
var fx: Fixture = .init();
defer fx.deinit();