1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
//! docs/typ/reference.typ, Flags and undo <flags>.
const std = @import("std");
const Session = @import("session").Session;
test "flags: dirty, mark and scroll read and write the state acme kept behind ctl verbs, 1 or 0" {
var s = try Session.initFile(std.testing.allocator, "one\ntwo\n");
defer s.deinit();
const n = try s.focused();
const dirty = s.at("/pane/{d}/dirty", .{n});
const mark = s.at("/pane/{d}/mark", .{n});
const scroll = s.at("/pane/{d}/scroll", .{n});
for ([_][]const u8{ dirty, mark, scroll }) |flag| {
try std.testing.expectEqual(@as(u64, 2), (try s.stat(flag)).size);
for ([_][]const u8{ "", "yes", "2", "0 1", "true" }) |bad| {
try std.testing.expectEqual(@as(u16, 22), try s.refused(flag, bad));
try std.testing.expectEqualStrings("bad flag: takes 1 or 0", s.said);
}
}
try s.expect(dirty, "0\n");
try s.expect(mark, "1\n");
try s.expect(scroll, "1\n");
// dirty as /index shows it.
try s.write(dirty, "1\n");
try s.expect(dirty, "1\n");
try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), s.at("{d} text 1 ", .{n})) != null);
try s.write(dirty, "0");
try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), s.at("{d} text 0 ", .{n})) != null);
try s.write(mark, "0");
try s.write(scroll, "0");
try s.expect(mark, "0\n");
try s.expect(scroll, "0\n");
try s.write(mark, "1");
try s.write(scroll, "1");
try s.expect(mark, "1\n");
try s.expect(scroll, "1\n");
// A terminal has no file, so its dirty flag is readable but not writable.
var t = try Session.initTerm(std.testing.allocator);
defer t.deinit();
const term_dirty = t.at("/pane/{d}/dirty", .{try t.focused()});
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");
}
|