From d4d6fd28eb9ab8a2608ca90bcdaa8563389b8bce Mon Sep 17 00:00:00 2001 From: extrawurst <776816+extrawurst@users.noreply.github.com> Date: Wed, 15 Feb 2023 00:20:45 +0000 Subject: [PATCH] Unittest keylist (#1545) * fix warning * add unittest to keylist --- Cargo.lock | 1 + Cargo.toml | 1 + src/components/status_tree.rs | 2 +- src/keys/key_list.rs | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 1a9c4bba..c016c31c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -786,6 +786,7 @@ dependencies = [ "serde", "simplelog", "syntect", + "tempfile", "textwrap", "tui", "unicode-segmentation", diff --git a/Cargo.toml b/Cargo.toml index 73ff2fa6..0d2253d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,6 +61,7 @@ pprof = { version = "0.11", features = ["flamegraph"], optional = true } [dev-dependencies] pretty_assertions = "1.3" +tempfile = "3.2" [badges] maintenance = { status = "actively-developed" } diff --git a/src/components/status_tree.rs b/src/components/status_tree.rs index 0302350d..d389741b 100644 --- a/src/components/status_tree.rs +++ b/src/components/status_tree.rs @@ -226,7 +226,7 @@ impl StatusTreeComponent { } } - /// Returns a Vec which is used to draw the `FileTreeComponent` correctly, + /// Returns a `Vec` which is used to draw the `FileTreeComponent` correctly, /// allowing folders to be folded up if they are alone in their directory fn build_vec_text_draw_info_for_drawing( &self, diff --git a/src/keys/key_list.rs b/src/keys/key_list.rs index e9343c0c..d80a6ad4 100644 --- a/src/keys/key_list.rs +++ b/src/keys/key_list.rs @@ -210,3 +210,37 @@ impl KeysList { } } } + +#[cfg(test)] +mod tests { + use super::*; + use pretty_assertions::assert_eq; + use std::io::Write; + use tempfile::NamedTempFile; + + #[test] + fn test_smoke() { + let mut file = NamedTempFile::new().unwrap(); + + writeln!( + file, + r" +( + move_down: Some(( code: Char('j'), modifiers: ( bits: 2,),)), +) +" + ) + .unwrap(); + + let keys = KeysList::init(file.path().to_path_buf()); + + assert_eq!(keys.move_right, KeysList::default().move_right); + assert_eq!( + keys.move_down, + GituiKeyEvent::new( + KeyCode::Char('j'), + KeyModifiers::CONTROL + ) + ); + } +}