diff --git a/src/ceprint/mod.rs b/src/ceprint/mod.rs index 25ef3fa..1cc7dbb 100644 --- a/src/ceprint/mod.rs +++ b/src/ceprint/mod.rs @@ -73,7 +73,32 @@ macro_rules! ceprintln { #[cfg(test)] mod tests { #[test] - fn ceprint_macro() { - ceprintln!("Failed to compile"); + fn ceprint_title_message_color() { + ceprint!("Failed", "to compile" => Red); + } + + #[test] + fn ceprint_title_message_rgb() { + ceprint!("Failed", "to compile main.rs" => (255, 0, 0)); + } + + #[test] + fn ceprint_title_message() { + ceprint!("Failed", "to compile main.rs"); + } + + #[test] + fn ceprint_message_color() { + ceprint!("Failed to compile" => Red); + } + + #[test] + fn ceprint_message_rgb() { + ceprint!("Failed to compile" => (255, 0, 0)); + } + + #[test] + fn ceprint_message() { + ceprint!("Failed to compile"); } } diff --git a/src/cformat/mod.rs b/src/cformat/mod.rs index ce971b9..6104635 100644 --- a/src/cformat/mod.rs +++ b/src/cformat/mod.rs @@ -77,41 +77,79 @@ macro_rules! cformat { }}; } - #[cfg(test)] mod tests { use crate::{Color, Coloration}; #[test] - fn test_cformat() { - let string = cformat!("Compiling", "main.rs" => Green); + fn cformat_title_message_color() { + let string = cformat!("Cleaning up", "the mess" => Green); + let right = format!( + "{}{} {}", + " ".repeat(12 - "Cleaning up".len()), + "Cleaning up".as_colored_title(Color::Green), + "the mess" + ); + assert_eq!(string, right.as_ref()); + } + + #[test] + fn cformat_title_message_rgb() { + let string = cformat!("Cleaning up", "the mess" => (0, 255, 0)); + let right = format!( + "{}{} {}", + " ".repeat(12 - "Cleaning up".len()), + "Cleaning up".as_colored_title(Color::TrueColor { r: 0, g: 255, b: 0 }), + "the mess" + ); + assert_eq!(string, right.as_ref()); + } + + #[test] + fn cformat_title_message() { + let string = cformat!("Cleaning up", "the mess"); let right = format!( - "{} {}", - " Compiling".as_colored_title(Color::Green), - "main.rs" + "{}{} {}", + " ".repeat(12 - "Cleaning up".len()), + "Cleaning up".as_colored_title(Color::Green), + "the mess" ); - assert_eq!(string, right); + assert_eq!(string, right.as_ref()); } #[test] - fn test_cformat_with_spaces() { - let string = cformat!("Pre Build", "Parsing `main.rs`..." => Green); + fn cformat_message_color() { + let string = cformat!("Testing cformat!" => Green); let right = format!( - "{} {}", - " Pre Build".as_colored_title(Color::Green), - "Parsing `main.rs`..." + "{}{} {}", + " ".repeat(12 - "Testing".len()), + "Testing".as_colored_title(Color::Green), + "cformat!" ); - assert_eq!(string, right); + assert_eq!(string, right.as_ref()); } #[test] - fn test_cformat_with_carry_return_at_start() { - let string = cformat!("\rPre-Build parsing `main.rs`..." => (0, 255, 0)); + fn cformat_message_rgb() { + let string = cformat!("Testing cformat!" => (0, 255, 0)); let right = format!( - "\r{} {}", - " Pre-Build".as_colored_title(Color::TrueColor { r: 0, g: 255, b: 0 }), - "parsing `main.rs`..." + "{}{} {}", + " ".repeat(12 - "Testing".len()), + "Testing".as_colored_title(Color::TrueColor { r: 0, g: 255, b: 0 }), + "cformat!" + ); + assert_eq!(string, right.as_ref()); + } + + #[test] + fn cformat_message() { + let string = cformat!("Testing cformat!"); + let right = format!( + "{}{} {}", + " ".repeat(12 - "Testing".len()), + "Testing".as_colored_title(Color::Green), + "cformat!" ); - assert_eq!(string, right); + assert_eq!(string, right.as_ref()); } } diff --git a/src/cprint/mod.rs b/src/cprint/mod.rs index 1048823..7643982 100644 --- a/src/cprint/mod.rs +++ b/src/cprint/mod.rs @@ -69,3 +69,37 @@ macro_rules! cprintln { println!("{}", $crate::cformat!($msg => Green)) }}; } + +// These tests are just to make sure the macros compile, so we only use the `cprint!` macro. +#[cfg(test)] +mod tests { + #[test] + fn cprint_title_message_color() { + cprint!("Compiling", "main.rs" => Green); + } + + #[test] + fn cprint_title_message_rgb() { + cprint!("Compiling", "main.rs" => (255, 0, 0)); + } + + #[test] + fn cprint_title_message() { + cprint!("Compiling", "main.rs"); + } + + #[test] + fn cprint_message_color() { + cprint!("Compiling main.rs" => Green); + } + + #[test] + fn cprint_message_rgb() { + cprint!("Compiling main.rs" => (255, 0, 0)); + } + + #[test] + fn cprint_message() { + cprint!("Compiling main.rs"); + } +} diff --git a/src/lib.rs b/src/lib.rs index d309598..8fd07ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,7 +18,6 @@ //! - [`ceprint!`] and [`ceprintln!`] for printing to stderr. //! - [`cformat!`] for formatting a string. - pub use coloration::{Color, Coloration}; #[doc(hidden)]