diff options
author | mario <mario-krehl@gmx.de> | 2016-06-29 16:31:06 +0200 |
---|---|---|
committer | mario <mario-krehl@gmx.de> | 2016-06-29 19:36:44 +0200 |
commit | a771d00c5b69e141ec5a18e3c3e9d31071a4c5c0 (patch) | |
tree | 8b78a9cf5ee3d6d02c1dc99596e4c649e2a3cf3d /src/import.rs | |
parent | 6ac9fbc4d69eaa259c4c8d55df7c01107e6d2611 (diff) |
impl import_task
Diffstat (limited to 'src/import.rs')
-rw-r--r-- | src/import.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/import.rs b/src/import.rs index be4760c..f6df79c 100644 --- a/src/import.rs +++ b/src/import.rs @@ -17,6 +17,14 @@ pub fn import<R: Read>(r: R) -> Result<Vec<Task>> { }) } +/// Import a single JSON-formatted Task +pub fn import_task(s : &str) -> Result<Task> { + serde_json::from_str(s) + .map_err(|e| { + TaskError::new(TaskErrorKind::ParserError, Some(Box::new(e))) + }) +} + #[test] fn test_one() { let s = r#" @@ -98,3 +106,27 @@ fn test_two() { let imported = imported.unwrap(); assert!(imported.len() == 3); } + +#[test] +fn test_one_single() { + use status::TaskStatus; + let s = r#" +{ + "id": 1, + "description": "some description", + "entry": "20150619T165438Z", + "modified": "20160327T164007Z", + "project": "someproject", + "status": "waiting", + "tags": ["some", "tags", "are", "here"], + "uuid": "8ca953d5-18b4-4eb9-bd56-18f2e5b752f0", + "wait": "20160508T164007Z", + "urgency": 0.583562 +} +"#; + let imported = import_task(&s); + assert!(imported.is_ok()); + let imported = imported.unwrap(); + assert!(imported.status() == &TaskStatus::Waiting); +} + |