summaryrefslogtreecommitdiff
path: root/tests/resize_failure_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/resize_failure_test.c')
-rw-r--r--tests/resize_failure_test.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/resize_failure_test.c b/tests/resize_failure_test.c
index 5d7e63c..fbfa38d 100644
--- a/tests/resize_failure_test.c
+++ b/tests/resize_failure_test.c
@@ -146,6 +146,57 @@ int main(void)
assert(tt_cols(term) == 10);
term_free(term);
+ /* A failed same-width height shrink must not scroll rows into history or
+ * move the cursor. The same resize must succeed when allocation recovers. */
+ term = tt_new(8, 4);
+ assert(term);
+ const char four_rows[] = "A\r\nB\r\nC\r\nD";
+ tt_write(term, four_rows, sizeof four_rows - 1);
+ assert(tt_cursor_y(term) == 3);
+ assert(tt_history(term) == 0);
+
+ fail_next_calloc = true;
+ resized = tt_resize(term, 8, 2);
+ assert(!fail_next_calloc);
+ assert(!resized);
+ assert(tt_cols(term) == 8 && tt_rows(term) == 4);
+ assert(tt_cell(term, 0, 0)->text == 'A');
+ assert(tt_cell(term, 0, 1)->text == 'B');
+ assert(tt_cell(term, 0, 2)->text == 'C');
+ assert(tt_cell(term, 0, 3)->text == 'D');
+ assert(tt_cursor_y(term) == 3);
+ assert(tt_history(term) == 0);
+
+ resized = tt_resize(term, 8, 2);
+ assert(resized);
+ assert(tt_cols(term) == 8 && tt_rows(term) == 2);
+ assert(tt_cell(term, 0, 0)->text == 'C');
+ assert(tt_cell(term, 0, 1)->text == 'D');
+ assert(tt_cursor_y(term) == 1);
+ assert(tt_history(term) == 2);
+ term_free(term);
+
+ /* The alternate screen uses the same allocation-before-scroll path. */
+ term = tt_new(8, 4);
+ assert(term);
+ tt_write(term, "\033[?1049h", 8);
+ tt_write(term, four_rows, sizeof four_rows - 1);
+ assert(term_modes(term).alternate);
+ assert(tt_cursor_y(term) == 3);
+ fail_next_calloc = true;
+ resized = tt_resize(term, 8, 2);
+ assert(!fail_next_calloc);
+ assert(!resized);
+ assert(tt_rows(term) == 4 && tt_cursor_y(term) == 3);
+ assert(tt_cell(term, 0, 0)->text == 'A');
+ assert(tt_cell(term, 0, 3)->text == 'D');
+ resized = tt_resize(term, 8, 2);
+ assert(resized);
+ assert(tt_rows(term) == 2 && tt_cursor_y(term) == 1);
+ assert(tt_cell(term, 0, 0)->text == 'C');
+ assert(tt_cell(term, 0, 1)->text == 'D');
+ term_free(term);
+
puts("lazy screen allocation failures preserve observable terminal state");
return 0;
#endif