refactor(test): initialize variable with functional update syntax

Fix clippy lint
https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default
This commit is contained in:
Narawit Rakket 2022-07-03 15:39:01 +07:00 committed by Abin Simon
parent 2c540f17a0
commit b35b09817e
4 changed files with 60 additions and 30 deletions

View file

@ -215,8 +215,10 @@ mod test {
let colors = Colors::new(ThemeOption::Default);
let date = Date::from(&file_path.metadata().unwrap());
let mut flags = Flags::default();
flags.date = DateFlag::Relative;
let flags = Flags {
date: DateFlag::Relative,
..Default::default()
};
assert_eq!(
"2 days ago".to_string().with(Color::AnsiValue(36)),
@ -240,8 +242,10 @@ mod test {
let colors = Colors::new(ThemeOption::Default);
let date = Date::from(&file_path.metadata().unwrap());
let mut flags = Flags::default();
flags.date = DateFlag::Relative;
let flags = Flags {
date: DateFlag::Relative,
..Default::default()
};
assert_eq!(
"now".to_string().with(Color::AnsiValue(40)),
@ -265,8 +269,10 @@ mod test {
let colors = Colors::new(ThemeOption::Default);
let date = Date::from(&file_path.metadata().unwrap());
let mut flags = Flags::default();
flags.date = DateFlag::Iso;
let flags = Flags {
date: DateFlag::Iso,
..Default::default()
};
assert_eq!(
creation_date
@ -293,8 +299,10 @@ mod test {
let colors = Colors::new(ThemeOption::Default);
let date = Date::from(&file_path.metadata().unwrap());
let mut flags = Flags::default();
flags.date = DateFlag::Iso;
let flags = Flags {
date: DateFlag::Iso,
..Default::default()
};
assert_eq!(
creation_date
@ -318,8 +326,10 @@ mod test {
let colors = Colors::new(ThemeOption::Default);
let date = Date::from(end_time);
let mut flags = Flags::default();
flags.date = DateFlag::Date;
let flags = Flags {
date: DateFlag::Date,
..Default::default()
};
assert_eq!(
"-".to_string().with(Color::AnsiValue(36)),

View file

@ -38,8 +38,10 @@ mod test {
#[test]
fn test_directory_indicator() {
let mut flags = Flags::default();
flags.display_indicators = Indicators(true);
let flags = Flags {
display_indicators: Indicators(true),
..Default::default()
};
let file_type = Indicator::from(FileType::Directory { uid: false });
@ -48,8 +50,10 @@ mod test {
#[test]
fn test_executable_file_indicator() {
let mut flags = Flags::default();
flags.display_indicators = Indicators(true);
let flags = Flags {
display_indicators: Indicators(true),
..Default::default()
};
let file_type = Indicator::from(FileType::File {
uid: false,
@ -61,8 +65,10 @@ mod test {
#[test]
fn test_socket_indicator() {
let mut flags = Flags::default();
flags.display_indicators = Indicators(true);
let flags = Flags {
display_indicators: Indicators(true),
..Default::default()
};
let file_type = Indicator::from(FileType::Socket);
@ -71,8 +77,10 @@ mod test {
#[test]
fn test_symlink_indicator() {
let mut flags = Flags::default();
flags.display_indicators = Indicators(true);
let flags = Flags {
display_indicators: Indicators(true),
..Default::default()
};
let file_type = Indicator::from(FileType::SymLink { is_dir: false });
assert_eq!("@", file_type.render(&flags).to_string());
@ -83,8 +91,10 @@ mod test {
#[test]
fn test_not_represented_indicator() {
let mut flags = Flags::default();
flags.display_indicators = Indicators(true);
let flags = Flags {
display_indicators: Indicators(true),
..Default::default()
};
// The File type doesn't have any indicator
let file_type = Indicator::from(FileType::File {

View file

@ -221,8 +221,10 @@ mod test {
let meta = file_path.metadata().expect("failed to get meta");
let colors = Colors::new(ThemeOption::NoColor);
let mut flags = Flags::default();
flags.permission = PermissionFlag::Rwx;
let flags = Flags {
permission: PermissionFlag::Rwx,
..Default::default()
};
let perms = Permissions::from(&meta);
assert_eq!("rwxrwxrwt", perms.render(&colors, &flags).content());
@ -240,8 +242,10 @@ mod test {
let meta = file_path.metadata().expect("failed to get meta");
let colors = Colors::new(ThemeOption::NoColor);
let mut flags = Flags::default();
flags.permission = PermissionFlag::Octal;
let flags = Flags {
permission: PermissionFlag::Octal,
..Default::default()
};
let perms = Permissions::from(&meta);
assert_eq!("0655", perms.render(&colors, &flags).content());
@ -259,8 +263,10 @@ mod test {
let meta = file_path.metadata().expect("failed to get meta");
let colors = Colors::new(ThemeOption::NoColor);
let mut flags = Flags::default();
flags.permission = PermissionFlag::Octal;
let flags = Flags {
permission: PermissionFlag::Octal,
..Default::default()
};
let perms = Permissions::from(&meta);
assert_eq!("0777", perms.render(&colors, &flags).content());
@ -279,8 +285,10 @@ mod test {
let meta = file_path.metadata().expect("failed to get meta");
let colors = Colors::new(ThemeOption::NoColor);
let mut flags = Flags::default();
flags.permission = PermissionFlag::Octal;
let flags = Flags {
permission: PermissionFlag::Octal,
..Default::default()
};
let perms = Permissions::from(&meta);
assert_eq!("1777", perms.render(&colors, &flags).content());

View file

@ -317,8 +317,10 @@ mod test {
#[test]
fn render_short_nospaces() {
let size = Size::new(42 * KB); // 42 kilobytes
let mut flags = Flags::default();
flags.size = SizeFlag::Short;
let flags = Flags {
size: SizeFlag::Short,
..Default::default()
};
let colors = Colors::new(ThemeOption::NoColor);
assert_eq!(size.render(&colors, &flags, Some(2)).to_string(), "42K");