summaryrefslogtreecommitdiff
path: root/test/behaviour/addresses.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 10:35:50 -0300
committerGabriel Schneider <[email protected]>2026-11-04 10:41:18 -0300
commitfb9b3a3304e0bdbeffc68e56dfe2ad6511a6a64e (patch)
tree828fd59465b245556c478b5a79ef88c69b99c751 /test/behaviour/addresses.zig
parentf697bb13c3599db3ce30fac059932242597acdf6 (diff)
downloadpardes-fb9b3a3304e0bdbeffc68e56dfe2ad6511a6a64e.tar.gz
pardes-fb9b3a3304e0bdbeffc68e56dfe2ad6511a6a64e.zip
test: nineteen of src/ninep/pane.zig's tests through the 9P tree alone: in test/behaviour/flags.zig a > into an empty body one undo step (Undo empties it), a write that changes nothing no step and no new qid version (an empty : > data, a line written over itself, Edit's s/d/d/), and an open's hundred writes one edit (version +1, one Undo); in addresses.zig a 9P write moving dot as acme's textinsert (dot written, read back), an addr pair out of order or range refused in the address form's words, every address on a rune (a combining mark, a lone \r, a match inside a rune), and truncating data or xdata deleting only the addressed range; in panes.zig name refusing a directory (EISDIR), two lines on a held open or not, a component over 255 bytes by the write that holds it, a name cut across writes applied at its newline or close, a scratch promoted by name without touching its body, its file on disk or its undo, relative names from the file's directory and from a pane/new scratch's session directory and a /virtual one, errors appending to one +Errors (found in /index), and a truncated body's stat; in tags.zig a pane tag read whole and appended to up to 4096 bytes, and a truncated tag cleared, undone by u in the tag, clicked on, and a > dropping its one trailing newline; in look_and_exec.zig a pane's tagexec; each checked to fail against a break (a truncated empty body's step joined, spliceBody's no-op return gone, every held write put in at once, shiftOne growing nothing at dot's start, a pair's range unchecked, #n not snapped to a rune, data's truncation to the end, is_dir false, o.named never set, a held name's component limit 1255, a pane open's closing line dropped, a rename pushing an undo step, names resolved from /, pane/new taking the active pane's directory, a new +Errors every write, the tag's room one more, the tag's clear not remembered, the results read with a blank, an empty truncation of body); two old tests trimmed to what is an effect (a long path's failed Save; the watch a rename asks for); the line-index U test, the clock-held writes X test and the terminal and shell ones (pty bytes, output, spawns) stay
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/behaviour/addresses.zig')
-rw-r--r--test/behaviour/addresses.zig91
1 files changed, 91 insertions, 0 deletions
diff --git a/test/behaviour/addresses.zig b/test/behaviour/addresses.zig
index a1474c3d..dde36f59 100644
--- a/test/behaviour/addresses.zig
+++ b/test/behaviour/addresses.zig
@@ -63,3 +63,94 @@ test "addresses: sel reads the selection, and a write to sel replaces it and is
try s.expect(body, "ab\ntwo\n");
try s.expect(sel, "ab");
}
+
+test "addresses: a 9P write moves dot only as acme's textinsert does" {
+ // dot is `cd` of `abcdef\n` (2 4); two bytes go in at `at`.
+ for ([_][3]u32{
+ .{ 0, 4, 6 }, // before: shifted
+ .{ 2, 2, 6 }, // at its start: grown
+ .{ 3, 2, 6 }, // inside: grown
+ .{ 4, 2, 4 }, // at its end: left
+ .{ 6, 2, 4 }, // after: left
+ }) |c| {
+ var s = try Session.initFile(std.testing.allocator, "abcdef\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const dot = s.at("/pane/{d}/dot", .{n});
+ try s.write(dot, "2 4");
+ try s.write(s.at("/pane/{d}/addr", .{n}), s.at("#{d}", .{c[0]}));
+ try s.write(s.at("/pane/{d}/data", .{n}), "XX");
+ try expectEqual(.{ c[1], c[2] }, try s.range(dot));
+ }
+ // A body append leaves dot, and a sel write after it replaces dot, not
+ // the text appended.
+ var s = try Session.initFile(std.testing.allocator, "abcdef\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const dot = s.at("/pane/{d}/dot", .{n});
+ try s.write(dot, "2 4");
+ try s.write(s.at("/pane/{d}/body", .{n}), "more\n");
+ try expectEqual(.{ @as(u32, 2), @as(u32, 4) }, try s.range(dot));
+ try s.write(s.at("/pane/{d}/sel", .{n}), "YY");
+ try s.expect(s.at("/pane/{d}/body", .{n}), "abYYef\nmore\n");
+}
+
+test "addresses: a pair out of order or out of range is refused as the address form is, not clamped" {
+ var s = try Session.initFile(std.testing.allocator, "abcdef\n");
+ defer s.deinit();
+ const addr = s.at("/pane/{d}/addr", .{try s.focused()});
+ for ([_][2][]const u8{
+ .{ "5 2", "addresses out of order" },
+ .{ "#5,#2", "addresses out of order" },
+ .{ "2 99", "address out of range" },
+ .{ "#2,#99", "address out of range" },
+ }) |c| {
+ try expectEqual(@as(u16, 22), try s.refused(addr, c[0]));
+ try std.testing.expectEqualStrings(c[1], s.said);
+ }
+ try s.write(addr, "2 4");
+ try expectEqual(.{ @as(u32, 2), @as(u32, 4) }, try s.range(addr));
+}
+
+test "addresses: every address lands on a rune, and a combining mark and a lone \\r are places of their own" {
+ // e, U+0301 (two bytes, 1-2), x, \r, \n
+ var s = try Session.initFile(std.testing.allocator, "e\u{0301}x\r\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const addr = s.at("/pane/{d}/addr", .{n});
+ for ([_]struct { []const u8, u32, u32 }{
+ .{ "#1,#3", 1, 3 }, // the mark alone
+ .{ "#2", 1, 1 }, // inside it: back to its start
+ .{ "#4,#5", 4, 5 }, // the \r alone
+ .{ "1:2", 1, 1 }, // line:col the same
+ .{ "1:3", 1, 1 },
+ .{ "0/\xCC/", 1, 3 }, // a match inside a rune covers it
+ }) |c| {
+ try s.write(addr, c[0]);
+ try expectEqual(.{ c[1], c[2] }, try s.range(addr));
+ }
+ // Copied to dot, it reads back the same.
+ const dot = s.at("/pane/{d}/dot", .{n});
+ try s.write(addr, "#1,#3");
+ try s.write(dot, " 1 3 ");
+ try s.expect(dot, " 1 3 ");
+ try s.write(addr, "#4,#5");
+ try s.expect(s.at("/pane/{d}/xdata", .{n}), "\r");
+}
+
+test "addresses: truncating data or xdata deletes only the addressed range, so > data replaces it" {
+ var s = try Session.initFile(std.testing.allocator, "");
+ defer s.deinit();
+ const n = try s.focused();
+ const body = s.at("/pane/{d}/body", .{n});
+ for ([_][]const u8{ "data", "xdata" }) |file| {
+ try s.replace(body, "hello world\nsecond line\n");
+ try s.write(s.at("/pane/{d}/addr", .{n}), "#0,#5");
+ const h = try s.hold(s.at("/pane/{d}/{s}", .{ n, file }), 1);
+ try s.truncate(h);
+ try s.expect(body, " world\nsecond line\n");
+ try expectEqual(@as(u16, 0), try s.writeFid(h, "HOWDY"));
+ s.clunk(h);
+ try s.expect(body, "HOWDY world\nsecond line\n");
+ }
+}