From 22b4f0f816c3e9a94dfb0aea9dd985361f86c68d Mon Sep 17 00:00:00 2001 From: Peltoche Date: Fri, 14 Dec 2018 13:48:03 +0100 Subject: [PATCH] Add a test on relative date flag --- src/meta/date.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/meta/date.rs b/src/meta/date.rs index ffc1388..bcfdd83 100644 --- a/src/meta/date.rs +++ b/src/meta/date.rs @@ -188,4 +188,48 @@ mod test { fs::remove_file(file_path).unwrap(); } + + #[test] + fn test_with_relative_date() { + let mut file_path = env::temp_dir(); + file_path.push("test_with_relative_date.tmp"); + + let creation_date = time::now() - time::Duration::days(2); + + let success = Command::new("touch") + .arg("-t") + .arg( + creation_date + .to_local() + .strftime("%Y%m%d%H%M.%S") + .unwrap() + .to_string(), + ) + .arg(&file_path) + .status() + .unwrap() + .success(); + assert_eq!(true, success, "failed to exec touch"); + + let colors = Colors::new(Theme::Default); + let date = Date::from(&file_path.metadata().unwrap()); + let flags = Flags { + display_all: true, + display_long: true, + display_online: true, + display_tree: true, + display_indicators: true, + recursive: true, + date: DateFlag::Relative, + color: WhenFlag::Always, + icon: WhenFlag::Always, + }; + + assert_eq!( + Colour::Fixed(36).paint("2 days ago "), + date.render(&colors, 12, flags) + ); + + fs::remove_file(file_path).unwrap(); + } }