Skip to content
Myr

Add chain iterator test

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Tolnay · committed by David Tolnay · parent 7c8064f · Browse files · 1 file+45 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+45 added−0 removed

  • tests:+45 added−0 removed

1 file+45 added−0 removed

added:tests/test_chain.rs+45 added
1use anyhow::{anyhow, Error};23fn error() -> Error {4 anyhow!(0).context(1).context(2).context(3)5}67#[test]8fn test_iter() {9 let e = error();10 let mut chain = e.chain();11 assert_eq!("3", chain.next().unwrap().to_string());12 assert_eq!("2", chain.next().unwrap().to_string());13 assert_eq!("1", chain.next().unwrap().to_string());14 assert_eq!("0", chain.next().unwrap().to_string());15 assert!(chain.next().is_none());16 assert!(chain.next_back().is_none());17}1819#[test]20fn test_rev() {21 let e = error();22 let mut chain = e.chain().rev();23 assert_eq!("0", chain.next().unwrap().to_string());24 assert_eq!("1", chain.next().unwrap().to_string());25 assert_eq!("2", chain.next().unwrap().to_string());26 assert_eq!("3", chain.next().unwrap().to_string());27 assert!(chain.next().is_none());28 assert!(chain.next_back().is_none());29}3031#[test]32fn test_len() {33 let e = error();34 let mut chain = e.chain();35 assert_eq!(4, chain.len());36 assert_eq!("3", chain.next().unwrap().to_string());37 assert_eq!(3, chain.len());38 assert_eq!("0", chain.next_back().unwrap().to_string());39 assert_eq!(2, chain.len());40 assert_eq!("2", chain.next().unwrap().to_string());41 assert_eq!(1, chain.len());42 assert_eq!("1", chain.next_back().unwrap().to_string());43 assert_eq!(0, chain.len());44 assert!(chain.next().is_none());45}