summaryrefslogtreecommitdiff
path: root/test/behaviour
diff options
context:
space:
mode:
Diffstat (limited to 'test/behaviour')
-rw-r--r--test/behaviour/columns_and_tags.zig57
-rw-r--r--test/behaviour/mouse.zig64
2 files changed, 121 insertions, 0 deletions
diff --git a/test/behaviour/columns_and_tags.zig b/test/behaviour/columns_and_tags.zig
index d485ee6e..ac8e7034 100644
--- a/test/behaviour/columns_and_tags.zig
+++ b/test/behaviour/columns_and_tags.zig
@@ -233,3 +233,60 @@ test "columns-and-tags: a refused Delcol changes nothing: no pane, no focus" {
try s.expect("/focus", focus);
try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "unsaved ") != null);
}
+
+/// Column `i`'s x and width, from /layout.
+fn columnBox(s: *Session, i: usize) !struct { usize, usize } {
+ var lines = std.mem.tokenizeScalar(u8, try s.read("/layout"), '\n');
+ for (0..i) |_| _ = lines.next();
+ var fields = std.mem.tokenizeScalar(u8, lines.next().?, ' ');
+ _ = fields.next(); // serial
+ _ = fields.next(); // index
+ return .{ try std.fmt.parseInt(usize, fields.next().?, 10), try std.fmt.parseInt(usize, fields.next().?, 10) };
+}
+
+test "columns-and-tags: a column tag lights the word under the mouse, is clicked and swept into, typed at its caret, and scrolls from its column's edge" {
+ var s = try Session.initFile(std.testing.allocator, "untouched\n");
+ defer s.deinit();
+ const file = try s.focused();
+ try s.write("/ctl", "Newcol\n");
+ try s.write(s.at("/col/{d}/exec", .{try s.column(1)}), "New\n");
+ for (0..2) |i| {
+ const tag = s.at("/col/{d}/tag", .{try s.column(i)});
+ const left, const w = try columnBox(&s, i);
+ // Its text starts two cells into the column.
+ const x = left + 2;
+ const width = w - 2;
+ const plain = try s.bg(x, 1);
+ try s.write("/mousein", s.at("m {d} 1 0\n", .{x}));
+ const lit = try s.bg(x, 1);
+ try std.testing.expect(!std.mem.eql(u8, plain, lit));
+ try expectEqualStrings(plain, try s.bg(x + 4, 1)); // Tty, another word
+ // Pressed, the keyboard is on the tag, its caret where it was pressed.
+ try s.write("/mousein", s.at("m {d} 1 1\n", .{x}));
+ try s.expect("/focus", "");
+ try std.testing.expectEqual(.{ x, @as(usize, 1) }, (try s.cursor()).?);
+ // Swept over three cells: those three in the selection's colour.
+ try s.write("/mousein", s.at("m {d} 1 1\nm {d} 1 0\n", .{ x + 3, x + 3 }));
+ for (0..3) |k| try expectEqualStrings(lit, try s.bg(x + k, 1));
+ try std.testing.expect(!std.mem.eql(u8, lit, try s.bg(x + 3, 1)));
+ try s.keys("\u{F00D}Help ");
+ try std.testing.expect(std.mem.startsWith(u8, try s.read(tag), "Help New Tty"));
+ try std.testing.expectEqual(x + 5, (try s.cursor()).?[0]);
+ // A tag one short of its room: its caret at the end is drawn on the
+ // last cell, and one more letter scrolls the text, never the caret.
+ const as: [80]u8 = @splat('a');
+ const row = as[0 .. width - 1];
+ try s.replace(tag, row);
+ try s.keys("\u{F018}");
+ try std.testing.expectEqual(x + width - 1, (try s.cursor()).?[0]);
+ try std.testing.expect(std.mem.indexOf(u8, try s.screen(), row) != null);
+ try s.keys("b");
+ try std.testing.expectEqual(x + width - 1, (try s.cursor()).?[0]);
+ try std.testing.expect(std.mem.indexOf(u8, try s.screen(), s.at("{s}b", .{row[1..]})) != null);
+ try s.keys("\u{F00D}");
+ try std.testing.expectEqual(x, (try s.cursor()).?[0]);
+ try s.keys("\x1b\x1b");
+ try s.write("/mousein", "m 0 23 0\n");
+ }
+ try s.expect(s.at("/pane/{d}/body", .{file}), "untouched\n");
+}
diff --git a/test/behaviour/mouse.zig b/test/behaviour/mouse.zig
index 0abe15dc..aba0f2d5 100644
--- a/test/behaviour/mouse.zig
+++ b/test/behaviour/mouse.zig
@@ -131,3 +131,67 @@ test "mouse: a B1 sweep over several lines is a stream, as acme's, in a body and
try mouse(&s, "m {d} {d} 1\nm {d} {d} 1\nm {d} {d} 3\nm {d} {d} 0\n", .{ tx + 3, ty, lx + 1, ly, lx + 1, ly, lx + 1, ly });
try s.expect(tag, "/test.txt Save Tty Colok Edit");
}
+
+test "mouse: a click on either half of a wide character lands before it, in the text and on a tag's path, and the caret steps over it whole" {
+ var s = try Session.initFile(std.testing.allocator, "a界e\u{301}z\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const dot = s.at("/pane/{d}/dot", .{n});
+ const x, const y = try s.where("a界");
+ // 界 is two cells, bytes 1 to 4; é two runes, bytes 4 to 7.
+ for ([_]usize{ 1, 2 }) |into| {
+ try mouse(&s, "m {d} {d} 1\nm {d} {d} 0\n", .{ x + into, y, x + into, y });
+ try std.testing.expectEqual(.{ @as(u32, 1), @as(u32, 1) }, try s.range(dot));
+ }
+ try mouse(&s, "m {d} {d} 1\nm {d} {d} 0\n", .{ x + 4, y, x + 4, y });
+ try std.testing.expectEqual(.{ @as(u32, 7), @as(u32, 7) }, try s.range(dot));
+ // On the tag's path, the second half of 界 drafts the name with its
+ // caret before it; Right steps a whole grapheme, two cells then one.
+ try s.write(s.at("/pane/{d}/name", .{n}), "/界e\u{301}.txt\n");
+ const px, const py = try s.where("/界");
+ try mouse(&s, "m {d} {d} 1\nm {d} {d} 0\n", .{ px + 2, py, px + 2, py });
+ try std.testing.expectEqual(.{ px + 1, py }, (try s.cursor()).?);
+ try s.keys("\u{F012}");
+ try std.testing.expectEqual(.{ px + 3, py }, (try s.cursor()).?);
+ try s.keys("\u{F012}");
+ try std.testing.expectEqual(.{ px + 4, py }, (try s.cursor()).?);
+ try s.keys("\x1b\x1b");
+ try s.expect(s.at("/pane/{d}/name", .{n}), "/界e\u{301}.txt\n");
+ // Typed past the tag's words, a two-byte λ goes in and one backspace
+ // takes it out whole.
+ const tag = try s.read(s.at("/pane/{d}/tag", .{n}));
+ try s.click("Collapse Del", "Collapse Del".len + 1, 1);
+ const caret = (try s.cursor()).?;
+ try s.keys("λ");
+ try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/tag", .{n})), "λ"));
+ try std.testing.expectEqual(.{ caret[0] + 1, caret[1] }, (try s.cursor()).?);
+ try s.keys("\x08");
+ try std.testing.expectEqual(caret, (try s.cursor()).?);
+ try s.expect(s.at("/pane/{d}/tag", .{n}), tag);
+}
+
+test "mouse: a sweep pressed on the line numbers takes only the text: drawn while held and once let go, looked for by a click in it, cut by a chord" {
+ var s = try Session.initFile(std.testing.allocator, "alpha beta\ngamma delta\nalpha beta\ngamma\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const x, const y = try s.where("alpha");
+ const plain = try s.bg(x - 2, y);
+ try mouse(&s, "m {d} {d} 1\nm {d} {d} 1\n", .{ x - 2, y, x + 4, y + 1 });
+ for (0..2) |released| {
+ // The number pressed on, and the room after the line, stay unlit.
+ try std.testing.expectEqualStrings(plain, try s.bg(x - 2, y));
+ try std.testing.expectEqualStrings(plain, try s.bg(x - 2, y + 1));
+ const lit = try s.bg(x, y);
+ try std.testing.expect(!std.mem.eql(u8, plain, lit));
+ try std.testing.expectEqualStrings(lit, try s.bg(x + 4, y + 1));
+ try std.testing.expectEqualStrings(plain, try s.bg(x + 5, y + 1));
+ if (released == 0) try mouse(&s, "m {d} {d} 0\n", .{ x + 4, y + 1 });
+ }
+ // A Look clicked in it looks for the text swept: its next place, the
+ // third and fourth lines.
+ try mouse(&s, "m {d} {d} 4\nm {d} {d} 0\n", .{ x + 1, y, x + 1, y });
+ try std.testing.expectEqual(.{ @as(u32, 23), @as(u32, 39) }, try s.range(s.at("/pane/{d}/dot", .{n})));
+ // A chord cuts what was swept: the text, no number.
+ try mouse(&s, "m {d} {d} 1\nm {d} {d} 1\nm {d} {d} 3\nm {d} {d} 1\nm {d} {d} 0\n", .{ x - 2, y, x + 4, y + 1, x + 4, y + 1, x + 4, y + 1, x + 4, y + 1 });
+ try s.expect(s.at("/pane/{d}/body", .{n}), " delta\nalpha beta\ngamma\n");
+}