Add some unit tests
This commit is contained in:
84
Cargo.lock
generated
84
Cargo.lock
generated
@@ -234,6 +234,21 @@ version = "0.13.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
|
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bit-set"
|
||||||
|
version = "0.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de"
|
||||||
|
dependencies = [
|
||||||
|
"bit-vec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bit-vec"
|
||||||
|
version = "0.6.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.3.2"
|
version = "1.3.2"
|
||||||
@@ -275,6 +290,12 @@ version = "3.9.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899"
|
checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byteorder"
|
||||||
|
version = "1.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytes"
|
name = "bytes"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
@@ -340,6 +361,7 @@ dependencies = [
|
|||||||
"lazy_static",
|
"lazy_static",
|
||||||
"listenfd",
|
"listenfd",
|
||||||
"mktemp",
|
"mktemp",
|
||||||
|
"proptest",
|
||||||
"regex",
|
"regex",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rstest",
|
"rstest",
|
||||||
@@ -1096,6 +1118,38 @@ dependencies = [
|
|||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proptest"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e0d9cc07f18492d879586c92b485def06bc850da3118075cd45d50e9c95b0e5"
|
||||||
|
dependencies = [
|
||||||
|
"bit-set",
|
||||||
|
"bitflags",
|
||||||
|
"byteorder",
|
||||||
|
"lazy_static",
|
||||||
|
"num-traits",
|
||||||
|
"quick-error 2.0.1",
|
||||||
|
"rand",
|
||||||
|
"rand_chacha",
|
||||||
|
"rand_xorshift",
|
||||||
|
"regex-syntax",
|
||||||
|
"rusty-fork",
|
||||||
|
"tempfile",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quick-error"
|
||||||
|
version = "1.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quick-error"
|
||||||
|
version = "2.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.14"
|
version = "1.0.14"
|
||||||
@@ -1145,6 +1199,15 @@ dependencies = [
|
|||||||
"rand_core",
|
"rand_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_xorshift"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f"
|
||||||
|
dependencies = [
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.2.10"
|
version = "0.2.10"
|
||||||
@@ -1246,6 +1309,18 @@ dependencies = [
|
|||||||
"semver",
|
"semver",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rusty-fork"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f"
|
||||||
|
dependencies = [
|
||||||
|
"fnv",
|
||||||
|
"quick-error 1.2.3",
|
||||||
|
"tempfile",
|
||||||
|
"wait-timeout",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
version = "1.0.9"
|
version = "1.0.9"
|
||||||
@@ -1729,6 +1804,15 @@ version = "0.9.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wait-timeout"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "want"
|
name = "want"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
|||||||
@@ -36,5 +36,6 @@ anyhow = "1.0"
|
|||||||
http = "0.2.0"
|
http = "0.2.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
proptest = "1.0.0"
|
||||||
reqwest = { version = "0.11.0", features = ["json"] }
|
reqwest = { version = "0.11.0", features = ["json"] }
|
||||||
rstest = "0.12.0"
|
rstest = "0.12.0"
|
||||||
|
|||||||
@@ -260,3 +260,100 @@ pub async fn add_task(add_args: Vec<&str>) -> Result<TaskwarriorTask, Taskwarrio
|
|||||||
))
|
))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
|
||||||
|
mod from_taskwarrior_task_to_contextswitch_task {
|
||||||
|
use super::super::*;
|
||||||
|
use chrono::TimeZone;
|
||||||
|
use contextswitch_types::Bookmark;
|
||||||
|
use http::uri::Uri;
|
||||||
|
use proptest::prelude::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_successful_full_convertion() {
|
||||||
|
let tw_task = TaskwarriorTask {
|
||||||
|
uuid: TaskwarriorTaskId(Uuid::new_v4()),
|
||||||
|
id: TaskwarriorTaskLocalId(42),
|
||||||
|
entry: Utc.ymd(2022, 1, 1).and_hms(1, 0, 0),
|
||||||
|
modified: Utc.ymd(2022, 1, 1).and_hms(1, 0, 1),
|
||||||
|
status: contextswitch_types::Status::Pending,
|
||||||
|
description: String::from("simple task"),
|
||||||
|
urgency: 0.5,
|
||||||
|
due: Some(Utc.ymd(2022, 1, 1).and_hms(1, 0, 2)),
|
||||||
|
start: Some(Utc.ymd(2022, 1, 1).and_hms(1, 0, 3)),
|
||||||
|
end: Some(Utc.ymd(2022, 1, 1).and_hms(1, 0, 4)),
|
||||||
|
wait: Some(Utc.ymd(2022, 1, 1).and_hms(1, 0, 5)),
|
||||||
|
parent: Some(Uuid::new_v4()),
|
||||||
|
project: Some(String::from("simple project")),
|
||||||
|
priority: Some(contextswitch_types::Priority::H),
|
||||||
|
recur: Some(contextswitch_types::Recurrence::Daily),
|
||||||
|
tags: Some(vec!["tag1".to_string(), "tag2".to_string()]),
|
||||||
|
contextswitch: Some(String::from(
|
||||||
|
r#"{"bookmarks": [{"uri": "https://www.example.com/path"}]}"#,
|
||||||
|
)),
|
||||||
|
};
|
||||||
|
let cs_task: Task = (&tw_task).into();
|
||||||
|
|
||||||
|
assert_eq!(tw_task.uuid.0, cs_task.id.0);
|
||||||
|
assert_eq!(tw_task.entry, cs_task.entry);
|
||||||
|
assert_eq!(tw_task.modified, cs_task.modified);
|
||||||
|
assert_eq!(tw_task.status, cs_task.status);
|
||||||
|
assert_eq!(tw_task.description, cs_task.description);
|
||||||
|
assert_eq!(tw_task.urgency, cs_task.urgency);
|
||||||
|
assert_eq!(tw_task.due, cs_task.due);
|
||||||
|
assert_eq!(tw_task.start, cs_task.start);
|
||||||
|
assert_eq!(tw_task.end, cs_task.end);
|
||||||
|
assert_eq!(tw_task.wait, cs_task.wait);
|
||||||
|
assert_eq!(tw_task.parent, cs_task.parent);
|
||||||
|
assert_eq!(tw_task.project, cs_task.project);
|
||||||
|
assert_eq!(tw_task.priority, cs_task.priority);
|
||||||
|
assert_eq!(tw_task.recur, cs_task.recur);
|
||||||
|
assert_eq!(tw_task.tags, cs_task.tags);
|
||||||
|
assert_eq!(
|
||||||
|
Some(ContextswitchData {
|
||||||
|
bookmarks: vec![Bookmark {
|
||||||
|
uri: "https://www.example.com/path".parse::<Uri>().unwrap(),
|
||||||
|
content: None
|
||||||
|
}]
|
||||||
|
}),
|
||||||
|
cs_task.contextswitch
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
proptest! {
|
||||||
|
#[test]
|
||||||
|
fn test_conversion_with_invalid_contextswitch_data_format(cs_data in ".*") {
|
||||||
|
let tw_task = TaskwarriorTask {
|
||||||
|
uuid: TaskwarriorTaskId(Uuid::new_v4()),
|
||||||
|
id: TaskwarriorTaskLocalId(42),
|
||||||
|
entry: Utc.ymd(2022, 1, 1).and_hms(1, 0, 0),
|
||||||
|
modified: Utc.ymd(2022, 1, 1).and_hms(1, 0, 1),
|
||||||
|
status: contextswitch_types::Status::Pending,
|
||||||
|
description: String::from("simple task"),
|
||||||
|
urgency: 0.5,
|
||||||
|
due: None,
|
||||||
|
start: None,
|
||||||
|
end: None,
|
||||||
|
wait: None,
|
||||||
|
parent: None,
|
||||||
|
project: None,
|
||||||
|
priority: None,
|
||||||
|
recur: None,
|
||||||
|
tags: None,
|
||||||
|
contextswitch: Some(cs_data.to_string()),
|
||||||
|
};
|
||||||
|
let cs_task: Task = (&tw_task).into();
|
||||||
|
|
||||||
|
assert_eq!(tw_task.uuid.0, cs_task.id.0);
|
||||||
|
assert_eq!(tw_task.entry, cs_task.entry);
|
||||||
|
assert_eq!(tw_task.modified, cs_task.modified);
|
||||||
|
assert_eq!(tw_task.status, cs_task.status);
|
||||||
|
assert_eq!(tw_task.description, cs_task.description);
|
||||||
|
assert_eq!(tw_task.urgency, cs_task.urgency);
|
||||||
|
assert_eq!(None, cs_task.contextswitch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user