From 0543bb8ade04451dfffbb8dfb03af42cfc76bbe2 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 31 May 2020 21:48:39 +0800 Subject: [PATCH] move test to tetss/ --- src/lib.rs | 34 ---------------------------------- tests/lib_test.rs | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 34 deletions(-) create mode 100644 tests/lib_test.rs diff --git a/src/lib.rs b/src/lib.rs index 37c8bee..ed3ad23 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -226,37 +226,3 @@ fn get_all_chars(c: char, chars: &mut Peekable) -> usize { } cnt } - -#[test] -fn test_simpledateformat_format() { - let t = Utc.timestamp_millis(0); - assert_eq!("1970/01/01 00:00:00.000 Z", &fmt("yyyy/MM/dd HH:mm:ss.SSS z").unwrap().format(&t)); - - let t = Utc.timestamp_millis(1111111111); - assert_eq!("1970/01/13 20:38:31.111 Z", &fmt("yyyy/MM/dd HH:mm:ss.SSS z").unwrap().format(&t)); - - let t = Utc.timestamp_millis(1111111111); - assert_eq!("1970/01/13 08:38:31.111 Z PM", &fmt("yyyy/MM/dd hh:mm:ss.SSS z a").unwrap().format(&t)); - - let t = Utc.timestamp_millis(1590816448678); - assert_eq!("2020/05/30 05:27:28.678 Z AM", &fmt("yyyy/MM/dd hh:mm:ss.SSS z a").unwrap().format(&t)); - - let t = Utc.timestamp_millis(1590816448678); - assert_eq!("Sat May 30, 2020 05:27:28.678 Z AM", &fmt("EEE MMM dd, yyyy hh:mm:ss.SSS z a").unwrap().format(&t)); - - let t = Local.timestamp_millis(1590816448678); - assert_eq!("Sat May 30, 2020 01:27:28.678 +08:00 PM", &fmt("EEE MMM dd, yyyy hh:mm:ss.SSS z a").unwrap().format(&t)); -} - -#[test] -fn test_format_human() { - assert_eq!("0ms", format_human(Duration::from_millis(0))); - assert_eq!("11ms", format_human(Duration::from_millis(11))); - assert_eq!("11s 111ms", format_human(Duration::from_millis(11111))); - assert_eq!("1s", format_human(Duration::from_secs(1))); - assert_eq!("1min", format_human(Duration::from_secs(60))); - assert_eq!("1hour", format_human(Duration::from_secs(60 * 60))); - assert_eq!("1day", format_human(Duration::from_secs(24 * 60 * 60))); - assert_eq!("2days", format_human(Duration::from_secs(2 * 24 * 60 * 60))); - assert_eq!("2days 0hour 0min 1s", format_human(Duration::from_secs(2 * 24 * 60 * 60 + 1))); -} \ No newline at end of file diff --git a/tests/lib_test.rs b/tests/lib_test.rs new file mode 100644 index 0000000..a2b3759 --- /dev/null +++ b/tests/lib_test.rs @@ -0,0 +1,37 @@ +use simpledateformat::{ fmt, format_human, }; +use chrono::prelude::*; +use std::time::Duration; + +#[test] +fn test_simpledateformat_format() { + let t = Utc.timestamp_millis(0); + assert_eq!("1970/01/01 00:00:00.000 Z", &fmt("yyyy/MM/dd HH:mm:ss.SSS z").unwrap().format(&t)); + + let t = Utc.timestamp_millis(1111111111); + assert_eq!("1970/01/13 20:38:31.111 Z", &fmt("yyyy/MM/dd HH:mm:ss.SSS z").unwrap().format(&t)); + + let t = Utc.timestamp_millis(1111111111); + assert_eq!("1970/01/13 08:38:31.111 Z PM", &fmt("yyyy/MM/dd hh:mm:ss.SSS z a").unwrap().format(&t)); + + let t = Utc.timestamp_millis(1590816448678); + assert_eq!("2020/05/30 05:27:28.678 Z AM", &fmt("yyyy/MM/dd hh:mm:ss.SSS z a").unwrap().format(&t)); + + let t = Utc.timestamp_millis(1590816448678); + assert_eq!("Sat May 30, 2020 05:27:28.678 Z AM", &fmt("EEE MMM dd, yyyy hh:mm:ss.SSS z a").unwrap().format(&t)); + + let t = Local.timestamp_millis(1590816448678); + assert_eq!("Sat May 30, 2020 01:27:28.678 +08:00 PM", &fmt("EEE MMM dd, yyyy hh:mm:ss.SSS z a").unwrap().format(&t)); +} + +#[test] +fn test_format_human() { + assert_eq!("0ms", format_human(Duration::from_millis(0))); + assert_eq!("11ms", format_human(Duration::from_millis(11))); + assert_eq!("11s 111ms", format_human(Duration::from_millis(11111))); + assert_eq!("1s", format_human(Duration::from_secs(1))); + assert_eq!("1min", format_human(Duration::from_secs(60))); + assert_eq!("1hour", format_human(Duration::from_secs(60 * 60))); + assert_eq!("1day", format_human(Duration::from_secs(24 * 60 * 60))); + assert_eq!("2days", format_human(Duration::from_secs(2 * 24 * 60 * 60))); + assert_eq!("2days 0hour 0min 1s", format_human(Duration::from_secs(2 * 24 * 60 * 60 + 1))); +}