Skip to content

Commit

Permalink
theme: 🔍 🔨 update tests to fit optional theme items
Browse files Browse the repository at this point in the history
Signed-off-by: zwPapEr <[email protected]>
  • Loading branch information
zwpaper authored and meain committed Jan 16, 2022
1 parent 6049e2e commit ade8662
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 86 deletions.
134 changes: 48 additions & 86 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,81 +324,57 @@ mod elem {
#[cfg(test)]
fn test_theme() -> Theme {
Theme {
user: Some(Color::AnsiValue(230)), // Cornsilk1
group: Some(Color::AnsiValue(187)), // LightYellow3
permission: Some(theme::Permission {
read: Some(Color::Green),
write: Some(Color::Yellow),
exec: Some(Color::Red),
exec_sticky: Some(Color::Magenta),
no_access: Some(Color::AnsiValue(245)), // Grey
}),
file_type: theme::FileType {
file: Some(theme::File {
exec_uid: Some(Color::AnsiValue(40)), // Green3
uid_no_exec: Some(Color::AnsiValue(184)), // Yellow3
exec_no_uid: Some(Color::AnsiValue(40)), // Green3
no_exec_no_uid: Some(Color::AnsiValue(184)), // Yellow3
}),
dir: Some(theme::Dir {
uid: Some(Color::AnsiValue(33)), // DodgerBlue1
no_uid: Some(Color::AnsiValue(33)), // DodgerBlue1
}),
pipe: Some(Color::AnsiValue(44)), // DarkTurquoise
symlink: Some(theme::Symlink {
default: Some(Color::AnsiValue(44)), // DarkTurquoise
broken: Some(Color::AnsiValue(124)), // Red3
missing_target: Some(Color::AnsiValue(124)), // Red3
}),
block_device: Some(Color::AnsiValue(44)), // DarkTurquoise
char_device: Some(Color::AnsiValue(172)), // Orange3
socket: Some(Color::AnsiValue(44)), // DarkTurquoise
special: Some(Color::AnsiValue(44)), // DarkTurquoise
user: Color::AnsiValue(230), // Cornsilk1
group: Color::AnsiValue(187), // LightYellow3
permission: theme::Permission {
read: Color::Green,
write: Color::Yellow,
exec: Color::Red,
exec_sticky: Color::Magenta,
no_access: Color::AnsiValue(245), // Grey
},
date: Some(theme::Date {
hour_old: Some(Color::AnsiValue(40)), // Green3
day_old: Some(Color::AnsiValue(42)), // SpringGreen2
older: Some(Color::AnsiValue(36)), // DarkCyan
}),
size: Some(theme::Size {
none: Some(Color::AnsiValue(245)), // Grey
small: Some(Color::AnsiValue(229)), // Wheat1
medium: Some(Color::AnsiValue(216)), // LightSalmon1
large: Some(Color::AnsiValue(172)), // Orange3
}),
inode: Some(theme::INode {
valid: Some(Color::AnsiValue(13)), // Pink
invalid: Some(Color::AnsiValue(245)), // Grey
}),
links: Some(theme::Links {
valid: Some(Color::AnsiValue(13)), // Pink
invalid: Some(Color::AnsiValue(245)), // Grey
}),
tree_edge: Some(Color::AnsiValue(245)), // Grey
}
}

fn none_theme() -> Theme {
Theme {
default: Color::Green,
file_type: theme::FileType {
file: None,
dir: None,
pipe: None,
symlink: None,
block_device: None,
char_device: None,
socket: None,
special: None,
file: theme::File {
exec_uid: Color::AnsiValue(40), // Green3
uid_no_exec: Color::AnsiValue(184), // Yellow3
exec_no_uid: Color::AnsiValue(40), // Green3
no_exec_no_uid: Color::AnsiValue(184), // Yellow3
},
dir: theme::Dir {
uid: Color::AnsiValue(33), // DodgerBlue1
no_uid: Color::AnsiValue(33), // DodgerBlue1
},
pipe: Color::AnsiValue(44), // DarkTurquoise
symlink: theme::Symlink {
default: Color::AnsiValue(44), // DarkTurquoise
broken: Color::AnsiValue(124), // Red3
missing_target: Color::AnsiValue(124), // Red3
},
block_device: Color::AnsiValue(44), // DarkTurquoise
char_device: Color::AnsiValue(172), // Orange3
socket: Color::AnsiValue(44), // DarkTurquoise
special: Color::AnsiValue(44), // DarkTurquoise
},
date: theme::Date {
hour_old: Color::AnsiValue(40), // Green3
day_old: Color::AnsiValue(42), // SpringGreen2
older: Color::AnsiValue(36), // DarkCyan
},
size: theme::Size {
none: Color::AnsiValue(245), // Grey
small: Color::AnsiValue(229), // Wheat1
medium: Color::AnsiValue(216), // LightSalmon1
large: Color::AnsiValue(172), // Orange3
},
inode: theme::INode {
valid: Color::AnsiValue(13), // Pink
invalid: Color::AnsiValue(245), // Grey
},
group: None,
user: None,
permission: None,
date: None,
size: None,
inode: None,
links: None,
tree_edge: None,
links: theme::Links {
valid: Color::AnsiValue(13), // Pink
invalid: Color::AnsiValue(245), // Grey
},
tree_edge: Color::AnsiValue(245), // Grey
}
}

Expand Down Expand Up @@ -437,18 +413,4 @@ mod elem {
Color::AnsiValue(184),
);
}

#[test]
fn test_default_theme_default() {
assert_eq!(Elem::User.get_color(&none_theme()), none_theme().default,);
assert_eq!(Elem::Group.get_color(&none_theme()), none_theme().default,);
assert_eq!(
Elem::INode { valid: false }.get_color(&none_theme()),
none_theme().default,
);
assert_eq!(
Elem::Links { valid: true }.get_color(&none_theme()),
none_theme().default,
);
}
}
37 changes: 37 additions & 0 deletions src/color/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,41 @@ mod tests {
Theme::from_path(theme.to_str().unwrap()).unwrap()
);
}

#[test]
fn test_empty_theme_return_default() {
// Must contain one field at least
// ref https://github.com/dtolnay/serde-yaml/issues/86
let empty_theme = Theme::with_yaml("user: 230".into()).unwrap();
let default_theme = Theme::default_dark();
assert_eq!(empty_theme, default_theme);
}

#[test]
fn test_first_level_theme_return_default_but_changed() {
// Must contain one field at least
// ref https://github.com/dtolnay/serde-yaml/issues/86
let empty_theme = Theme::with_yaml("user: 130".into()).unwrap();
let mut theme = Theme::default_dark();
use crossterm::style::Color;
theme.user = Color::AnsiValue(130);
assert_eq!(empty_theme, theme);
}

#[test]
fn test_second_level_theme_return_default_but_changed() {
// Must contain one field at least
// ref https://github.com/dtolnay/serde-yaml/issues/86
let empty_theme = Theme::with_yaml(
r#"---
permission:
read: 130"#
.into(),
)
.unwrap();
let mut theme = Theme::default_dark();
use crossterm::style::Color;
theme.permission.read = Color::AnsiValue(130);
assert_eq!(empty_theme, theme);
}
}

0 comments on commit ade8662

Please sign in to comment.