Sha256: b7894874132918b8229c7150b2637511d8e3e14197d8eeb9382d46b2a514efa2

Contents?: true

Size: 1.54 KB

Versions: 38

Compression:

Stored size: 1.54 KB

Contents

use itertools::{assert_equal, Itertools};
use std::{ops::Range, vec::IntoIter};

fn mix_data() -> IntoIter<Result<Range<i32>, bool>> {
    vec![Ok(0..2), Err(false), Ok(2..4), Err(true), Ok(4..6)].into_iter()
}

fn ok_data() -> IntoIter<Result<Range<i32>, bool>> {
    vec![Ok(0..2), Ok(2..4), Ok(4..6)].into_iter()
}

#[test]
fn flatten_ok_mixed_expected_forward() {
    assert_equal(
        mix_data().flatten_ok(),
        vec![
            Ok(0),
            Ok(1),
            Err(false),
            Ok(2),
            Ok(3),
            Err(true),
            Ok(4),
            Ok(5),
        ],
    );
}

#[test]
fn flatten_ok_mixed_expected_reverse() {
    assert_equal(
        mix_data().flatten_ok().rev(),
        vec![
            Ok(5),
            Ok(4),
            Err(true),
            Ok(3),
            Ok(2),
            Err(false),
            Ok(1),
            Ok(0),
        ],
    );
}

#[test]
fn flatten_ok_collect_mixed_forward() {
    assert_eq!(
        mix_data().flatten_ok().collect::<Result<Vec<_>, _>>(),
        Err(false)
    );
}

#[test]
fn flatten_ok_collect_mixed_reverse() {
    assert_eq!(
        mix_data().flatten_ok().rev().collect::<Result<Vec<_>, _>>(),
        Err(true)
    );
}

#[test]
fn flatten_ok_collect_ok_forward() {
    assert_eq!(
        ok_data().flatten_ok().collect::<Result<Vec<_>, _>>(),
        Ok((0..6).collect())
    );
}

#[test]
fn flatten_ok_collect_ok_reverse() {
    assert_eq!(
        ok_data().flatten_ok().rev().collect::<Result<Vec<_>, _>>(),
        Ok((0..6).rev().collect())
    );
}

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/itertools-0.12.1/tests/flatten_ok.rs
wasmtime-28.0.0 ./ext/cargo-vendor/itertools-0.12.1/tests/flatten_ok.rs
wasmtime-27.0.0 ./ext/cargo-vendor/itertools-0.12.1/tests/flatten_ok.rs
wasmtime-26.0.0 ./ext/cargo-vendor/itertools-0.12.1/tests/flatten_ok.rs
wasmtime-25.0.2 ./ext/cargo-vendor/itertools-0.12.1/tests/flatten_ok.rs
wasmtime-25.0.1 ./ext/cargo-vendor/itertools-0.12.1/tests/flatten_ok.rs
wasmtime-25.0.0 ./ext/cargo-vendor/itertools-0.12.1/tests/flatten_ok.rs
wasmtime-24.0.0 ./ext/cargo-vendor/itertools-0.12.1/tests/flatten_ok.rs
wasmtime-23.0.2 ./ext/cargo-vendor/itertools-0.12.1/tests/flatten_ok.rs
wasmtime-22.0.0 ./ext/cargo-vendor/itertools-0.12.1/tests/flatten_ok.rs
wasmtime-21.0.1 ./ext/cargo-vendor/itertools-0.12.1/tests/flatten_ok.rs
wasmtime-20.0.2 ./ext/cargo-vendor/itertools-0.12.1/tests/flatten_ok.rs
wasmtime-20.0.0 ./ext/cargo-vendor/itertools-0.12.1/tests/flatten_ok.rs
wasmtime-18.0.3 ./ext/cargo-vendor/itertools-0.10.5/tests/flatten_ok.rs
wasmtime-17.0.1 ./ext/cargo-vendor/itertools-0.10.5/tests/flatten_ok.rs
wasmtime-17.0.0 ./ext/cargo-vendor/itertools-0.10.5/tests/flatten_ok.rs
wasmtime-16.0.0 ./ext/cargo-vendor/itertools-0.10.5/tests/flatten_ok.rs
wasmtime-15.0.1 ./ext/cargo-vendor/itertools-0.10.5/tests/flatten_ok.rs
wasmtime-15.0.0 ./ext/cargo-vendor/itertools-0.10.5/tests/flatten_ok.rs
wasmtime-14.0.4 ./ext/cargo-vendor/itertools-0.10.5/tests/flatten_ok.rs