terminal2: selectionString with rect

This commit is contained in:
Mitchell Hashimoto
2024-03-07 13:40:07 -08:00
parent 016db43867
commit 0b2b56506a
2 changed files with 101 additions and 0 deletions

View File

@ -5847,6 +5847,7 @@ test "Screen: selectionString with zero width joiner" {
}
}
// X
test "Screen: selectionString, rectangle, basic" {
const testing = std.testing;
const alloc = testing.allocator;
@ -5877,6 +5878,7 @@ test "Screen: selectionString, rectangle, basic" {
try testing.expectEqualStrings(expected, contents);
}
// X
test "Screen: selectionString, rectangle, w/EOL" {
const testing = std.testing;
const alloc = testing.allocator;
@ -5909,6 +5911,7 @@ test "Screen: selectionString, rectangle, w/EOL" {
try testing.expectEqualStrings(expected, contents);
}
// X
test "Screen: selectionString, rectangle, more complex w/breaks" {
const testing = std.testing;
const alloc = testing.allocator;

View File

@ -5399,3 +5399,101 @@ test "Screen: selectionString with zero width joiner" {
try testing.expectEqualStrings(expected, contents);
}
}
test "Screen: selectionString, rectangle, basic" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 30, 5, 0);
defer s.deinit();
const str =
\\Lorem ipsum dolor
\\sit amet, consectetur
\\adipiscing elit, sed do
\\eiusmod tempor incididunt
\\ut labore et dolore
;
const sel = Selection.init(
s.pages.pin(.{ .screen = .{ .x = 2, .y = 1 } }).?,
s.pages.pin(.{ .screen = .{ .x = 6, .y = 3 } }).?,
true,
);
const expected =
\\t ame
\\ipisc
\\usmod
;
try s.testWriteString(str);
const contents = try s.selectionString(alloc, sel, true);
defer alloc.free(contents);
try testing.expectEqualStrings(expected, contents);
}
test "Screen: selectionString, rectangle, w/EOL" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 30, 5, 0);
defer s.deinit();
const str =
\\Lorem ipsum dolor
\\sit amet, consectetur
\\adipiscing elit, sed do
\\eiusmod tempor incididunt
\\ut labore et dolore
;
const sel = Selection.init(
s.pages.pin(.{ .screen = .{ .x = 12, .y = 0 } }).?,
s.pages.pin(.{ .screen = .{ .x = 26, .y = 4 } }).?,
true,
);
const expected =
\\dolor
\\nsectetur
\\lit, sed do
\\or incididunt
\\ dolore
;
try s.testWriteString(str);
const contents = try s.selectionString(alloc, sel, true);
defer alloc.free(contents);
try testing.expectEqualStrings(expected, contents);
}
// test "Screen: selectionString, rectangle, more complex w/breaks" {
// const testing = std.testing;
// const alloc = testing.allocator;
//
// var s = try init(alloc, 30, 8, 0);
// defer s.deinit();
// const str =
// \\Lorem ipsum dolor
// \\sit amet, consectetur
// \\adipiscing elit, sed do
// \\eiusmod tempor incididunt
// \\ut labore et dolore
// \\
// \\magna aliqua. Ut enim
// \\ad minim veniam, quis
// ;
// const sel = Selection.init(
// s.pages.pin(.{ .screen = .{ .x = 11, .y = 2 } }).?,
// s.pages.pin(.{ .screen = .{ .x = 26, .y = 7 } }).?,
// true,
// );
// const expected =
// \\elit, sed do
// \\por incididunt
// \\t dolore
// \\
// \\a. Ut enim
// \\niam, quis
// ;
// try s.testWriteString(str);
//
// const contents = try s.selectionString(alloc, sel, true);
// defer alloc.free(contents);
// try testing.expectEqualStrings(expected, contents);
// }