From 7bbcd971a761def328fb9eeb881301bf45fb4783 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 10:28:11 -0300 Subject: test: twenty-one of src/ninep/ctl.zig's tests through the 9P tree alone: in test/behaviour/look_and_exec.zig a look's miss quoting up to 256 bytes then an ellipsis, @p:
taking any sam address (a miss and an unknown serial errs), file:3:0 refused as addr 3:0 is, ./x, ../x, x and /abs/x misses, a terminal's file:addr miss logged once, and an exec's builtin refused wrong #args bare or with an argument it takes none of; in flags.zig Undo and Redo stepping the body and saying when there is none (counted), dirty back to 0 at the saved text; in edit.zig an Edit rename one undo step and a failed one changing nothing; in panes.zig Mini bare, the name word bare, and ctl's undo and redo fields; in addresses.zig malformed addresses and a terminal's addr, dot and limit refused; in event.zig a bad record's words; in the new repls.zig Repl with no such language; in settings.zig two bad values logged as two; in root_ctl.zig Kill with a name and nothing running; in mounts.zig an unknown network a bad dial address; the old Unmount test dropped, mounts.zig's first test covering it; each checked to fail against a break (miss_path_cap 200, "no pane at", captured's wrong #args words, Redo's and Kill's messages, the name word's refusal, an event's backwards-range words, e_syntax, Repl's "others)", Mount's bad dial words, a splice back to the saved text left dirty, Edit's no substitution words, a setting's refusal quoting "x", zeroColumn missing a column 0, a look's no such file words, a terminal's text miss unquoted, ctl's undo flag needing two edits) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour/look_and_exec.zig | 110 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) (limited to 'test/behaviour/look_and_exec.zig') diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig index 98cab342..360055d2 100644 --- a/test/behaviour/look_and_exec.zig +++ b/test/behaviour/look_and_exec.zig @@ -323,3 +323,113 @@ test "look-and-exec: a +PdfSections row's first number is the page: a section no _ = try s.refused(look, "design.pdf:1:999\n"); try expectEqual(@as(usize, 2), try errs(&s)); } + +test "look-and-exec: a look's miss repeats the path whole up to 256 bytes, then gives up its middle to an ellipsis" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const long = "some/deeply/nested/directory/that/goes/on/and/on/with/a_rather_long_file_name.txt"; + try s.write("/look", long ++ "\n"); + try std.testing.expect(has(try s.read("/log"), "look: no match for \"" ++ long ++ "\"\n")); + const huge = std.mem.asBytes(&@as([150][2]u8, @splat("é".*))); // 300 bytes: its middle cut to fit 256, between characters + const kept = std.mem.asBytes(&@as([63][2]u8, @splat("é".*))); + try s.write("/look", huge ++ "\n"); + try std.testing.expect(has(try s.read("/log"), "look: no match for \"" ++ kept ++ "…" ++ kept ++ "\"\n")); +} + +test "look-and-exec: @p:
takes any sam address; a miss and an unknown serial are errs" { + var s = try Session.initFile(std.testing.allocator, "foo x foo y\nbar\n"); + defer s.deinit(); + const n = try s.focused(); + const dot = s.at("/pane/{d}/dot", .{n}); + const Case = struct { []const u8, u32, u32 }; + for ([_]Case{ + .{ "0/foo/", 0, 3 }, + .{ "/foo/", 6, 9 }, + .{ "#12,#15", 12, 15 }, + .{ "$", 16, 16 }, + .{ "1,2", 0, 16 }, + // Backward, as in addr: from the dot's start, wrapping to the last. + .{ "?foo?", 6, 9 }, + .{ "$-?y?", 10, 11 }, + }) |c| { + try s.write("/look", s.at("@p{d}:{s}\n", .{ n, c[0] })); + try expectEqual(.{ c[1], c[2] }, try s.range(dot)); + } + try s.write("/look", s.at("@p{d}:/zzqq/\n", .{n})); + try std.testing.expect(has(try s.read("/log"), ": no match for regexp")); + try s.expect("/look", ""); + try s.write("/look", "@p999:/foo/\n"); + try std.testing.expect(has(try s.read("/log"), "look: no pane @p999")); + try s.expect("/look", ""); + // A line address to no pane is a miss too, not the active pane. + try s.write("/look", "@p77:1\n"); + try std.testing.expect(has(try s.read("/log"), "look: no pane @p77")); + try s.expect("/look", ""); +} + +test "look-and-exec: a look at file:3:0 is refused as addr 3:0 is, a column counting from 1" { + var s = try Session.initFile(std.testing.allocator, "one\ntwo\nthree\n"); + defer s.deinit(); + const n = try s.focused(); + try expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/addr", .{n}), "3:0")); + const by_addr = s.said; + try expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/look", .{n}), "/test.txt:3:0\n")); + try std.testing.expectEqualStrings(by_addr, s.said); + try s.write(s.at("/pane/{d}/look", .{n}), "/test.txt:3:1\n"); +} + +test "look-and-exec: a look of ./x, x or /abs/x that is not there is a miss: answered, the err logged" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const look = s.at("/pane/{d}/look", .{try s.focused()}); + for ([_][]const u8{ "./zzq-nosuch.txt\n", "zzq-nosuch.txt\n", "/zzq-nosuch.txt\n" }) |line| try s.write(look, line); + try std.testing.expect(has(try s.read("/log"), "look: ./zzq-nosuch.txt: no such file")); +} + +test "look-and-exec: a look at a ./ or ../ name that is not there is a miss naming the file; a plain one is looked for as text" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.createDirPath(std.testing.io, "many"); + var buf: [4096]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)]; + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + try s.write(s.at("/pane/{d}/name", .{n}), s.at("{s}/many/a.txt\n", .{dir})); + for ([_][]const u8{ "./zz.txt", "../zz.txt" }) |name| { + try s.write(s.at("/pane/{d}/look", .{n}), s.at("{s}\n", .{name})); + try std.testing.expect(has(try s.read("/log"), s.at("look: {s}: no such file", .{name}))); + } + try s.write(s.at("/pane/{d}/look", .{n}), "zz.txt\n"); + try std.testing.expect(has(try s.read("/log"), "look: no match for \"zz.txt\"")); +} + +test "look-and-exec: a look at file:addr whose file is not there is one miss, quoting what was written, in a terminal too" { + var s = try Session.initTerm(std.testing.allocator); + defer s.deinit(); + const look = s.at("/pane/{d}/look", .{try s.focused()}); + const before = try errs(&s); + for ([_][]const u8{ "zzq:#3", "zzq:2", "zzq:/re/" }) |written| { + try s.write(look, s.at("{s}\n", .{written})); + try expectEqual(@as(usize, 1), std.mem.count(u8, try s.read("/log"), s.at("look: no match for \"{s}\"\n", .{written}))); + } + try expectEqual(before + 3, try errs(&s)); +} + +test "look-and-exec: a builtin that needs its argument, written bare to an exec, is EINVAL as through ctl" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + for ([_][]const u8{ "/exec", s.at("/pane/{d}/exec", .{try s.focused()}), "/tagexec" }) |path| { + try expectEqual(@as(u16, 22), try s.refused(path, "Mount\n")); + try std.testing.expectEqualStrings("wrong #args in control message \"Mount\"", s.said); + } +} + +test "look-and-exec: a builtin that takes no argument, written with one to an exec, is refused wrong #args, as at a ctl" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + for ([_][]const u8{ "/exec", s.at("/pane/{d}/exec", .{try s.focused()}) }) |path| for ([_][]const u8{ "Config extra\n", "DumpConfig extra\n" }) |line| { + try expectEqual(@as(u16, 22), try s.refused(path, line)); + try std.testing.expect(std.mem.startsWith(u8, s.said, "wrong #args in control message")); + }; +} -- cgit v1.3