-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(tui): extract function
execute_command
- Loading branch information
Showing
2 changed files
with
38 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::app::{App, MainWidget}; | ||
|
||
pub fn execute_command(command: &str, app: &mut App) -> Result<(), String> { | ||
match command { | ||
"quit" => app.shutdown(), | ||
"listAll" => app.main_widget = MainWidget::EntryTypes, | ||
_ => return Err(format!("Unknown command: {}", command)), | ||
} | ||
Ok(()) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::execute_command; | ||
use crate::app::App; | ||
|
||
#[test] | ||
fn test_command_quit() { | ||
let mut app = App::new(); | ||
|
||
assert!(app.running()); | ||
execute_command("quit", &mut app).unwrap(); | ||
assert!(!app.running()); | ||
} | ||
|
||
#[test] | ||
fn test_unknown_command() { | ||
let mut app = App::new(); | ||
|
||
let result = execute_command("nonexistent", &mut app); | ||
assert_eq!(result, Err("Unknown command: nonexistent".to_string())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters