test tsheet.add(x, tag)
parent
673f511e3d
commit
f82418db47
28
src/main.rs
28
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()},
|
||||
|
|
|
|||
Loading…
Reference in New Issue