summaryrefslogtreecommitdiff
path: root/test/behaviour/flags.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/flags.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/flags.zig')
-rw-r--r--test/behaviour/flags.zig60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/behaviour/flags.zig b/test/behaviour/flags.zig
index 656d219f..0c8b6660 100644
--- a/test/behaviour/flags.zig
+++ b/test/behaviour/flags.zig
@@ -40,3 +40,63 @@ test "flags: dirty, mark and scroll read and write the state acme kept behind ct
try t.expect(term_dirty, "0\n");
try std.testing.expectEqual(@as(u16, 22), try t.refused(term_dirty, "1"));
}
+
+test "flags: a > into an empty body is one undo step, as into any other" {
+ var s = try Session.initFile(std.testing.allocator, "");
+ defer s.deinit();
+ const n = try s.focused();
+ const body = s.at("/pane/{d}/body", .{n});
+ try s.replace(body, "fresh\n");
+ try s.expect(body, "fresh\n");
+ try s.write(s.at("/pane/{d}/ctl", .{n}), "Undo\n");
+ try s.expect(body, "");
+}
+
+test "flags: a write that changes nothing, an empty range deleted or a range replaced by itself, is no undo step and no new version" {
+ var s = try Session.initFile(std.testing.allocator, "abc\ndef\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const body = s.at("/pane/{d}/body", .{n});
+ const addr = s.at("/pane/{d}/addr", .{n});
+ const data = s.at("/pane/{d}/data", .{n});
+ const ctl = s.at("/pane/{d}/ctl", .{n});
+ // One real change, so a step made after it would be the one undone.
+ try s.write(addr, "1");
+ try s.write(data, "abd\n");
+ const version = (try s.stat(body)).version;
+ // Each as a shell does it: `: > data` after an empty address, `echo
+ // abd > data` over the line it holds, and Edit's `s/d/d/`.
+ try s.write(addr, "#2,#2");
+ const h = try s.hold(data, 1);
+ try s.truncate(h);
+ s.clunk(h);
+ try s.write(addr, "1");
+ try s.write(data, "abd\n");
+ try s.write(ctl, "Edit ,s/d/d/\n");
+ try s.expect(body, "abd\ndef\n");
+ try std.testing.expectEqual(version, (try s.stat(body)).version);
+ try s.write(ctl, "Undo\n");
+ try s.expect(body, "abc\ndef\n");
+}
+
+test "flags: an open's writes in a row go in as one edit, seen by the next request" {
+ var s = try Session.initFile(std.testing.allocator, "one\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const body = s.at("/pane/{d}/body", .{n});
+ const version = (try s.stat(body)).version;
+ const h = try s.hold(body, 1);
+ for (0..100) |_| try std.testing.expectEqual(@as(u16, 0), try s.writeFid(h, "0123456789\n"));
+ try std.testing.expectEqual(@as(usize, 4 + 1100), (try s.read(body)).len);
+ try std.testing.expectEqual(version + 1, (try s.stat(body)).version);
+ s.clunk(h);
+ try s.write(s.at("/pane/{d}/ctl", .{n}), "Undo\n");
+ try s.expect(body, "one\n");
+ // data inserts at its address go on the same way.
+ try s.write(s.at("/pane/{d}/addr", .{n}), "#0");
+ const d = try s.hold(s.at("/pane/{d}/data", .{n}), 1);
+ _ = try s.writeFid(d, "a");
+ _ = try s.writeFid(d, "b");
+ s.clunk(d);
+ try s.expect(body, "abone\n");
+}