summaryrefslogtreecommitdiff
path: root/test/behaviour/mouse.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/behaviour/mouse.zig')
-rw-r--r--test/behaviour/mouse.zig64
1 files changed, 64 insertions, 0 deletions
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");
+}