1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
use std::io::Read;
use serde_json;
use result::Result;
use task::Task;
use error::{TaskError, TaskErrorKind};
pub fn import<R: Read>(r: R) -> Result<Vec<Task>> {
serde_json::from_reader(r)
.map_err(|e| {
TaskError::new(TaskErrorKind::ParserError, Some(Box::new(e)))
})
}
#[test]
fn test_one() {
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(s.as_bytes());
assert!(imported.is_ok());
let imported = imported.unwrap();
assert!(imported.len() == 1);
}
#[test]
fn test_two() {
let s = r#"
[
{
"id" : 1,
"description" : "test",
"entry" : "20150619T165438Z",
"modified" : "20160327T164007Z",
"project" : "self.software",
"status" : "waiting",
"tags" : ["check", "this", "crate", "out"],
"uuid" : "8ca953d5-18b4-4eb9-bd56-18f2e5b752f0",
"wait" : "20160508T164007Z",
"urgency" : 0.583562
},
{
"id" : 2,
"description" : "another test",
"entry" : "20150623T181011Z",
"modified" : "20160327T163718Z",
"priority" : "L",
"project" : "studying",
"status" : "waiting",
"tags" : ["I", "have", "awesome", "kittens"],
"uuid" : "54d49ffc-a06b-4dd8-b7d1-db5f50594312",
"wait" : "20160508T163718Z",
"annotations" : [
{
"entry" : "20150623T181018Z",
"description" : "fooooooobar"
}
],
"urgency" : 3.16164
},
{
"id" : 3,
"description" : "I love kittens, really!",
"entry" : "20150919T222323Z",
"modified" : "20160327T163718Z",
"project" : "getkittens",
"status" : "waiting",
"tags" : ["kittens", "are", "so", "damn", "awesome"],
"uuid" : "08ee8dce-cb97-4c8c-9940-c9a440e90119",
"wait" : "20160508T163718Z",
"urgency" : 1.07397
}
]
"#;
let imported = import(s.as_bytes());
assert!(imported.is_ok());
let imported = imported.unwrap();
assert!(imported.len() == 3);
}
|