Skip to content

Commit

Permalink
Edit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sellig6792 committed May 4, 2024
1 parent d6e2cb6 commit f9f6698
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 22 deletions.
29 changes: 27 additions & 2 deletions src/ceprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
76 changes: 57 additions & 19 deletions src/cformat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
34 changes: 34 additions & 0 deletions src/cprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
//! - [`ceprint!`] and [`ceprintln!`] for printing to stderr.
//! - [`cformat!`] for formatting a string.


pub use coloration::{Color, Coloration};

#[doc(hidden)]
Expand Down

0 comments on commit f9f6698

Please sign in to comment.