From 6050c737d24f7a9dd81e5e664ce090144fd33e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bram=20Bonn=C3=A9?= Date: Tue, 22 Jun 2021 13:33:28 +0200 Subject: [PATCH] Increase Chain test coverage. Chain coverage: Lines: 76% -> 100% Functions: 57.14% -> 93.33% Total coverage: Lines: 82.32% -> 83.9% Functions: 46.33% -> 49.41% --- tests/test_chain.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/test_chain.rs b/tests/test_chain.rs index b1c5a3d..e137248 100644 --- a/tests/test_chain.rs +++ b/tests/test_chain.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Error}; +use anyhow::{anyhow, Chain, Error}; fn error() -> Error { anyhow!(0).context(1).context(2).context(3) @@ -33,13 +33,36 @@ fn test_len() { let e = error(); let mut chain = e.chain(); assert_eq!(4, chain.len()); + assert_eq!((4, Some(4)), chain.size_hint()); assert_eq!("3", chain.next().unwrap().to_string()); assert_eq!(3, chain.len()); + assert_eq!((3, Some(3)), chain.size_hint()); assert_eq!("0", chain.next_back().unwrap().to_string()); assert_eq!(2, chain.len()); + assert_eq!((2, Some(2)), chain.size_hint()); assert_eq!("2", chain.next().unwrap().to_string()); assert_eq!(1, chain.len()); + assert_eq!((1, Some(1)), chain.size_hint()); assert_eq!("1", chain.next_back().unwrap().to_string()); assert_eq!(0, chain.len()); + assert_eq!((0, Some(0)), chain.size_hint()); assert!(chain.next().is_none()); } + +#[test] +fn test_default() { + let mut c: Chain = Default::default(); + assert!(c.next().is_none()); +} + +#[test] +fn test_clone() { + let e = error(); + let mut chain = e.chain().clone(); + assert_eq!("3", chain.next().unwrap().to_string()); + assert_eq!("2", chain.next().unwrap().to_string()); + assert_eq!("1", chain.next().unwrap().to_string()); + assert_eq!("0", chain.next().unwrap().to_string()); + assert!(chain.next().is_none()); + assert!(chain.next_back().is_none()); +}