mirror of
https://github.com/lsd-rs/lsd
synced 2025-03-04 23:17:15 +00:00
🔍 🔨 fix tests to fit icon theme
Signed-off-by: zwPapEr <zw.paper@gmail.com> Signed-off-by: Wei Zhang <kweizh@gmail.com>
This commit is contained in:
parent
9de3090c12
commit
7e9a07a97d
8 changed files with 85 additions and 71 deletions
30
src/color.rs
30
src/color.rs
|
@ -301,7 +301,7 @@ fn to_content_style(ls: &lscolors::Style) -> ContentStyle {
|
|||
mod tests {
|
||||
use super::Colors;
|
||||
use crate::color::ThemeOption;
|
||||
use crate::theme::color_theme::Theme;
|
||||
use crate::theme::color::ColorTheme;
|
||||
#[test]
|
||||
fn test_color_new_no_color_theme() {
|
||||
assert!(Colors::new(ThemeOption::NoColor).theme.is_none());
|
||||
|
@ -311,7 +311,7 @@ mod tests {
|
|||
fn test_color_new_default_theme() {
|
||||
assert_eq!(
|
||||
Colors::new(ThemeOption::Default).theme,
|
||||
Some(Theme::default_dark()),
|
||||
Some(ColorTheme::default_dark()),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -319,7 +319,7 @@ mod tests {
|
|||
fn test_color_new_bad_custom_theme() {
|
||||
assert_eq!(
|
||||
Colors::new(ThemeOption::Custom("not-existed".to_string())).theme,
|
||||
Some(Theme::default_dark()),
|
||||
Some(ColorTheme::default_dark()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -327,15 +327,15 @@ mod tests {
|
|||
#[cfg(test)]
|
||||
mod elem {
|
||||
use super::Elem;
|
||||
use crate::color::{theme, Theme};
|
||||
use crate::theme::{color, color::ColorTheme};
|
||||
use crossterm::style::Color;
|
||||
|
||||
#[cfg(test)]
|
||||
fn test_theme() -> Theme {
|
||||
Theme {
|
||||
fn test_theme() -> ColorTheme {
|
||||
ColorTheme {
|
||||
user: Color::AnsiValue(230), // Cornsilk1
|
||||
group: Color::AnsiValue(187), // LightYellow3
|
||||
permission: theme::Permission {
|
||||
permission: color::Permission {
|
||||
read: Color::Green,
|
||||
write: Color::Yellow,
|
||||
exec: Color::Red,
|
||||
|
@ -345,19 +345,19 @@ mod elem {
|
|||
acl: Color::DarkCyan,
|
||||
context: Color::Cyan,
|
||||
},
|
||||
file_type: theme::FileType {
|
||||
file: theme::File {
|
||||
file_type: color::FileType {
|
||||
file: color::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 {
|
||||
dir: color::Dir {
|
||||
uid: Color::AnsiValue(33), // DodgerBlue1
|
||||
no_uid: Color::AnsiValue(33), // DodgerBlue1
|
||||
},
|
||||
pipe: Color::AnsiValue(44), // DarkTurquoise
|
||||
symlink: theme::Symlink {
|
||||
symlink: color::Symlink {
|
||||
default: Color::AnsiValue(44), // DarkTurquoise
|
||||
broken: Color::AnsiValue(124), // Red3
|
||||
missing_target: Color::AnsiValue(124), // Red3
|
||||
|
@ -367,22 +367,22 @@ mod elem {
|
|||
socket: Color::AnsiValue(44), // DarkTurquoise
|
||||
special: Color::AnsiValue(44), // DarkTurquoise
|
||||
},
|
||||
date: theme::Date {
|
||||
date: color::Date {
|
||||
hour_old: Color::AnsiValue(40), // Green3
|
||||
day_old: Color::AnsiValue(42), // SpringGreen2
|
||||
older: Color::AnsiValue(36), // DarkCyan
|
||||
},
|
||||
size: theme::Size {
|
||||
size: color::Size {
|
||||
none: Color::AnsiValue(245), // Grey
|
||||
small: Color::AnsiValue(229), // Wheat1
|
||||
medium: Color::AnsiValue(216), // LightSalmon1
|
||||
large: Color::AnsiValue(172), // Orange3
|
||||
},
|
||||
inode: theme::INode {
|
||||
inode: color::INode {
|
||||
valid: Color::AnsiValue(13), // Pink
|
||||
invalid: Color::AnsiValue(245), // Grey
|
||||
},
|
||||
links: theme::Links {
|
||||
links: color::Links {
|
||||
valid: Color::AnsiValue(13), // Pink
|
||||
invalid: Color::AnsiValue(245), // Grey
|
||||
},
|
||||
|
|
|
@ -413,11 +413,11 @@ mod tests {
|
|||
use super::*;
|
||||
use crate::color;
|
||||
use crate::color::Colors;
|
||||
use crate::flags::HyperlinkOption;
|
||||
use crate::flags::{HyperlinkOption, IconOption, IconTheme as FlagTheme};
|
||||
use crate::icon::Icons;
|
||||
use crate::meta::{FileType, Name};
|
||||
use crate::Config;
|
||||
use crate::{app, flags, icon, sort};
|
||||
use crate::{app, flags, sort};
|
||||
use assert_fs::prelude::*;
|
||||
use std::path::Path;
|
||||
|
||||
|
@ -443,7 +443,7 @@ mod tests {
|
|||
let output = name
|
||||
.render(
|
||||
&Colors::new(color::ThemeOption::NoColor),
|
||||
&Icons::new(icon::Theme::NoIcon, " ".to_string()),
|
||||
&Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string()),
|
||||
&DisplayOption::FileName,
|
||||
HyperlinkOption::Never,
|
||||
true,
|
||||
|
@ -478,7 +478,7 @@ mod tests {
|
|||
let output = name
|
||||
.render(
|
||||
&Colors::new(color::ThemeOption::NoColor),
|
||||
&Icons::new(icon::Theme::Fancy, " ".to_string()),
|
||||
&Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string()),
|
||||
&DisplayOption::FileName,
|
||||
HyperlinkOption::Never,
|
||||
true,
|
||||
|
@ -512,7 +512,7 @@ mod tests {
|
|||
let output = name
|
||||
.render(
|
||||
&Colors::new(color::ThemeOption::NoLscolors),
|
||||
&Icons::new(icon::Theme::NoIcon, " ".to_string()),
|
||||
&Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string()),
|
||||
&DisplayOption::FileName,
|
||||
HyperlinkOption::Never,
|
||||
true,
|
||||
|
@ -554,7 +554,7 @@ mod tests {
|
|||
let output = name
|
||||
.render(
|
||||
&Colors::new(color::ThemeOption::NoColor),
|
||||
&Icons::new(icon::Theme::NoIcon, " ".to_string()),
|
||||
&Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string()),
|
||||
&DisplayOption::FileName,
|
||||
HyperlinkOption::Never,
|
||||
true,
|
||||
|
@ -618,7 +618,7 @@ mod tests {
|
|||
&metas,
|
||||
&flags,
|
||||
&Colors::new(color::ThemeOption::NoColor),
|
||||
&Icons::new(icon::Theme::NoIcon, " ".to_string()),
|
||||
&Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string()),
|
||||
);
|
||||
|
||||
assert_eq!("one.d\n├── .hidden\n└── two\n", output);
|
||||
|
@ -649,7 +649,7 @@ mod tests {
|
|||
&metas,
|
||||
&flags,
|
||||
&Colors::new(color::ThemeOption::NoColor),
|
||||
&Icons::new(icon::Theme::NoIcon, " ".to_string()),
|
||||
&Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string()),
|
||||
);
|
||||
|
||||
let length_before_b = |i| -> usize {
|
||||
|
@ -689,7 +689,7 @@ mod tests {
|
|||
&metas,
|
||||
&flags,
|
||||
&Colors::new(color::ThemeOption::NoColor),
|
||||
&Icons::new(icon::Theme::NoIcon, " ".to_string()),
|
||||
&Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string()),
|
||||
);
|
||||
|
||||
assert_eq!(output.lines().nth(1).unwrap().chars().next().unwrap(), '└');
|
||||
|
@ -728,7 +728,7 @@ mod tests {
|
|||
&metas,
|
||||
&flags,
|
||||
&Colors::new(color::ThemeOption::NoColor),
|
||||
&Icons::new(icon::Theme::NoIcon, " ".to_string()),
|
||||
&Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string()),
|
||||
);
|
||||
|
||||
assert!(output.ends_with("└── two\n"));
|
||||
|
@ -758,7 +758,7 @@ mod tests {
|
|||
&metas,
|
||||
&flags,
|
||||
&Colors::new(color::ThemeOption::NoColor),
|
||||
&Icons::new(icon::Theme::NoIcon, " ".to_string()),
|
||||
&Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string()),
|
||||
);
|
||||
|
||||
dir.close().unwrap();
|
||||
|
@ -791,7 +791,7 @@ mod tests {
|
|||
&metas,
|
||||
&flags,
|
||||
&Colors::new(color::ThemeOption::NoColor),
|
||||
&Icons::new(icon::Theme::NoIcon, " ".to_string()),
|
||||
&Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string()),
|
||||
);
|
||||
|
||||
dir.close().unwrap();
|
||||
|
|
|
@ -131,7 +131,7 @@ impl Configurable<Self> for IconTheme {
|
|||
/// this returns its corresponding variant in a [Some].
|
||||
/// Otherwise this returns [None].
|
||||
fn from_config(config: &Config) -> Option<Self> {
|
||||
config.icons.as_ref().and_then(|icon| icon.theme)
|
||||
config.icons.as_ref().and_then(|icon| icon.theme.clone())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
39
src/icon.rs
39
src/icon.rs
|
@ -21,7 +21,7 @@ impl Icons {
|
|||
} else {
|
||||
Some(IconTheme::default())
|
||||
}
|
||||
},
|
||||
}
|
||||
(_, _, FlagTheme::Unicode) => Some(IconTheme::unicode()),
|
||||
};
|
||||
|
||||
|
@ -79,7 +79,8 @@ impl Icons {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::{Icons, Theme};
|
||||
use super::{IconTheme, Icons};
|
||||
use crate::flags::{IconOption, IconTheme as FlagTheme};
|
||||
use crate::meta::Meta;
|
||||
use std::fs::File;
|
||||
use tempfile::tempdir;
|
||||
|
@ -91,7 +92,7 @@ mod test {
|
|||
File::create(&file_path).expect("failed to create file");
|
||||
let meta = Meta::from_path(&file_path, false).unwrap();
|
||||
|
||||
let icon = Icons::new(Theme::NoIcon, " ".to_string());
|
||||
let icon = Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string());
|
||||
let icon = icon.get(&meta.name);
|
||||
|
||||
assert_eq!(icon, "");
|
||||
|
@ -104,7 +105,7 @@ mod test {
|
|||
File::create(&file_path).expect("failed to create file");
|
||||
let meta = Meta::from_path(&file_path, false).unwrap();
|
||||
|
||||
let icon = Icons::new(Theme::Fancy, " ".to_string());
|
||||
let icon = Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string());
|
||||
let icon_str = icon.get(&meta.name);
|
||||
|
||||
assert_eq!(icon_str, "\u{f016} "); //
|
||||
|
@ -117,10 +118,15 @@ mod test {
|
|||
File::create(&file_path).expect("failed to create file");
|
||||
let meta = Meta::from_path(&file_path, false).unwrap();
|
||||
|
||||
let icon = Icons::new(Theme::Unicode, " ".to_string());
|
||||
let icon = Icons::new(
|
||||
false,
|
||||
IconOption::Always,
|
||||
FlagTheme::Unicode,
|
||||
" ".to_string(),
|
||||
);
|
||||
let icon_str = icon.get(&meta.name);
|
||||
|
||||
assert_eq!(icon_str, "\u{1f5cb} ");
|
||||
assert_eq!(icon_str, format!("{}{}", "\u{1f4c4}", icon.icon_separator));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -129,7 +135,7 @@ mod test {
|
|||
let file_path = tmp_dir.path();
|
||||
let meta = Meta::from_path(file_path, false).unwrap();
|
||||
|
||||
let icon = Icons::new(Theme::Fancy, " ".to_string());
|
||||
let icon = Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string());
|
||||
let icon_str = icon.get(&meta.name);
|
||||
|
||||
assert_eq!(icon_str, "\u{f115} "); //
|
||||
|
@ -141,10 +147,15 @@ mod test {
|
|||
let file_path = tmp_dir.path();
|
||||
let meta = Meta::from_path(file_path, false).unwrap();
|
||||
|
||||
let icon = Icons::new(Theme::Unicode, " ".to_string());
|
||||
let icon = Icons::new(
|
||||
false,
|
||||
IconOption::Always,
|
||||
FlagTheme::Unicode,
|
||||
" ".to_string(),
|
||||
);
|
||||
let icon_str = icon.get(&meta.name);
|
||||
|
||||
assert_eq!(icon_str, "\u{1f5c1} ");
|
||||
assert_eq!(icon_str, format!("{}{}", "\u{1f4c2}", icon.icon_separator));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -153,7 +164,7 @@ mod test {
|
|||
let file_path = tmp_dir.path();
|
||||
let meta = Meta::from_path(file_path, false).unwrap();
|
||||
|
||||
let icon = Icons::new(Theme::Fancy, " ".to_string());
|
||||
let icon = Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string());
|
||||
let icon_str = icon.get(&meta.name);
|
||||
|
||||
assert_eq!(icon_str, "\u{f115} "); //
|
||||
|
@ -163,12 +174,12 @@ mod test {
|
|||
fn get_icon_by_name() {
|
||||
let tmp_dir = tempdir().expect("failed to create temp dir");
|
||||
|
||||
for (file_name, file_icon) in &Icons::get_default_icons_by_name() {
|
||||
for (file_name, file_icon) in &IconTheme::get_default_icons_by_name() {
|
||||
let file_path = tmp_dir.path().join(file_name);
|
||||
File::create(&file_path).expect("failed to create file");
|
||||
let meta = Meta::from_path(&file_path, false).unwrap();
|
||||
|
||||
let icon = Icons::new(Theme::Fancy, " ".to_string());
|
||||
let icon = Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string());
|
||||
let icon_str = icon.get(&meta.name);
|
||||
|
||||
assert_eq!(icon_str, format!("{}{}", file_icon, icon.icon_separator));
|
||||
|
@ -179,12 +190,12 @@ mod test {
|
|||
fn get_icon_by_extension() {
|
||||
let tmp_dir = tempdir().expect("failed to create temp dir");
|
||||
|
||||
for (ext, file_icon) in &Icons::get_default_icons_by_extension() {
|
||||
for (ext, file_icon) in &IconTheme::get_default_icons_by_extension() {
|
||||
let file_path = tmp_dir.path().join(format!("file.{}", ext));
|
||||
File::create(&file_path).expect("failed to create file");
|
||||
let meta = Meta::from_path(&file_path, false).unwrap();
|
||||
|
||||
let icon = Icons::use Theme::Fancy, " ".to_string());
|
||||
let icon = Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string());
|
||||
let icon_str = icon.get(&meta.name);
|
||||
|
||||
assert_eq!(icon_str, format!("{}{}", file_icon, icon.icon_separator));
|
||||
|
|
|
@ -219,8 +219,8 @@ mod test {
|
|||
use super::DisplayOption;
|
||||
use super::Name;
|
||||
use crate::color::{self, Colors};
|
||||
use crate::flags::HyperlinkOption;
|
||||
use crate::icon::{self, Icons};
|
||||
use crate::flags::{HyperlinkOption, IconOption, IconTheme as FlagTheme};
|
||||
use crate::icon::Icons;
|
||||
use crate::meta::FileType;
|
||||
use crate::meta::Meta;
|
||||
#[cfg(unix)]
|
||||
|
@ -240,7 +240,7 @@ mod test {
|
|||
#[cfg(unix)] // Windows uses different default permissions
|
||||
fn test_print_file_name() {
|
||||
let tmp_dir = tempdir().expect("failed to create temp dir");
|
||||
let icons = Icons::new(icon::Theme::Fancy, " ".to_string());
|
||||
let icons = Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string());
|
||||
|
||||
// Create the file;
|
||||
let file_path = tmp_dir.path().join("file.txt");
|
||||
|
@ -266,7 +266,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_print_dir_name() {
|
||||
let tmp_dir = tempdir().expect("failed to create temp dir");
|
||||
let icons = Icons::new(icon::Theme::Fancy, " ".to_string());
|
||||
let icons = &Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string());
|
||||
|
||||
// Create the directory
|
||||
let dir_path = tmp_dir.path().join("directory");
|
||||
|
@ -279,7 +279,7 @@ mod test {
|
|||
" directory".to_string().with(Color::AnsiValue(33)),
|
||||
meta.name.render(
|
||||
&colors,
|
||||
&icons,
|
||||
icons,
|
||||
&DisplayOption::FileName,
|
||||
HyperlinkOption::Never,
|
||||
false
|
||||
|
@ -291,7 +291,7 @@ mod test {
|
|||
#[cfg(unix)] // Symlinks are hard on Windows
|
||||
fn test_print_symlink_name_file() {
|
||||
let tmp_dir = tempdir().expect("failed to create temp dir");
|
||||
let icons = Icons::new(icon::Theme::Fancy, " ".to_string());
|
||||
let icons = &Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string());
|
||||
|
||||
// Create the file;
|
||||
let file_path = tmp_dir.path().join("file.tmp");
|
||||
|
@ -313,7 +313,7 @@ mod test {
|
|||
" target.tmp".to_string().with(Color::AnsiValue(44)),
|
||||
name.render(
|
||||
&colors,
|
||||
&icons,
|
||||
icons,
|
||||
&DisplayOption::FileName,
|
||||
HyperlinkOption::Never,
|
||||
false
|
||||
|
@ -325,7 +325,7 @@ mod test {
|
|||
#[cfg(unix)] // Symlinks are hard on Windows
|
||||
fn test_print_symlink_name_dir() {
|
||||
let tmp_dir = tempdir().expect("failed to create temp dir");
|
||||
let icons = Icons::new(icon::Theme::Fancy, " ".to_string());
|
||||
let icons = Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string());
|
||||
|
||||
// Create the directory;
|
||||
let dir_path = tmp_dir.path().join("tmp.d");
|
||||
|
@ -359,7 +359,7 @@ mod test {
|
|||
#[cfg(unix)]
|
||||
fn test_print_other_type_name() {
|
||||
let tmp_dir = tempdir().expect("failed to create temp dir");
|
||||
let icons = Icons::new(icon::Theme::Fancy, " ".to_string());
|
||||
let icons = &Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string());
|
||||
|
||||
// Create the pipe;
|
||||
let pipe_path = tmp_dir.path().join("pipe.tmp");
|
||||
|
@ -379,7 +379,7 @@ mod test {
|
|||
" pipe.tmp".to_string().with(Color::AnsiValue(184)),
|
||||
name.render(
|
||||
&colors,
|
||||
&icons,
|
||||
icons,
|
||||
&DisplayOption::FileName,
|
||||
HyperlinkOption::Never,
|
||||
false
|
||||
|
@ -390,7 +390,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_print_without_icon_or_color() {
|
||||
let tmp_dir = tempdir().expect("failed to create temp dir");
|
||||
let icons = Icons::new(icon::Theme::NoIcon, " ".to_string());
|
||||
let icons = Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string());
|
||||
|
||||
// Create the file;
|
||||
let file_path = tmp_dir.path().join("file.txt");
|
||||
|
@ -416,7 +416,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_print_hyperlink() {
|
||||
let tmp_dir = tempdir().expect("failed to create temp dir");
|
||||
let icons = Icons::new(icon::Theme::NoIcon, " ".to_string());
|
||||
let icons = Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string());
|
||||
|
||||
// Create the file;
|
||||
let file_path = tmp_dir.path().join("file.txt");
|
||||
|
@ -643,7 +643,7 @@ mod test {
|
|||
#[cfg(unix)]
|
||||
fn test_special_chars_in_filename() {
|
||||
let tmp_dir = tempdir().expect("failed to create temp dir");
|
||||
let icons = Icons::new(icon::Theme::Fancy, " ".to_string());
|
||||
let icons = Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string());
|
||||
|
||||
// Create the file;
|
||||
let file_path = tmp_dir.path().join("file\ttab.txt");
|
||||
|
|
|
@ -13,7 +13,7 @@ use crate::print_error;
|
|||
use color::ColorTheme;
|
||||
use icon::IconTheme;
|
||||
|
||||
#[derive(Debug, Deserialize, Default, PartialEq)]
|
||||
#[derive(Debug, Deserialize, Default, PartialEq, Eq)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
#[serde(deny_unknown_fields)]
|
||||
#[serde(default)]
|
||||
|
|
|
@ -379,13 +379,14 @@ tree-edge: 245
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Theme;
|
||||
use super::ColorTheme;
|
||||
use crate::theme::Theme;
|
||||
|
||||
#[test]
|
||||
fn test_default_theme() {
|
||||
assert_eq!(
|
||||
Theme::default_dark(),
|
||||
Theme::with_yaml(Theme::default_yaml()).unwrap()
|
||||
ColorTheme::default_dark(),
|
||||
Theme::with_yaml(ColorTheme::default_yaml()).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -396,10 +397,10 @@ mod tests {
|
|||
let dir = assert_fs::TempDir::new().unwrap();
|
||||
let theme = dir.path().join("theme.yaml");
|
||||
let mut file = File::create(&theme).unwrap();
|
||||
writeln!(file, "{}", Theme::default_yaml()).unwrap();
|
||||
writeln!(file, "{}", ColorTheme::default_yaml()).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
Theme::default_dark(),
|
||||
ColorTheme::default_dark(),
|
||||
Theme::from_path(theme.to_str().unwrap()).unwrap()
|
||||
);
|
||||
}
|
||||
|
@ -408,8 +409,8 @@ mod tests {
|
|||
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").unwrap(); // 230 is the default value
|
||||
let default_theme = Theme::default_dark();
|
||||
let empty_theme: ColorTheme = Theme::with_yaml("user: 230").unwrap(); // 230 is the default value
|
||||
let default_theme = ColorTheme::default_dark();
|
||||
assert_eq!(empty_theme, default_theme);
|
||||
}
|
||||
|
||||
|
@ -417,8 +418,8 @@ mod tests {
|
|||
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").unwrap();
|
||||
let mut theme = Theme::default_dark();
|
||||
let empty_theme: ColorTheme = Theme::with_yaml("user: 130").unwrap();
|
||||
let mut theme = ColorTheme::default_dark();
|
||||
use crossterm::style::Color;
|
||||
theme.user = Color::AnsiValue(130);
|
||||
assert_eq!(empty_theme, theme);
|
||||
|
@ -428,13 +429,13 @@ mod tests {
|
|||
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(
|
||||
let empty_theme: ColorTheme = Theme::with_yaml(
|
||||
r#"---
|
||||
permission:
|
||||
read: 130"#,
|
||||
)
|
||||
.unwrap();
|
||||
let mut theme = Theme::default_dark();
|
||||
let mut theme = ColorTheme::default_dark();
|
||||
use crossterm::style::Color;
|
||||
theme.permission.read = Color::AnsiValue(130);
|
||||
assert_eq!(empty_theme, theme);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use serde::Deserialize;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq)]
|
||||
#[derive(Debug, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
#[serde(deny_unknown_fields)]
|
||||
#[serde(default)]
|
||||
|
@ -11,7 +11,7 @@ pub struct IconTheme {
|
|||
pub icons_by_filetype: IconByType,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq)]
|
||||
#[derive(Debug, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
#[serde(deny_unknown_fields)]
|
||||
#[serde(default)]
|
||||
|
@ -81,7 +81,8 @@ impl IconTheme {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_default_icons_by_name() -> HashMap<String, String> {
|
||||
// pub only for testing in icons.rs
|
||||
pub fn get_default_icons_by_name() -> HashMap<String, String> {
|
||||
// Note: filenames must be lower-case
|
||||
[
|
||||
(".trash", "\u{f1f8}"), // ""
|
||||
|
@ -208,7 +209,8 @@ impl IconTheme {
|
|||
.collect::<HashMap<_, _>>()
|
||||
}
|
||||
|
||||
fn get_default_icons_by_extension() -> HashMap<String, String> {
|
||||
// pub only for testing in icons.rs
|
||||
pub fn get_default_icons_by_extension() -> HashMap<String, String> {
|
||||
// Note: extensions must be lower-case
|
||||
[
|
||||
("1", "\u{f02d}"), // ""
|
||||
|
|
Loading…
Add table
Reference in a new issue