diff --git a/src/ansi_escape_code.rs b/src/ansi_escape_code.rs index 7dbde5d..926003a 100644 --- a/src/ansi_escape_code.rs +++ b/src/ansi_escape_code.rs @@ -2,11 +2,36 @@ pub struct ANSIEscapeCode { parameter: String, } impl ANSIEscapeCode { - pub fn new(parameter: String) -> Self { - ANSIEscapeCode { parameter } + pub fn new(parameter: &str) -> Self { + ANSIEscapeCode { parameter: parameter.to_string() } } pub fn code(&self) -> String { format!("\\x1b[{}m", self.parameter) } } + +// ======================================================================= + +#[cfg(test)] +mod ansi_escape_code_test { + use super::*; + + #[test] + fn create_simple_ansi_code() { + let p = ANSIEscapeCode::new("33"); + assert_eq!(p.code(), "\\x1b[33m") + } + + #[test] + fn create_reset_ansi_code() { + let reset_ansi = ANSIEscapeCode::new("0"); + assert_eq!("\\x1b[0m", reset_ansi.code()); + } + + #[test] + fn create_bright_cyan_ansi_code() { + let reset_ansi = ANSIEscapeCode::new("96"); + assert_eq!("\\x1b[96m", reset_ansi.code()); + } +} diff --git a/src/test.rs b/src/test.rs deleted file mode 100644 index 2fc6eaa..0000000 --- a/src/test.rs +++ /dev/null @@ -1,23 +0,0 @@ -#[cfg(test)] -mod ansi_escape_code_test { - use crate::ansi_escape_code::ANSIEscapeCode; - use super::*; - - #[test] - fn create_simple_ansi_code() { - let p = ANSIEscapeCode::new(String::from("33")); - assert_eq!(p.code(), "\\x1b[33m") - } - - #[test] - fn create_reset_ansi_code() { - let reset_ansi = ANSIEscapeCode::new(String::from("0")); - assert_eq!("\\x1b[0m", reset_ansi.code()); - } - - #[test] - fn create_bright_cyan_ansi_code() { - let reset_ansi = ANSIEscapeCode::new(String::from("96")); - assert_eq!("\\x1b[96m", reset_ansi.code()); - } -}