Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@aljazerzen
Copy link
Contributor

When changing the interface, tests had to be updated using following error messages to find the mismatch:

---- ui::draw_blocks::tests::test_draw_blocks_whole_layout_long_name stdout ----
thread 'ui::draw_blocks::tests::test_draw_blocks_whole_layout_long_name' panicked at src/ui/draw_blocks.rs:3192:17:
assertion `left == right` failed
  left: "n"
 right: " "

I've now added insta, that defines tests like this:

        assert_snapshot!(
            text, @r#"
            ╭──────────╮
            │▶ pause   │
            │  restart │
            │  stop    │
            │  remove  │
            ╰──────────╯
            "#
        );

... and produces error messages like this:

---- ui::draw_blocks::tests::test_draw_blocks_commands_panel_selected_color stdout ----
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Snapshot Summary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Snapshot: draw_blocks_commands_panel_selected_color
Source: src/ui/draw_blocks.rs:1274
─────────────────────────────────────────────────────────────────────────────────────────────────────
Expression: text
─────────────────────────────────────────────────────────────────────────────────────────────────────
-old snapshot
+new results
────────────┬────────────────────────────────────────────────────────────────────────────────────────
    0     0 │ ╭──────────╮
    1     1 │ │▶ pause   │
    2     2 │ │  restart │
    3     3 │ │  stop    │
    4       │-│  remove  │
          4 │+│  delete  │
    5     5 │ ╰──────────╯
────────────┴────────────────────────────────────────────────────────────────────────────────────────
To update snapshots run `cargo insta review`
Stopped on the first failure. Run `cargo insta test` to run all snapshots.

@mrjackwills
Copy link
Owner

Still need to get my head around this, will have a play around with it all

@aljazerzen
Copy link
Contributor Author

I have converted only a few of the tests, to see if you want to go ahead with it first.

@mrjackwills
Copy link
Owner

Finally got round to switching to Insta, although your colour assertions look superior to the current, new, system, so might have to implement that into all the tests

@aljazerzen
Copy link
Contributor Author

Oh, damn, I totally forgot that I ever done this.

The color assertions do look cool. Do you want me to rebase this pr to current master?

@mrjackwills
Copy link
Owner

If you can be bothered to, but no rush or obligation

@aljazerzen
Copy link
Contributor Author

There you go. I've only ported the code for "get color from buffer" and one test case.

Now you can port any test case where you deem colors/boldness to be important.

@aljazerzen
Copy link
Contributor Author

Oh, I had to add unicode_width dev dep, to deal with cells that are rendered in multiple columns. This is already a dependency of ratatui (and is used in impl Debug for Buffer).

@aljazerzen aljazerzen changed the title refactor: use insta for tests snapshots refactor: test colors and boldness with insta Apr 23, 2025
@aljazerzen
Copy link
Contributor Author

I'm now unsubscribing from this issue, mention me if you want me to see it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants