Skip to content

Commit

Permalink
Merge pull request #158 from BramBonne/chain-tests
Browse files Browse the repository at this point in the history
Increase Chain test coverage.
  • Loading branch information
dtolnay authored Jul 3, 2021
2 parents e9e706c + 6050c73 commit f01f908
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/test_chain.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{anyhow, Error};
use anyhow::{anyhow, Chain, Error};

fn error() -> Error {
anyhow!(0).context(1).context(2).context(3)
Expand Down Expand Up @@ -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());
}

0 comments on commit f01f908

Please sign in to comment.