diff options
Diffstat (limited to 'test/behaviour')
| -rw-r--r-- | test/behaviour/builtins.zig | 35 | ||||
| -rw-r--r-- | test/behaviour/keys.zig | 49 | ||||
| -rw-r--r-- | test/behaviour/settings.zig | 23 |
3 files changed, 107 insertions, 0 deletions
diff --git a/test/behaviour/builtins.zig b/test/behaviour/builtins.zig new file mode 100644 index 00000000..6f029072 --- /dev/null +++ b/test/behaviour/builtins.zig @@ -0,0 +1,35 @@ +//! docs/typ/builtins.typ, the builtins' glossary. +const std = @import("std"); +const Session = @import("session").Session; + +test "builtins: Mini maps a file of the pane's directory over pardes's own source of that name, in one pane, refreshed only when asked again" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "build.zig", .data = "x\n" }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "a\n" }); + var dir: [4096]u8 = undefined; + const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)]; + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try s.write("/look", s.at("{s}/a.txt\n", .{at})); + const a = try s.focused(); + // The directory's one-line build.zig, one braille row, not pardes's. + try s.write(s.at("/pane/{d}/exec", .{a}), "Mini build.zig\n"); + const mini = try s.focused(); + try std.testing.expect(mini != a); + const body = s.at("/pane/{d}/body", .{mini}); + try s.expect(body, "⠁\n"); + const index = try s.read("/index"); + try s.write(s.at("/pane/{d}/exec", .{mini}), "Mini build.zig\n"); + try std.testing.expectEqual(mini, try s.focused()); + try s.expect("/index", index); + // A snapshot: the file grown on disk shows only at the next Mini. + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "build.zig", .data = "xx\n" }); + try s.expect(body, "⠁\n"); + try s.write(s.at("/pane/{d}/exec", .{mini}), "Mini build.zig\n"); + try s.expect(body, "⠉\n"); + try s.expect("/index", index); + // Save asks for a path; nothing is written for it. + try s.write(s.at("/pane/{d}/exec", .{mini}), "Save\n"); + try std.testing.expectEqual(@as(usize, 0), s.saved); +} diff --git a/test/behaviour/keys.zig b/test/behaviour/keys.zig index 41a2821a..e659b369 100644 --- a/test/behaviour/keys.zig +++ b/test/behaviour/keys.zig @@ -225,3 +225,52 @@ test "keys: SPC j n and SPC j p walk Themes' rows, whole, never its section head try s.keys("\t"); try std.testing.expectEqualStrings(names.items[brk - 1]["Theme ".len..], try setting(&s, "Theme")); } + +test "keys: SPC j n in a command output selects its whole row, Tab runs it, and from where a Look took the keyboard it walks on there" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + for ([_][]const u8{ "a.txt", "b.txt" }) |name| try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = "x\n" }); + var dir: [4096]u8 = undefined; + const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)]; + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try s.write("/look", s.at("{s}/a.txt\n", .{at})); + const a = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{a}), "Themes\n"); + try s.keys(" jn"); + const themes = try s.focused(); + try std.testing.expect(themes != a); + const sel = s.at("/pane/{d}/sel", .{themes}); + try s.expect(sel, "Theme orchard"); + try s.keys(" jn\t"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nTheme dusk\n") != null); + try s.write(s.at("/pane/{d}/exec", .{a}), "Look b.txt\n"); + try std.testing.expect(try s.focused() != themes); + try s.keys(" jn"); + try std.testing.expectEqual(themes, try s.focused()); + try std.testing.expect(std.mem.startsWith(u8, try s.read(sel), "Theme ")); +} + +test "keys: SPC j n and SPC j p walk on from the place a Look's +Search listing chose, its keyboard left in the file" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "look-owner.txt", .data = "alpha target\nbeta target\ngamma target\n" }); + var dir: [4096]u8 = undefined; + const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)]; + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try s.write("/ctl", "LookWord list\n"); // the +Search listing is what is walked + try s.write("/look", s.at("{s}/look-owner.txt\n", .{at})); + const file = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{file}), "Look target\n"); + try std.testing.expectEqual(file, try s.focused()); + // The Look took the first; the walk goes on from it, and back. + try s.keys(" jn"); + const results = try s.focused(); + try std.testing.expect(results != file); + const sel = s.at("/pane/{d}/sel", .{results}); + try s.expect(sel, "look-owner.txt:2:6-11"); + try s.keys(" jp"); + try std.testing.expectEqual(results, try s.focused()); + try s.expect(sel, "look-owner.txt:1:7-12"); +} diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig index ff24704a..027fd1c9 100644 --- a/test/behaviour/settings.zig +++ b/test/behaviour/settings.zig @@ -101,3 +101,26 @@ test "settings: Config without a configuration directory says so and opens nothi try s.expect("/index", index); try expectHas(try s.read("/log"), "Config: no startup file here: no configuration directory"); } + +test "settings: every on/off setting the root ctl reads flips when its word is written bare, and Theme and Shell take a value" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + var lines = std.mem.tokenizeScalar(u8, try s.read("/ctl"), '\n'); + var flipped: usize = 0; + while (lines.next()) |line| { + const space = std.mem.indexOfScalar(u8, line, ' ') orelse continue; + const word, const was = .{ line[0..space], line[space + 1 ..] }; + const on = std.mem.eql(u8, was, "on"); + if (!on and !std.mem.eql(u8, was, "off")) continue; + try s.write("/ctl", s.at("{s}\n", .{word})); + try std.testing.expectEqualStrings(s.at("{s} {s}", .{ word, if (on) "off" else "on" }), try setting(&s, word)); + flipped += 1; + } + try std.testing.expect(flipped > 20); + for ([_][]const u8{ "Colors off", "Wrap off", "Tagbottom on", "Debug on" }) |want| + try std.testing.expectEqualStrings(want, try setting(&s, want[0..std.mem.indexOfScalar(u8, want, ' ').?])); + try s.write("/ctl", "Theme acme\n"); + try s.write("/ctl", "Shell /bin/sh\n"); + try std.testing.expectEqualStrings("Theme acme", try setting(&s, "Theme")); + try std.testing.expectEqualStrings("Shell /bin/sh", try setting(&s, "Shell")); +} |
