diff options
Diffstat (limited to 'src/ninep/ctl.zig')
| -rw-r--r-- | src/ninep/ctl.zig | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 45336a1e..635e03a6 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -3017,7 +3017,7 @@ test "a builtin that needs its argument, written bare to an exec, is EINVAL as t } } -test "Grep with no hit says grep: no match and opens nothing, a missing pane directory passed over" { +test "a script's Grep and Find fill the pane's one query pane, a row a line under its file; a miss says not found and opens nothing" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); var tmp = testing.tmpDir(.{}); @@ -3028,22 +3028,26 @@ test "Grep with no hit says grep: no match and opens nothing, a missing pane dir const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; var line: [4200]u8 = undefined; _ = wr(p, Node.of(serialOf(p), .name), try std.fmt.bufPrint(&line, "{s}/a.txt\n", .{dir})); - // A hit opens its +Search, a row a line: exec reads it back. Find and - // Grep share it, a directory's one +Search, each run replacing it. + // A hit fills the pane's query pane, line 1 the command, its rows under + // the file they are in: exec reads it back. Find and Grep share it, the + // pane's one query pane, each run replacing it. try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .exec), "Grep bravo\n").reply.status); const grepped = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?; - try testing.expectEqual(@as(usize, 2), std.mem.count(u8, grepped.file.?.content, "other.txt:")); - try testing.expect(std.mem.indexOf(u8, grepped.file.?.content, "other.txt:2") != null); - try testing.expect(std.mem.indexOf(u8, grepped.file.?.content, "other.txt:3") != null); + const rows = grepped.file.?.content; + try testing.expect(std.mem.startsWith(u8, rows, "Grep bravo\n")); + try testing.expect(std.mem.indexOf(u8, rows, "\nother.txt\n") != null); + try testing.expect(std.mem.indexOf(u8, rows, "2 bravo here\n") != null); + try testing.expect(std.mem.indexOf(u8, rows, "3 three bravo\n") != null); + try testing.expectEqual(@as(usize, 2), grepped.query.?.total); try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .exec), "Find other\n").reply.status); const found = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?; - try testing.expect(std.mem.indexOf(u8, found.file.?.content, "other.txt") != null); try testing.expectEqual(grepped.serial, found.serial); + try testing.expect(std.mem.indexOf(u8, found.file.?.content, "\nother.txt\n") != null); try testing.expect(std.mem.indexOf(u8, found.file.?.content, "bravo here") == null); - // The same Find again reads back the +Search, not the pane it ran in. + // The same Find again reads back the query pane, not the pane it ran in. try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .exec), "Find other\n").reply.status); try testing.expectEqualStrings(try std.fmt.bufPrint(&line, "{d}\n", .{found.serial}), rd(p, root_exec, 0, 64).bytes); - // A Grep run from the +Search itself fills that one, never a second. + // A Grep run from the query pane itself fills that one, never a second. try testing.expectEqual(Status.ok, wr(p, Node.of(found.serial, .exec), "Grep bravo\n").reply.status); try testing.expectEqualStrings(try std.fmt.bufPrint(&line, "{d}\n", .{found.serial}), rd(p, root_exec, 0, 64).bytes); var searches: usize = 0; @@ -3052,23 +3056,19 @@ test "Grep with no hit says grep: no match and opens nothing, a missing pane dir }; try testing.expectEqual(@as(usize, 1), searches); try testing.expect(std.mem.indexOf(u8, found.file.?.content, "bravo here") != null); - // A second pane in a directory that is not there. - const other = try th.newPane(p); - _ = wr(p, Node.of(other, .name), "/tmp/pardes-no-such-dir-zz/b.txt\n"); var count: usize = 0; for (p.panes) |slot| count += @intFromBool(slot != null); + // A miss: said to the script, the query pane's count 0, nothing opened. const missed = wr(p, Node.of(serialOf(p), .exec), "Grep zzqqnomatchzz\n"); try testing.expectEqual(E.NOENT, missed.errno()); try testing.expectEqualStrings("Grep: text not found", missed.reply.ename); + try testing.expectEqual(@as(usize, 0), found.query.?.total); const unfound = wr(p, Node.of(serialOf(p), .exec), "Find zzqqnomatchzz\n"); try testing.expectEqual(E.NOENT, unfound.errno()); try testing.expectEqualStrings("Find: name not found", unfound.reply.ename); var after: usize = 0; for (p.panes) |slot| after += @intFromBool(slot != null); try testing.expectEqual(count, after); - // The +Search a miss would have filled keeps the last search's rows: - // the miss is said, and its tag names what they are of. - try testing.expect(std.mem.indexOf(u8, found.file.?.content, "bravo here") != null); } test "Unmount of a name not mounted says no such mount, which a mount reads as ENOENT" { @@ -4911,7 +4911,7 @@ test "a Rename the server answered for this file alone, with other open files sa try testing.expect(th.logHas(p, "Rename: previewed, not applied: the server renamed in this file only, and 1 other open file(s) say the name")); } -test "Find ends with what it skipped, and a Find or Grep that finds nothing leaves the +Search as it was" { +test "Find says what it skipped under its names, and a script's Find that finds nothing is told so" { if (comptime !pardes.hosted) return; const gpa = testing.allocator; var tmp = testing.tmpDir(.{}); @@ -4928,18 +4928,18 @@ test "Find ends with what it skipped, and a Find or Grep that finds nothing leav const path = try std.fmt.bufPrint(&path_buf, "{s}/zz-needle.txt", .{dir}); const p = try Pardes.init(gpa, .{ .file = path, .tty_only = true, .cols = 80, .rows = 30 }); defer p.deinit(); - try testing.expect(p.executeBuiltinLine(0, "Find needle")); - const search = p.panes[p.panes[0].?.search_pane.?].?; + // the walk's own skips are what is said (rg would pass over in silence) + p.stream.engine = .walk; + try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .exec), "Find needle\n").reply.status); + const search = p.panes[pardes.panes.Query.ofOwner(p, p.panes[0].?.serial).?].?; const listed = search.file.?.content; try testing.expect(std.mem.endsWith(u8, listed, "1 directory skipped: permission denied\n")); - try testing.expect(std.mem.startsWith(u8, listed, "zz-needle.txt\n")); - // Nothing found where it looked, and nothing passed over: the miss is - // said, and the +Search keeps the last search's rows. + try testing.expect(std.mem.startsWith(u8, listed, "Find needle\nzz-needle.txt\n")); + // Nothing found: the miss is said, the query pane's count 0. _ = std.c.chmod(locked, 0o755); - const before = try gpa.dupe(u8, listed); - defer gpa.free(before); - try testing.expect(p.executeBuiltinLine(0, "Find nosuchname")); - try testing.expectEqualStrings(before, search.file.?.content); + const missed = wr(p, Node.of(serialOf(p), .exec), "Find nosuchname\n"); + try testing.expectEqual(E.NOENT, missed.errno()); + try testing.expectEqual(@as(usize, 0), search.query.?.total); try testing.expect(th.logHas(p, "Find: name not found")); } |
