summaryrefslogtreecommitdiff
path: root/test/mode.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 17:35:06 -0300
committerGabriel Schneider <[email protected]>2026-10-30 17:35:06 -0300
commit6d8da8721141284cf33bb901168b26135893eb86 (patch)
tree791d63401d4e85fbca1d597a8ce0326e70efd545 /test/mode.zig
parentefd43a3a2cf03bb741366331158b368abf9ac583 (diff)
parentbf6810a8f9d6cc82050e7d9c0cfb06358301b574 (diff)
downloadpardes-6d8da8721141284cf33bb901168b26135893eb86.tar.gz
pardes-6d8da8721141284cf33bb901168b26135893eb86.zip
Merge latest upstream into the macOS branch for Zig 0.17
Retain the macOS branch history and local Acme selection color while adopting upstream's current core and platform changes. Pin Zig and ZLS to 0.17.0, and fetch the existing zstbi compatibility commit through upstream after its original fork was removed.
Diffstat (limited to 'test/mode.zig')
-rw-r--r--test/mode.zig63
1 files changed, 33 insertions, 30 deletions
diff --git a/test/mode.zig b/test/mode.zig
index cc36ac04..f49c434c 100644
--- a/test/mode.zig
+++ b/test/mode.zig
@@ -3,57 +3,60 @@ const pardes = @import("pardes");
const panes = pardes.panes;
const Pardes = pardes.Pardes;
-fn mode(p: *Pardes, id: usize, expected: pardes.Pane.Mode) !void {
+fn mode(p: *Pardes, id: usize, expected: panes.Text.Mode) !void {
try std.testing.expect(p.executeBuiltinLine(id, "Mode"));
- try std.testing.expectEqual(expected, p.panes[id].?.mode);
- try std.testing.expect(!p.panes[id].?.tag_edit);
+ try std.testing.expectEqual(expected, p.panes[id].?.body.mode);
+ try std.testing.expect(p.panes[id].?.focus == .body);
}
fn clickModeTag(p: *Pardes) !void {
const pane = p.panes[0].?;
- const text = try p.tagText(p.scratch.allocator(), pane);
+ const text = try pardes.tagline.tagText(p, p.scratch.allocator(), pane);
const col = std.mem.indexOf(u8, text, "Mode") orelse return error.MissingModeTag;
const rect = p.rects[0];
const row = if (p.settings.tag_bottom) rect.y + rect.h - pardes.BOX_H else rect.y;
for ([_]pardes.Mouse.Kind{ .press, .release }) |kind|
p.update(.{ .mouse = .{ .button = .left, .kind = kind, .col = rect.x + pardes.TAG_TEXT_INSET + @as(u16, @intCast(col)), .row = row } });
- try std.testing.expect(pane.tag_edit);
+ try std.testing.expect(pane.focus == .tag);
}
-fn customTag(pane: *pardes.Pane, text: []const u8) void {
- @memcpy(pane.tag_tail[0..text.len], text);
- pane.tag_tail_len = text.len;
- pane.tag_init = true;
+fn customTag(pane: *pardes.Pane, text: []const u8) !void {
+ if (pane.tag.own) |own| pane.gpa.free(own);
+ pane.tag.own = try pane.gpa.dupe(u8, text);
}
test "Mode cycles terminal modes and keeps legacy toggle and custom tags" {
- if (comptime !panes.Terminal.enabled) return error.SkipZigTest;
+ if (comptime !panes.terminal.enabled) return error.SkipZigTest;
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100 });
defer p.deinit();
p.presentation.enabled = false;
while (p.nextEffect()) |_| {}
const pane = p.panes[0].?;
- try std.testing.expectEqual(pardes.Pane.Mode.tty, pane.mode);
- try std.testing.expect(std.mem.indexOf(u8, try p.tagText(p.scratch.allocator(), pane), " Mode") != null);
+ try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode);
+ try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, p.scratch.allocator(), pane), " Mode") != null);
try mode(p, 0, .normal);
try mode(p, 0, .insert);
+ // A clicked tag is typed into; its execute key is a normal-mode key, as
+ // a body's is, and the body keeps its own mode meanwhile.
try clickModeTag(p);
- try std.testing.expectEqual(pardes.Pane.Mode.insert, pane.tag_mode);
+ try std.testing.expectEqual(panes.Text.Mode.insert, pane.tag.mode);
+ try std.testing.expectEqual(panes.Text.Mode.insert, pane.body.mode);
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
p.update(.{ .key = .{ .cp = pardes.Key.tab } });
- try std.testing.expectEqual(pardes.Pane.Mode.tty, pane.mode);
- try std.testing.expect(!pane.tag_edit);
+ try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode);
+ try std.testing.expect(pane.focus == .body);
while (p.nextEffect()) |effect| try std.testing.expect(effect != .write);
- customTag(pane, " Togglettymode Keep");
+ try customTag(pane, " Togglettymode Keep");
try mode(p, 0, .normal);
try mode(p, 0, .insert);
try std.testing.expect(p.executeBuiltinLine(0, "Togglettymode"));
- try std.testing.expectEqual(pardes.Pane.Mode.tty, pane.mode);
+ try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode);
p.update(.{ .key = .{ .cp = 'b', .ctrl = true } });
- try std.testing.expectEqual(pardes.Pane.Mode.normal, pane.mode);
+ try std.testing.expectEqual(panes.Text.Mode.normal, pane.body.mode);
p.update(.{ .key = .{ .cp = 'b', .ctrl = true } });
- try std.testing.expectEqual(pardes.Pane.Mode.tty, pane.mode);
- try std.testing.expectEqualStrings(" Togglettymode Keep", pane.tag_tail[0..pane.tag_tail_len]);
+ try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode);
+ try std.testing.expectEqualStrings(" Togglettymode Keep", pane.tag.own.?);
}
test "Mode from actual tag Exec preserves parked file and output insert transactions" {
@@ -64,26 +67,26 @@ test "Mode from actual tag Exec preserves parked file and output insert transact
p.presentation.enabled = false;
const pane = try p.setTestFile("ab\n");
if (output) pane.file.?.output = .{ .from = .search };
- try std.testing.expect(std.mem.indexOf(u8, try p.tagText(p.scratch.allocator(), pane), " Mode") == null);
- customTag(pane, " Mode");
+ try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, p.scratch.allocator(), pane), " Mode") == null);
+ try customTag(pane, " Mode");
try mode(p, 0, .insert);
p.update(.{ .key = .{ .cp = '界', .text = "界" } });
p.update(.{ .key = .{ .cp = 'x', .text = "x" } });
try std.testing.expectEqualStrings("界xab\n", pane.file.?.content);
try clickModeTag(p);
- try std.testing.expectEqual(pardes.Pane.Mode.insert, pane.tag_mode);
- if (normal_tag) pane.mode = .normal;
+ try std.testing.expectEqual(panes.Text.Mode.insert, pane.body.mode);
+ if (normal_tag) pane.tag.mode = .normal else p.update(.{ .key = .{ .cp = pardes.Key.escape } });
p.update(.{ .key = .{ .cp = pardes.Key.tab } });
- try std.testing.expectEqual(pardes.Pane.Mode.normal, pane.mode);
- try std.testing.expect(!pane.tag_edit);
- try std.testing.expect(pane.append_at == null);
+ try std.testing.expectEqual(panes.Text.Mode.normal, pane.body.mode);
+ try std.testing.expect(pane.focus == .body);
+ try std.testing.expect(!pane.body.restore_cursor);
p.update(.{ .key = .{ .cp = 'u' } });
try std.testing.expectEqualStrings("ab\n", pane.file.?.content);
p.update(.{ .key = .{ .cp = 'a' } });
p.update(.{ .key = .{ .cp = 'z', .text = "z" } });
- try std.testing.expect(pane.append_at != null);
+ try std.testing.expect(pane.body.restore_cursor);
try mode(p, 0, .normal);
- try std.testing.expect(pane.append_at == null);
+ try std.testing.expect(!pane.body.restore_cursor);
p.update(.{ .key = .{ .cp = 'u' } });
try std.testing.expectEqualStrings("ab\n", pane.file.?.content);
}
@@ -106,7 +109,7 @@ test "Mode leaves image and PDF document modes unchanged" {
const len = try tmp.dir.realPath(std.testing.io, &buffer);
const path = try std.fmt.allocPrint(std.testing.allocator, "{s}/mode.pdf", .{buffer[0..len]});
defer std.testing.allocator.free(path);
- const document = try panes.Pdf.openPane(p, 2, path, 1);
+ const document = try panes.Pdf.openPane(p, 2, path, 1, .last);
const page = document.pdf.?.page;
try mode(p, 2, .normal);
try std.testing.expectEqual(page, document.pdf.?.page);