Skip to content

Commit

Permalink
add unit tests to ui/mod.rs #700
Browse files Browse the repository at this point in the history
  • Loading branch information
o2sh committed Aug 7, 2022
1 parent 26cb0f1 commit d562e86
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,51 @@ fn num_to_color(num: &u8) -> DynColors {
_ => DynColors::Ansi(AnsiColors::Default),
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_num_to_color() {
assert_eq!(num_to_color(&2), DynColors::Ansi(AnsiColors::Green));
assert_eq!(num_to_color(&u8::MAX), DynColors::Ansi(AnsiColors::Default));
}

#[test]
fn get_ascii_colors_no_custom_language_no_custom_colors_no_true_color() {
let colors = get_ascii_colors(&None, &Language::Rust, &[], false);
assert_eq!(colors.len(), 2);
assert_eq!(
colors,
vec![
DynColors::Ansi(AnsiColors::Red),
DynColors::Ansi(AnsiColors::Default)
]
);
}

#[test]
fn get_ascii_colors_no_custom_language_no_custom_colors_true_color() {
let colors = get_ascii_colors(&None, &Language::Rust, &[], true);
assert_eq!(colors.len(), 2);
assert_eq!(
colors,
vec![DynColors::Rgb(228, 55, 23), DynColors::Rgb(255, 255, 255)]
);
}

#[test]
fn get_ascii_colors_custom_language_no_custom_colors_no_true_color() {
let colors = get_ascii_colors(&Some(Language::Sh), &Language::Rust, &[], false);
assert_eq!(colors.len(), 1);
assert_eq!(colors, vec![DynColors::Ansi(AnsiColors::Green)]);
}

#[test]
fn get_ascii_colors_no_custom_language_custom_colors_no_true_color() {
let colors = get_ascii_colors(&None, &Language::Rust, &[2, 3], false);
assert_eq!(colors.len(), 2);
assert_eq!(colors, vec![num_to_color(&2), num_to_color(&3)]);
}
}

0 comments on commit d562e86

Please sign in to comment.