diff options
| author | Stjepan Glavina <stjepang@gmail.com> | 2019-01-13 11:16:14 +0100 |
|---|---|---|
| committer | Stjepan Glavina <stjepang@gmail.com> | 2019-01-13 16:58:08 +0100 |
| commit | 04c74f46f0a0ecf886f1c12b51483d38690fac22 (patch) | |
| tree | 4519dc9dad6f4fe396b3150f229bd4ecaa566541 /src/libcore/tests | |
| parent | 75a369c5b11459baa6bf7734eeb6135998a0a7de (diff) | |
| download | rust-04c74f46f0a0ecf886f1c12b51483d38690fac22.tar.gz rust-04c74f46f0a0ecf886f1c12b51483d38690fac22.zip | |
Add core::iter::once_with
Diffstat (limited to 'src/libcore/tests')
| -rw-r--r-- | src/libcore/tests/iter.rs | 17 | ||||
| -rw-r--r-- | src/libcore/tests/lib.rs | 1 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs index cf19851c17b..b62f55b2cd0 100644 --- a/src/libcore/tests/iter.rs +++ b/src/libcore/tests/iter.rs @@ -1907,6 +1907,23 @@ fn test_once() { } #[test] +fn test_once_with() { + let mut count = 0; + let mut it = once_with(|| { + count += 1; + 42 + }); + + assert_eq!(count, 0); + assert_eq!(it.next(), Some(42)); + assert_eq!(count, 1); + assert_eq!(it.next(), None); + assert_eq!(count, 1); + assert_eq!(it.next(), None); + assert_eq!(count, 1); +} + +#[test] fn test_empty() { let mut it = empty::<i32>(); assert_eq!(it.next(), None); diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs index 72846daf16a..a9b8decfd02 100644 --- a/src/libcore/tests/lib.rs +++ b/src/libcore/tests/lib.rs @@ -12,6 +12,7 @@ #![feature(hashmap_internals)] #![feature(iter_copied)] #![feature(iter_nth_back)] +#![feature(iter_once_with)] #![feature(iter_unfold)] #![feature(pattern)] #![feature(range_is_empty)] |
