()
| 1528 | |
| 1529 | #[test] |
| 1530 | fn test_horizontal_scrolling() { |
| 1531 | let mut cb = MockConsole::default(); |
| 1532 | cb.set_size_chars(yx(10, 40)); |
| 1533 | let mut ob = OutputBuilder::new(yx(10, 40)); |
| 1534 | ob = ob.refresh(linecol(0, 0), &["ab", "", "xyz"], yx(0, 0)); |
| 1535 | |
| 1536 | cb.add_input_keys(&[Key::ArrowDown]); |
| 1537 | ob = ob.quick_refresh(linecol(1, 0), yx(1, 0)); |
| 1538 | |
| 1539 | // Insert characters until the screen's right boundary. |
| 1540 | for (col, ch) in "123456789012345678901234567890123456789".chars().enumerate() { |
| 1541 | cb.add_input_keys(&[Key::Char(ch)]); |
| 1542 | ob = ob.set_dirty(); |
| 1543 | let mut buf = [0u8; 4]; |
| 1544 | ob = ob.add(CapturedOut::Write(ch.encode_utf8(&mut buf).to_string())); |
| 1545 | ob = ob.quick_refresh(linecol(1, col + 1), yx(1, u16::try_from(col + 1).unwrap())); |
| 1546 | } |
| 1547 | |
| 1548 | // Push the insertion line over the right boundary and test that surrounding lines scroll as |
| 1549 | // well. |
| 1550 | cb.add_input_keys(&[Key::Char('A')]); |
| 1551 | ob = ob.refresh( |
| 1552 | linecol(1, 40), |
| 1553 | &["b", "23456789012345678901234567890123456789A", "yz"], |
| 1554 | yx(1, 39), |
| 1555 | ); |
| 1556 | cb.add_input_keys(&[Key::Char('B')]); |
| 1557 | ob = ob.refresh( |
| 1558 | linecol(1, 41), |
| 1559 | &["", "3456789012345678901234567890123456789AB", "z"], |
| 1560 | yx(1, 39), |
| 1561 | ); |
| 1562 | cb.add_input_keys(&[Key::Char('C')]); |
| 1563 | ob = ob.refresh( |
| 1564 | linecol(1, 42), |
| 1565 | &["", "456789012345678901234567890123456789ABC", ""], |
| 1566 | yx(1, 39), |
| 1567 | ); |
| 1568 | |
| 1569 | // Move back a few characters, without pushing over the left boundary, and then insert two |
| 1570 | // characters: one will cause the insertion line to fill up the empty space left by the |
| 1571 | // cursor and the other will cause the view of the insertion line to be truncated on the |
| 1572 | // right side. |
| 1573 | for (file_col, cursor_col) in &[(41, 38), (40, 37), (39, 36)] { |
| 1574 | cb.add_input_keys(&[Key::ArrowLeft]); |
| 1575 | ob = ob.quick_refresh(linecol(1, *file_col), yx(1, *cursor_col)); |
| 1576 | } |
| 1577 | cb.add_input_keys(&[Key::Char('D')]); |
| 1578 | ob = ob.refresh_line(linecol(1, 40), "456789012345678901234567890123456789DABC", yx(1, 37)); |
| 1579 | cb.add_input_keys(&[Key::Char('E')]); |
| 1580 | ob = ob.refresh_line(linecol(1, 41), "456789012345678901234567890123456789DEAB", yx(1, 38)); |
| 1581 | |
| 1582 | // Delete a few characters to restore the overflow part of the insertion line. |
| 1583 | cb.add_input_keys(&[Key::Backspace]); |
| 1584 | ob = ob.refresh_line(linecol(1, 40), "456789012345678901234567890123456789DABC", yx(1, 37)); |
| 1585 | cb.add_input_keys(&[Key::Backspace]); |
| 1586 | ob = ob.refresh_line(linecol(1, 39), "456789012345678901234567890123456789ABC", yx(1, 36)); |
| 1587 | cb.add_input_keys(&[Key::Backspace]); |
nothing calls this directly
no test coverage detected