summaryrefslogtreecommitdiff
path: root/test/behaviour/keys.zig
blob: 3d6fdf314febace3964eba0c9ba4f3186304ae03 (plain) (blame)
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
//! docs/typ/guide.typ, Keys <keys>.
const std = @import("std");
const Session = @import("session").Session;

test "keys: a PDF shown as text turns pages for the moving keys, counted, and the editing keys do nothing" {
    var s = try Session.initFile(std.testing.allocator, "x\n");
    defer s.deinit();
    const n = try s.lookFile("docs/design.pdf");
    const pages = (try s.pdfPage(n))[1];
    try std.testing.expect(pages > 3);
    // j k, Ctrl-d Ctrl-u, Ctrl-f Ctrl-b: a page each, counted.
    for ([_][]const u8{ "2j", "2k", "2\x04", "2\x15", "2\x06", "2\x02" }, 0..) |keys, i| {
        try s.keys(keys);
        try std.testing.expectEqual(@as(u32, if (i % 2 == 0) 3 else 1), (try s.pdfPage(n))[0]);
    }
    for ([_]struct { []const u8, u32 }{ .{ "ge", pages }, .{ "gg", 1 }, .{ "3gg", 3 }, .{ "2G", 2 } }) |step| {
        try s.keys(step[0]);
        try std.testing.expectEqual(step[1], (try s.pdfPage(n))[0]);
    }
    // Consumed, with their count: the page stays, no selection begins, and
    // the next j is one page.
    try s.keys("4dv|");
    try std.testing.expectEqual(@as(u32, 2), (try s.pdfPage(n))[0]);
    try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/ctl", .{n})), " mode:normal "));
    try s.keys("j");
    try std.testing.expectEqual(@as(u32, 3), (try s.pdfPage(n))[0]);
}