diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/behaviour.zig | 1 | ||||
| -rw-r--r-- | test/behaviour/find_grep.zig | 63 | ||||
| -rw-r--r-- | test/behaviour/look_and_exec.zig | 21 | ||||
| -rw-r--r-- | test/session.zig | 8 | ||||
| -rw-r--r-- | test/snapshots/find.golden | 2 | ||||
| -rw-r--r-- | test/snapshots/leader.golden | 4 |
6 files changed, 96 insertions, 3 deletions
diff --git a/test/behaviour.zig b/test/behaviour.zig index 9fe1f50b..3822988e 100644 --- a/test/behaviour.zig +++ b/test/behaviour.zig @@ -11,6 +11,7 @@ test { _ = @import("behaviour/columns_and_tags.zig"); _ = @import("behaviour/edit.zig"); _ = @import("behaviour/event.zig"); + _ = @import("behaviour/find_grep.zig"); _ = @import("behaviour/flags.zig"); _ = @import("behaviour/follow.zig"); _ = @import("behaviour/from_acme.zig"); diff --git a/test/behaviour/find_grep.zig b/test/behaviour/find_grep.zig new file mode 100644 index 00000000..49bf64aa --- /dev/null +++ b/test/behaviour/find_grep.zig @@ -0,0 +1,63 @@ +//! docs/typ/reference.typ, Find and Grep <find-grep>. +const std = @import("std"); +const Session = @import("session").Session; + +fn has(haystack: []const u8, needle: []const u8) bool { + return std.mem.indexOf(u8, haystack, needle) != null; +} + +/// A project in `tmp`: a `.jj` at its top, `top.txt` there and `x.txt` +/// two directories below, in `a/b`, each holding `needle`; its path. +fn project(s: *Session, tmp: *std.testing.TmpDir) ![]const u8 { + try tmp.dir.createDirPath(std.testing.io, ".jj"); + try tmp.dir.createDirPath(std.testing.io, "a/b"); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "top.txt", .data = "needle at the top\n" }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a/b/x.txt", .data = "needle below\n" }); + var buf: [4096]u8 = undefined; + return s.arena.allocator().dupe(u8, buf[0..try tmp.dir.realPath(std.testing.io, &buf)]); +} + +test "find-grep: SPC f f lists the files of the pane's directory, SPC f F those of the project's root above it, its head `Find root`" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const root = try project(&s, &tmp); + _ = try s.lookFile(s.at("{s}/a/b/x.txt", .{root})); + try s.keys(" ff"); + s.tick(); + _ = try s.where("▶ x.txt"); + try std.testing.expect(!has(try s.screen(), "top.txt")); + try std.testing.expect(!has(try s.screen(), "Find root")); + try s.keys("\x1b"); + // From the root: its files by their paths from it, `.jj` passed over. + try s.keys(" fF"); + s.tick(); + _ = try s.where("␣ f Find root"); + _ = try s.where(" a/b/x.txt"); + _ = try s.where(" top.txt"); + try std.testing.expect(!has(try s.screen(), ".jj")); +} + +test "find-grep: SPC f G greps from the project's root above the pane's directory, its head `Grep root`, a leading directory narrowing it from the root" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const root = try project(&s, &tmp); + _ = try s.lookFile(s.at("{s}/a/b/x.txt", .{root})); + try s.keys(" fGneedle"); + s.advance(100 * std.time.ns_per_ms); + s.tick(); + _ = try s.where("␣ f Grep root needle"); + // Each row its place from the root, the places' column padded. + _ = try s.where("a/b/x.txt:1 needle below"); + _ = try s.where("top.txt:1 needle at the top"); + try s.keys("\x1b"); + // `a needle`: the root's a/, which the pane's directory has not. + try s.keys(" fGa needle"); + s.advance(100 * std.time.ns_per_ms); + s.tick(); + _ = try s.where("a/b/x.txt:1 needle below"); + try std.testing.expect(!has(try s.screen(), "top.txt:1")); +} diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig index 3e6137b1..387c28a7 100644 --- a/test/behaviour/look_and_exec.zig +++ b/test/behaviour/look_and_exec.zig @@ -442,6 +442,27 @@ fn tmpPath(s: *Session, tmp: *std.testing.TmpDir) ![]const u8 { return s.at("{s}", .{buf[0..try tmp.dir.realPath(std.testing.io, &buf)]}); } +test "look-and-exec: SPC : runs its line in a command pane at the project's root, the nearest directory at or above the pane's holding a .jj or a .git, where `:` runs it in the pane's own; its head `: root`" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.createDirPath(std.testing.io, ".git"); + try tmp.dir.createDirPath(std.testing.io, "a/b"); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a/b/x.txt", .data = "x\n" }); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const root = try tmpPath(&s, &tmp); + _ = try s.lookFile(s.at("{s}/a/b/x.txt", .{root})); + try s.keys(":pwd\n"); + const here = try paneNamed(&s, s.at("{s}/a/b", .{root})); + try std.testing.expect(std.mem.startsWith(u8, try s.read(s.at("/pane/{d}/body", .{here})), "% pwd\n")); + try s.keys(" :"); + _ = try s.where(": root"); + try s.keys("pwd\n"); + const at_root = try paneNamed(&s, root); + try std.testing.expect(at_root != here); + try std.testing.expect(std.mem.startsWith(u8, try s.read(s.at("/pane/{d}/body", .{at_root})), "% pwd\n")); +} + test "look-and-exec: a look opens spaced paths and locations without editing the source pane" { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); diff --git a/test/session.zig b/test/session.zig index 91cca3e5..e82c8bee 100644 --- a/test/session.zig +++ b/test/session.zig @@ -340,6 +340,14 @@ pub const Session = struct { s.drain(); } + /// The host's clock on by `ns`, as its loop moves it: what waits on + /// time (a typed Grep's pause) is due at the next tick. + pub fn advance(s: *Session, ns: u64) void { + const p = pardesOf(s); + p.advance(p.clock.now_ns + ns); + s.drain(); + } + /// Kinds' jobs and draws held from now on (`hold_jobs`), until /// `releaseJobs`. pub fn holdJobs(s: *Session) void { diff --git a/test/snapshots/find.golden b/test/snapshots/find.golden index 493f9e11..ac1e433d 100644 --- a/test/snapshots/find.golden +++ b/test/snapshots/find.golden @@ -1,7 +1,7 @@ == snap group grid=120x41 cursor=hidden | New Term Find Grep Newcol Help Exit | /tmp/pardes-snap/find/cwd/here.txt Keep Del -| ␣ f ▸ c Config f Find g Grep h History l Lists n New r Recent s Save ? help +| ␣ f ▸ c Config f Find F Find root g Grep G Grep root h History l Lists n New r Recent s Save ? help | | | diff --git a/test/snapshots/leader.golden b/test/snapshots/leader.golden index 29f86d82..cffccfa6 100644 --- a/test/snapshots/leader.golden +++ b/test/snapshots/leader.golden @@ -2,7 +2,7 @@ | New Term Find Grep Newcol Help Exit | /tmp/pardes-snap/leader/cwd/cmds.txt Keep Del | ␣ ▸ b buffer… c column… f file… h help… j jump… l lsp… n new… s session… t view… ' Resume -| │ / All ? Help d Del e Message p ClipPaste P ClipPasteBefore q Exit R ClipReplace +| │ / All : Root ? Help d Del e Message p ClipPaste P ClipPasteBefore q Exit R ClipReplace | │ w Window y ClipYank Y ClipYankMain ? help | | @@ -48,7 +48,7 @@ |2: 1 Help Help h Help t Help c Help l == snap unmapped grid=100x41 cursor=hidden |2: ␣ ▸ b buffer… c column… f file… h help… j jump… l lsp… n new… s session… t view… ' Resume -|3: │ / All ? Help d Del e Message p ClipPaste P ClipPasteBefore q Exit R ClipReplace +|3: │ / All : Root ? Help d Del e Message p ClipPaste P ClipPasteBefore q Exit R ClipReplace |4: │ w Window y ClipYank Y ClipYankMain x ? help == snap help-group grid=100x41 cursor=7,5 |2: 1 Help Help h Help t Help c Help l |
