gyscos / cursive

A Text User Interface library for the Rust programming language
MIT License
4.17k stars 240 forks source link

Tests support control chars widths 0 or 1 #789

Closed correabuscar closed 1 month ago

correabuscar commented 1 month ago

closes #788

fixed a couple of nits too

gyscos commented 1 month ago

Thanks for the PR!

I just pushed a change that only marks some backends "persistent". The puppet backend defaults to non-persistent. In the print buffer, we now only skip similar chars on persistent backends. What this means is that for the pupper backend, we will flush the entire screen and not just the diffs, so we shouldn't have to use the lowercase a workaround.

correabuscar commented 1 month ago

In the print buffer, we now only skip similar chars on persistent backends.

that commit is not pushed yet? I only see this one: https://github.com/gyscos/cursive/commit/2a7b368441fbb3b742845dbd84f9c77162556d14

therefore is_persistent isn't used by anything:

$ grep -nrIFw is_persistent
cursive-core/src/backend.rs:88:    fn is_persistent(&self) -> bool {
cursive/src/backends/curses/pan.rs:380:    fn is_persistent(&self) -> bool {
cursive/src/backends/curses/n.rs:325:    fn is_persistent(&self) -> bool {
cursive/src/backends/crossterm.rs:330:    fn is_persistent(&self) -> bool {
cursive/src/backends/termion.rs:270:    fn is_persistent(&self) -> bool {

I tested via:

$ cargo test --example select_test -- --nocapture
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.08s
     Running unittests examples/select_test.rs (target/x86_64-unknown-linux-gnu/debug/examples/select_test-d45f2e1e4022a737)

running 3 tests
captured piece:
x01234567890123456789012345678901234567890123456789012345678901234567890123456789x
0                                                                                |
1                                                                                |
2                           ┌┤ Where are you from? ├┐                            |
3                           │      Abidjan       ▒  │                            |
4                           │     Abu Dhabi      |  │                            |
5                           │       Abuja        |  │                            |
6                           │       Accra        |  │                            |
7                           │     Adamstown      |  │                            |
8                           │    Addis Ababa     |  │                            |
9                           │      Algiers       |  │                            |
0                           │       Alofi        |  │                            |
1                           │       Amman        |  │                            |
2                           │     Amsterdam      |  │                            |
3                           └───────────────────────┘                            |
4                                                                                |
5                                                                                |
x--------------------------------------------------------------------------------x

captured piece:
x01234567890123456789012345678901234567890123456789012345678901234567890123456789x
0................................................................................|
1................................................................................|
2................................................................................|
3.............................  short nul 1str  .|...............................|
4.................................  1thru8 ......................................|
5...............................tabandnewline....................................|
6..................................bthru15.......................................|
7................................. 16thru1F......................................|
8................................   7Fonly  .....................................|
9..................................80thru89......................................|
0..................................8.thru93......................................|
1..................................94thru9D......................................|
2.............................     9Ethru9F     .▒...............................|
3................................................................................|
4................................................................................|
5................................................................................|
x--------------------------------------------------------------------------------x

captured piece:
x01234567890123456789012345678901234567890123456789012345678901234567890123456789x
0................................................................................|
1................................................................................|
2...........................                         ............................|
3...........................                          ...........................|
4...........................                          ...........................|
5.........................┌────────────────────────────┐.........................|
6.........................│ Abu.Dhabi is a.great.city! │ ........................|
7.........................│  .....         ...... ..   │ ........................|
8.........................│  ....     .     ....<Quit> │ ........................|
9.........................└────────────────────────────┘ ........................|
0..........................                          .   ........................|
1...........................                          ...........................|
2...........................                          ...........................|
3...........................                          ...........................|
4............................                         ...........................|
5................................................................................|
x--------------------------------------------------------------------------------x

test tests::displays ... ok
test tests::interacts ... ok
thread 'tests::control_chars_including_nul_when_on_screen' panicked at cursive/examples/select_test.rs:229:13:
assertion `left == right` failed: control chars \x8A thru \x93 should've been deleted from output
  left: 0
 right: 1
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a70b2ae57713ed0e7411c059d582ab382fc4166a/library/std/src/panicking.rs:652:5
   1: core::panicking::panic_fmt
             at /rustc/a70b2ae57713ed0e7411c059d582ab382fc4166a/library/core/src/panicking.rs:72:14
   2: core::panicking::assert_failed_inner
             at /rustc/a70b2ae57713ed0e7411c059d582ab382fc4166a/library/core/src/panicking.rs:403:23
   3: core::panicking::assert_failed
             at /rustc/a70b2ae57713ed0e7411c059d582ab382fc4166a/library/core/src/panicking.rs:363:5
   4: select_test::tests::control_chars_including_nul_when_on_screen
             at ./examples/select_test.rs:229:13
   5: select_test::tests::control_chars_including_nul_when_on_screen::{{closure}}
             at ./examples/select_test.rs:129:52
   6: core::ops::function::FnOnce::call_once
             at /rustc/a70b2ae57713ed0e7411c059d582ab382fc4166a/library/core/src/ops/function.rs:250:5
   7: core::ops::function::FnOnce::call_once
             at /rustc/a70b2ae57713ed0e7411c059d582ab382fc4166a/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
test tests::control_chars_including_nul_when_on_screen ... FAILED

failures:

failures:
    tests::control_chars_including_nul_when_on_screen

test result: FAILED. 2 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.04s

error: test failed, to rerun pass `-p cursive --example select_test`

basically if you see lots of dots in the last 2 screens, it means it didn't change what was there before, it seems.

gyscos commented 1 month ago

Whoops indeed the last commit wasn't pushed :-'

correabuscar commented 1 month ago

I'll update in a sec, testing and such :) Done.