summaryrefslogtreecommitdiff
path: root/test/behaviour/flags.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/behaviour/flags.zig')
-rw-r--r--test/behaviour/flags.zig42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/behaviour/flags.zig b/test/behaviour/flags.zig
index 656d219f..9eca2e38 100644
--- a/test/behaviour/flags.zig
+++ b/test/behaviour/flags.zig
@@ -40,3 +40,45 @@ test "flags: dirty, mark and scroll read and write the state acme kept behind ct
try t.expect(term_dirty, "0\n");
try std.testing.expectEqual(@as(u16, 22), try t.refused(term_dirty, "1"));
}
+
+fn has(hay: []const u8, needle: []const u8) bool {
+ return std.mem.indexOf(u8, hay, needle) != null;
+}
+
+test "flags: Undo and Redo on a pane's ctl step its body through its edits, and say when there is none, counted" {
+ var s = try Session.initFile(std.testing.allocator, "one\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const body = s.at("/pane/{d}/body", .{n});
+ const ctl = s.at("/pane/{d}/ctl", .{n});
+ try s.write(body, "two\n");
+ try s.expect(body, "one\ntwo\n");
+ try s.write(ctl, "Undo");
+ try s.expect(body, "one\n");
+ try s.write(ctl, "Redo");
+ try s.expect(body, "one\ntwo\n");
+ // Nothing left: said, and the write still succeeds, as acme's is silent.
+ try s.write(ctl, "Redo");
+ try std.testing.expect(has(try s.read("/log"), "Redo: nothing to redo"));
+ try s.write(ctl, "Undo");
+ try s.write(ctl, "Undo");
+ try std.testing.expect(has(try s.read("/log"), "Undo: nothing to undo"));
+ // Said again word for word, it is that line counted, as err's are.
+ for (0..3) |_| try s.write(ctl, "Undo");
+ try std.testing.expect(has(try s.read("/log"), "Undo: nothing to undo (x4)\n"));
+}
+
+test "flags: dirty goes back to 0 when the text is the saved text again" {
+ var s = try Session.initFile(std.testing.allocator, "one\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const dirty = s.at("/pane/{d}/dirty", .{n});
+ const ctl = s.at("/pane/{d}/ctl", .{n});
+ try s.expect(dirty, "0\n");
+ try s.write(s.at("/pane/{d}/body", .{n}), "two\n");
+ try s.expect(dirty, "1\n");
+ try s.write(ctl, "Undo");
+ try s.expect(dirty, "0\n");
+ try s.write(ctl, "Redo");
+ try s.expect(dirty, "1\n");
+}