diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 10:35:50 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-04 10:41:18 -0300 |
| commit | fb9b3a3304e0bdbeffc68e56dfe2ad6511a6a64e (patch) | |
| tree | 828fd59465b245556c478b5a79ef88c69b99c751 /test/behaviour/panes.zig | |
| parent | f697bb13c3599db3ce30fac059932242597acdf6 (diff) | |
| download | pardes-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/panes.zig')
| -rw-r--r-- | test/behaviour/panes.zig | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig index a46f8432..553b1ca9 100644 --- a/test/behaviour/panes.zig +++ b/test/behaviour/panes.zig @@ -363,3 +363,188 @@ test "panes: a Mini that cannot read its file leaves the panes, the last Mini's try s.expect("/index", index); try s.expect(s.at("/pane/{d}/body", .{mini}), body); } + +test "panes: name refuses a directory, EISDIR, and leaves the name as it was" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const name = s.at("/pane/{d}/name", .{try s.focused()}); + for ([_][]const u8{ "/\n", "/tmp/\n", "sub/\n", "/tmp\n" }) |dir| { + try std.testing.expectEqual(@as(u16, 21), try s.refused(name, dir)); + try std.testing.expect(std.mem.indexOf(u8, s.said, "is a directory") != null); + } + try s.expect(name, "/test.txt\n"); +} + +test "panes: a write of two lines to name is refused EINVAL, on a held open or not" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const name = s.at("/pane/{d}/name", .{try s.focused()}); + try std.testing.expectEqual(@as(u16, 22), try s.refused(name, "/tmp/a\n/tmp/b\n")); + const h = try s.hold(name, 1); + try std.testing.expectEqual(@as(u16, 22), try s.writeFid(h, "/tmp/a\n/tmp/b\n")); + s.clunk(h); + try s.expect(name, "/test.txt\n"); + // Line by line, as bash writes it: the second line is refused. + const h2 = try s.hold(name, 1); + try std.testing.expectEqual(@as(u16, 0), try s.writeFid(h2, "/tmp/pardes-a\n")); + try std.testing.expectEqual(@as(u16, 22), try s.writeFid(h2, "/tmp/pardes-b\n")); + s.clunk(h2); + try s.expect(name, "/tmp/pardes-a\n"); +} + +test "panes: a name with a component over 255 bytes is refused by the write that holds it" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const name = s.at("/pane/{d}/name", .{try s.focused()}); + try std.testing.expectEqual(@as(u16, 22), try s.refused(name, "/tmp/" ++ &@as([256]u8, @splat('c')) ++ "/f.txt\n")); + try std.testing.expectEqualStrings("invalid file name: a component over 255 bytes", s.said); + const longest = "/tmp/" ++ &@as([255]u8, @splat('c')); + try s.write(name, longest ++ "\n"); + // Held with no newline, it is refused by that write, and the close + // has nothing left to apply. + const held = try s.hold(name, 1); + try std.testing.expectEqual(@as(u16, 22), try s.writeFid(held, "/tmp/" ++ &@as([256]u8, @splat('e')))); + s.clunk(held); + try s.expect(name, longest ++ "\n"); +} + +test "panes: a name cut across writes is one name, applied once at its newline or its close" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const name = s.at("/pane/{d}/name", .{try s.focused()}); + const h = try s.hold(name, 1); + _ = try s.writeFid(h, "/tmp/pardes-na"); + try s.expect(name, "/test.txt\n"); + _ = try s.writeFid(h, "me.txt\n"); + try s.expect(name, "/tmp/pardes-name.txt\n"); + s.clunk(h); + // No newline: held, and applied at the close. + const h3 = try s.hold(name, 1); + _ = try s.writeFid(h3, "/tmp/pardes-closed.txt"); + try s.expect(name, "/tmp/pardes-name.txt\n"); + s.clunk(h3); + try s.expect(name, "/tmp/pardes-closed.txt\n"); +} + +test "panes: name reads the file name, and a write promotes a scratch without touching its body or its file" { + const gpa = std.testing.allocator; + var s = try Session.initFile(gpa, "opener\n"); + defer s.deinit(); + const n = try s.newPane(); + const name = s.at("/pane/{d}/name", .{n}); + const body = s.at("/pane/{d}/body", .{n}); + const scratch = try s.read(name); + try std.testing.expect(std.mem.endsWith(u8, scratch, "/+New\n")); + try std.testing.expectEqual(@as(u64, scratch.len), (try s.stat(name)).size); + try s.write(body, "scratch "); + try s.write(body, "work\n"); + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "renamed.zig", .data = "existing target\n" }); + var dir_buf: [4096]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; + const path = s.at("{s}/renamed.zig", .{dir}); + try s.write(name, s.at("{s}\n", .{path})); + try s.expect(body, "scratch work\n"); + try s.expect(s.at("/pane/{d}/dirty", .{n}), "1\n"); + try s.expect(name, s.at("{s}\n", .{path})); + var target_buf: [64]u8 = undefined; + try std.testing.expectEqualStrings("existing target\n", try tmp.dir.readFile(std.testing.io, "renamed.zig", &target_buf)); + try std.testing.expectEqual(@as(u16, 22), try s.refused(name, "\n")); + // One name, and what no file name holds: a second line, a NUL. + for ([_][2][]const u8{ + .{ "two\nlines\n", "invalid file name: one name a write, on one line" }, + .{ "nul\x00.zig\n", "bad character in file name: a NUL" }, + }) |c| { + try std.testing.expectEqual(@as(u16, 22), try s.refused(name, c[0])); + try std.testing.expectEqualStrings(c[1], s.said); + } + // Any other byte a file name holds is taken, and reads back as written: + // blanks at its ends, a tab, a control byte, DEL, C1, bytes not UTF-8. + for ([_][]const u8{ " lead.zig ", "tab\t.zig", "c\x01.zig", "del\x7f.zig", "c1\xc2\x85.zig", "bad\xff.zig" }) |odd| { + try s.write(name, s.at("{s}\n", .{odd})); + const read_back = std.mem.trimEnd(u8, try s.read(name), "\n"); + try std.testing.expect(std.mem.endsWith(u8, read_back, odd)); + try s.write(name, read_back); + try s.expect(name, s.at("{s}\n", .{read_back})); + } + // A name that is one line and UTF-8 is taken, é and all. + try s.write(name, "caf\xc3\xa9.zig\n"); + try std.testing.expect(std.mem.endsWith(u8, try s.read(name), "/caf\xc3\xa9.zig\n")); + try s.write(name, "two words.zig\n"); + try s.expect(name, s.at("{s}/two words.zig\n", .{dir})); + // A rename is no edit: Undo takes back the last write. + try s.write(s.at("/pane/{d}/ctl", .{n}), "Undo\n"); + try s.expect(body, "scratch "); +} + +test "panes: relative names go from the file's directory and can name a new target" { + var s = try Session.initFile(std.testing.allocator, "retained body\n"); + defer s.deinit(); + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "note.txt", .data = "from pane directory\n" }); + var dir_buf: [4096]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; + const n = try s.focused(); + const name = s.at("/pane/{d}/name", .{n}); + try s.write(name, s.at("{s}/old.txt\n", .{dir})); + try s.write(name, "child/../note.txt\n"); + try s.write(s.at("/pane/{d}/ctl", .{n}), "get\n"); + try s.expect(s.at("/pane/{d}/body", .{n}), "from pane directory\n"); + try s.write(name, "./created.txt\n"); + try s.expect(name, s.at("{s}/created.txt\n", .{dir})); + // A name alone is no edit. + try s.expect(s.at("/pane/{d}/dirty", .{n}), "0\n"); +} + +test "panes: relative names follow a pane/new scratch's session directory, and a virtual one" { + var s = try Session.initFile(std.testing.allocator, "source body\n"); + defer s.deinit(); + const source = try s.focused(); + try s.write(s.at("/pane/{d}/name", .{source}), "/elsewhere/source.zig\n"); + // pane/new's scratch is the session's, not the active pane's. + const n = try s.newPane(); + const name = s.at("/pane/{d}/name", .{n}); + const session = std.fs.path.dirname(std.mem.trimEnd(u8, try s.read(name), "\n")).?; + try std.testing.expect(!std.mem.eql(u8, session, "/elsewhere")); + const up = std.fs.path.dirname(session) orelse ""; + try s.write(name, "../out/./notes.txt\n"); + try s.expect(name, s.at("{s}/out/notes.txt\n", .{up})); + try s.write(name, "again.txt\n"); + try s.expect(name, s.at("{s}/out/again.txt\n", .{up})); + try s.write(name, s.at("/virtual/pane/{d}/./body\n", .{source})); + try s.write(s.at("/pane/{d}/ctl", .{n}), "get\n"); + try s.expect(s.at("/pane/{d}/body", .{n}), "source body\n"); + try s.write(name, "./body\n"); + try s.expect(name, s.at("/virtual/pane/{d}/body\n", .{source})); + try s.expect(s.at("/pane/{d}/dirty", .{n}), "0\n"); +} + +test "panes: errors appends to one +Errors pane for the pane's directory" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), "+Errors") == null); + try s.write(s.at("/pane/{d}/errors", .{n}), "boom\n"); + try s.write(s.at("/pane/{d}/errors", .{n}), "again\n"); + const index = try s.read("/index"); + try std.testing.expectEqual(@as(usize, 1), std.mem.count(u8, index, " /+Errors ")); + const at = std.mem.indexOf(u8, index, " /+Errors ").?; + const line = index[(if (std.mem.lastIndexOfScalar(u8, index[0..at], '\n')) |i| i + 1 else 0)..]; + const serial = line[0..std.mem.indexOfScalar(u8, line, ' ').?]; + try s.expect(s.at("/pane/{s}/body", .{serial}), "boom\nagain\n"); +} + +test "panes: truncating body empties it, and a stat says the length after" { + var s = try Session.initFile(std.testing.allocator, "one\ntwo\n"); + defer s.deinit(); + const body = s.at("/pane/{d}/body", .{try s.focused()}); + const h = try s.hold(body, 1); + try s.truncate(h); + try std.testing.expectEqual(@as(u64, 0), (try s.stat(body)).size); + try s.expect(body, ""); + s.clunk(h); + try s.write(body, "new text\n"); + try std.testing.expectEqual(@as(u64, 9), (try s.stat(body)).size); +} |
