From f82418db475bf2fbf6387772f9ad2a520b87ac84 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Mon, 27 Nov 2023 08:59:01 -0700 Subject: [PATCH] test tsheet.add(x, tag) --- src/main.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0d30c9b..7a391d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,7 +54,7 @@ mod test_save_load { use super::*; #[test] - fn test_save_load_empty() { + fn test_empty() { let got = _load(&mut "xs: []".as_bytes()).expect("failed to parse 'xs: []' tsheet"); assert_eq!(got, TSheet{xs: vec![]}); @@ -88,6 +88,10 @@ impl TSheet { .for_each(|x| result.xs.push(x.clone())); result } + + fn add(&mut self, x: String, tag: String) { + self.xs.push(new_x(SystemTime::now(), x, tag)); + } } impl X { @@ -96,12 +100,32 @@ impl X { } } +fn new_x(t: SystemTime, x: String, tag: String) -> X { + X{ + t: t.duration_since(UNIX_EPOCH).unwrap().as_secs() as i64, + x: x, + tag: tag, + } +} + #[cfg(test)] mod test_tsheet { use super::*; #[test] - fn test_tsheet_since_date() { + fn test_add() { + let mut given = TSheet{xs: vec![ + X{t: 1, x: "def".to_string(), tag: "abc".to_string()}, + ]}; + given.add("ghi".to_string(), "".to_string()); + assert_eq!(given.xs.len(), 2); + assert!(given.xs[1].t != 1); + assert_eq!(given.xs[1].x, "ghi".to_string()); + assert_eq!(given.xs[1].tag, "".to_string()); + } + + #[test] + fn test_since_date() { let given = TSheet{xs: vec![ X{t: 1, x: "def".to_string(), tag: "abc".to_string()}, X{t: 2, x: "ghi".to_string(), tag: "".to_string()},