diff options
Diffstat (limited to 'test/panes.zig')
| -rw-r--r-- | test/panes.zig | 60 |
1 files changed, 49 insertions, 11 deletions
diff --git a/test/panes.zig b/test/panes.zig index 40b4b6ba..96819728 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -595,7 +595,8 @@ const BodyHitTests = struct { p.update(.{ .mouse = mouse(layer, last - 1, prefix + 11, .press) }); // Release at a different source row without an intermediate drag event. p.update(.{ .mouse = mouse(layer, last, prefix + 14, .release) }); - try std.testing.expectEqualStrings("body\nbody", pardes.test_api.heldSelection(p, 0).?); + // A stream: the last row from its start, indentation and all. + try std.testing.expect(std.mem.endsWith(u8, pardes.test_api.heldSelection(p, 0).?, "// body") and std.mem.startsWith(u8, pardes.test_api.heldSelection(p, 0).?, "body\n")); p.update(.{ .mouse = mouse(layer, last, 10, .press) }); p.update(.{ .mouse = mouse(layer, last, 10, .release) }); try std.testing.expectEqual(expected, pane.body.cur_row); @@ -873,7 +874,7 @@ const TtySelectionTests = struct { try noChildInput(p); } - test "tty selection preserves exact rectangle through yank clipboard and mode changes" { + test "tty selection preserves its exact stream through yank clipboard and mode changes" { if (comptime !panes.Terminal.enabled) return error.SkipZigTest; for ([_]bool{ false, true }) |prompt| { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 12 }); @@ -894,7 +895,7 @@ const TtySelectionTests = struct { const x = rect.x + config.GUTTER; const y = p.bodyTop(pane, rect); JumpSelectionTests.drag(p, x + @as(u16, if (prompt) 0 else 1), y, x + 3, y + @as(u16, if (prompt) 0 else 1)); - const expected = if (prompt) "$ ab" else "lph\nrav"; + const expected = if (prompt) "$ ab" else "lpha\nbrav"; try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode); try std.testing.expectEqualStrings(expected, pardes.test_api.heldSelection(p, 0).?); try std.testing.expectEqualStrings(expected, p.registers.text(p.gpa, '"') orelse return error.MissingAutomaticTtyYank); @@ -907,9 +908,13 @@ const TtySelectionTests = struct { try std.testing.expectEqual(panes.Text.Mode.normal, pane.body.mode); const normal = try p.render(frame.allocator()); if (!prompt) { - const selection_bg: pardes.Color = .{ .rgb = p.theme().sel_bg }; - try std.testing.expect(!std.meta.eql(selection_bg, normal.at(x + 4, y).style.bg)); - try std.testing.expect(!std.meta.eql(selection_bg, normal.at(x, y + 1).style.bg)); + // A stream: the first row to its edge, the last from its + // start; (x + 1, y) is surely in it, whatever its tint. + const selected = normal.at(x + 1, y).style.bg; + try std.testing.expect(std.meta.eql(selected, normal.at(x + 4, y).style.bg)); + try std.testing.expect(std.meta.eql(selected, normal.at(x, y + 1).style.bg)); + try std.testing.expect(!std.meta.eql(selected, normal.at(x + 4, y + 1).style.bg)); + try std.testing.expect(!std.meta.eql(selected, normal.at(x, y).style.bg)); } try std.testing.expectEqualStrings(expected, pardes.test_api.heldSelection(p, 0).?); p.update(.{ .key = .{ .cp = 'y' } }); @@ -956,7 +961,7 @@ const TtySelectionTests = struct { const sx = source.x + config.GUTTER; const sy = if (p.settings.tag_bottom) source.y else source.y + pardes.BOX_H; JumpSelectionTests.drag(p, sx + 1, sy, sx + 3, sy + 1); - try std.testing.expectEqualStrings("lph\nrav", p.registers.text(p.gpa, '"') orelse return error.MissingAutomaticTtyYank); + try std.testing.expectEqualStrings("lpha\nbrav", p.registers.text(p.gpa, '"') orelse return error.MissingAutomaticTtyYank); try noChildInput(p); const target = p.rects[1]; @@ -976,13 +981,13 @@ const TtySelectionTests = struct { } const expected = try std.fmt.allocPrint(p.gpa, "{s}{s}", .{ if (reports_mouse) "\x1b[<0;3;1M\x1b[<0;3;1m" else "", - if (bracketed) "\x1b[200~lph\nrav\x1b[201~" else "lph\rrav", + if (bracketed) "\x1b[200~lpha\nbrav\x1b[201~" else "lpha\rbrav", }); defer p.gpa.free(expected); try std.testing.expectEqualStrings(expected, written.written()); try std.testing.expectEqual(panes.Text.Mode.tty, p.panes[0].?.body.mode); try std.testing.expectEqual(panes.Text.Mode.tty, p.panes[1].?.body.mode); - try std.testing.expectEqualStrings("lph\nrav", pardes.test_api.heldSelection(p, 0).?); + try std.testing.expectEqualStrings("lpha\nbrav", pardes.test_api.heldSelection(p, 0).?); } } } @@ -1253,9 +1258,42 @@ const JumpSelectionTests = struct { try std.testing.expectEqual(@as(i32, 0), pane.body.cur_col); } - test "jump selection clears copied rectangles in both history directions" { + test "a B1 sweep over several lines is a stream, as acme's, in a body and a tag" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 12 }); + defer p.deinit(); + const pane = try p.setTestFile("alpha\nbravo\ncharlie\n"); + var frame = std.heap.ArenaAllocator.init(p.gpa); + defer frame.deinit(); + _ = try p.render(frame.allocator()); + const rect = p.rects[0]; + const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane); + const y = p.bodyTop(pane, rect); + // From the press to the end of its line, the line between whole, the + // last from its start: no line numbers, no rectangle. + drag(p, x + 2, y, x + 1, y + 2); + try std.testing.expectEqualStrings("pha\nbravo\nch", pardes.test_api.heldSelection(p, 0).?); + // Upward, the same text. + drag(p, x + 1, y + 2, x + 2, y); + try std.testing.expectEqualStrings("pha\nbravo\nch", pardes.test_api.heldSelection(p, 0).?); + // A tag of several rows sweeps the same way. + if (pane.tag.own) |own| p.gpa.free(own); + pane.tag.own = try p.gpa.dupe(u8, "Save Del\nLook Edit"); + p.sync(); + _ = try p.render(frame.allocator()); + p.sync(); + try std.testing.expectEqual(@as(u16, 2), pane.tag_rows); + const sl: panes.Pane.Sel = .{ .state = .done, .r0 = 0, .c0 = 3, .r1 = 1, .c1 = 1 }; + const text = try pardes.edit.paneText(p, pane); + const swept = try pardes.edit.selectionText(p, pane, sl); + const first_line = text[0 .. std.mem.indexOfScalar(u8, text, '\n') orelse text.len]; + const second = std.mem.sliceTo(text[first_line.len + 1 ..], '\n'); + const want = try std.fmt.allocPrint(frame.allocator(), "{s}\n{s}", .{ first_line[3..], second[0..@min(2, second.len)] }); + try std.testing.expectEqualStrings(want, swept); + } + + test "jump selection clears copied sweeps in both history directions" { for ([_]bool{ false, true }) |reverse| - try exercise("alpha\nbravo\n", false, reverse, 1, 3, "lph\nrav"); + try exercise("alpha\nbravo\n", false, reverse, 1, 3, "lpha\nbrav"); } test "jump selection clears wrapped Unicode and tab rectangles" { |
