From 3e27c21565305c530f6d2fc8d0255a27c1306c73 Mon Sep 17 00:00:00 2001 From: David Rousselie Date: Sat, 19 Feb 2022 20:35:32 +0100 Subject: [PATCH] Add some unit tests --- Cargo.lock | 84 +++++++++++++++++++++++++++ Cargo.toml | 1 + src/contextswitch/taskwarrior.rs | 97 ++++++++++++++++++++++++++++++++ 3 files changed, 182 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index dc70ee3..54f5768 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -234,6 +234,21 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" 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]] name = "bitflags" version = "1.3.2" @@ -275,6 +290,12 @@ version = "3.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "bytes" version = "1.1.0" @@ -340,6 +361,7 @@ dependencies = [ "lazy_static", "listenfd", "mktemp", + "proptest", "regex", "reqwest", "rstest", @@ -1096,6 +1118,38 @@ dependencies = [ "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]] name = "quote" version = "1.0.14" @@ -1145,6 +1199,15 @@ dependencies = [ "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]] name = "redox_syscall" version = "0.2.10" @@ -1246,6 +1309,18 @@ dependencies = [ "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]] name = "ryu" version = "1.0.9" @@ -1729,6 +1804,15 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" 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]] name = "want" version = "0.3.0" diff --git a/Cargo.toml b/Cargo.toml index 5846aef..32012c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,5 +36,6 @@ anyhow = "1.0" http = "0.2.0" [dev-dependencies] +proptest = "1.0.0" reqwest = { version = "0.11.0", features = ["json"] } rstest = "0.12.0" diff --git a/src/contextswitch/taskwarrior.rs b/src/contextswitch/taskwarrior.rs index 83adaf8..ee940a8 100644 --- a/src/contextswitch/taskwarrior.rs +++ b/src/contextswitch/taskwarrior.rs @@ -260,3 +260,100 @@ pub async fn add_task(add_args: Vec<&str>) -> Result().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); + } + } + } +}