diff --git a/src/exactly_one_err.rs b/src/exactly_one_err.rs index 51cfbc347..6b7bad56d 100644 --- a/src/exactly_one_err.rs +++ b/src/exactly_one_err.rs @@ -24,7 +24,7 @@ where I: Iterator, { /// Creates a new `ExactlyOneErr` iterator. - pub fn new(first_two: (Option, Option), inner: I) -> Self { + pub(crate) fn new(first_two: (Option, Option), inner: I) -> Self { Self { first_two, inner } } } diff --git a/src/lib.rs b/src/lib.rs index 59625a4c1..fa09d1028 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2056,7 +2056,7 @@ pub trait Itertools : Iterator { /// assert_eq!((0..10).filter(|&x| x == 2).exactly_one().unwrap(), 2); /// assert!((0..10).filter(|&x| x > 1 && x < 4).exactly_one().unwrap_err().eq(2..4)); /// assert!((0..10).filter(|&x| x > 1 && x < 5).exactly_one().unwrap_err().eq(2..5)); - /// assert!((0..10).filter(|&x| false).exactly_one().unwrap_err().eq(0..0)); + /// assert!((0..10).filter(|&_| false).exactly_one().unwrap_err().eq(0..0)); /// ``` fn exactly_one(mut self) -> Result> where diff --git a/tests/quick.rs b/tests/quick.rs index e0c61b47d..886c40533 100644 --- a/tests/quick.rs +++ b/tests/quick.rs @@ -1015,3 +1015,13 @@ quickcheck! { TestResult::from_bool(actual == expected) } } + +quickcheck! { + fn exactly_one_i32(a: Vec) -> TestResult { + let ret = a.iter().cloned().exactly_one(); + match a.len() { + 1 => TestResult::from_bool(ret.unwrap() == a[0]), + _ => TestResult::from_bool(ret.unwrap_err().eq(a.iter().cloned())), + } + } +} diff --git a/tests/test_core.rs b/tests/test_core.rs index cf97abd36..7007217da 100644 --- a/tests/test_core.rs +++ b/tests/test_core.rs @@ -244,3 +244,11 @@ fn tree_fold1() { assert_eq!((0..i).tree_fold1(|x, y| x + y), (0..i).fold1(|x, y| x + y)); } } + +#[test] +fn exactly_one() { + assert_eq!((0..10).filter(|&x| x == 2).exactly_one().unwrap(), 2); + assert!((0..10).filter(|&x| x > 1 && x < 4).exactly_one().unwrap_err().eq(2..4)); + assert!((0..10).filter(|&x| x > 1 && x < 5).exactly_one().unwrap_err().eq(2..5)); + assert!((0..10).filter(|&_| false).exactly_one().unwrap_err().eq(0..0)); +}