Skip to content

Commit a4fa980

Browse files
nikomatsakisGemini
andcommitted
feat: Add initial unit tests for the application
This commit introduces the first set of unit tests for the application. It includes tests for character entry and rendering of the initial empty application state. Co-authored-by: Gemini <[email protected]>
1 parent 465dc8e commit a4fa980

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ crossterm = { version = "0.28", features = ["event-stream"] }
99
color-eyre = "0.6"
1010
tokio = { version = "1", features = ["full"] }
1111
tokio-stream = "0.1"
12+
13+
[dev-dependencies]
14+
expect-test = "1.4"

src/app_tests.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use super::*;
2+
use expect_test::{Expect, expect};
3+
use ratatui::{Terminal, backend::TestBackend};
4+
5+
#[test]
6+
fn test_enter_char() {
7+
let mut app = App::new();
8+
app.enter_char('a');
9+
assert_eq!(app.editor_buffer, "a");
10+
assert_eq!(app.editor_cursor, 1);
11+
}
12+
13+
fn check(app: &App, expected: Expect) {
14+
let backend = TestBackend::new(50, 10);
15+
let mut terminal = Terminal::new(backend).unwrap();
16+
terminal.draw(|frame| app.render(frame)).unwrap();
17+
expected.assert_eq(&terminal.backend().to_string());
18+
}
19+
20+
#[test]
21+
fn test_render_empty_app() {
22+
let app = App::new();
23+
check(
24+
&app,
25+
expect![[r#"
26+
"┌Messages────────────────────────────────────────┐"
27+
"│ │"
28+
"│ │"
29+
"│ │"
30+
"│ │"
31+
"│ │"
32+
"└────────────────────────────────────────────────┘"
33+
"┌Editor──────────────────────────────────────────┐"
34+
"│ │"
35+
"└────────────────────────────────────────────────┘"
36+
"#]],
37+
);
38+
}

src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,6 @@ impl App {
296296
}
297297
}
298298
}
299+
300+
#[cfg(test)]
301+
mod app_tests;

0 commit comments

Comments
 (0)