Skip to content

Commit 9480006

Browse files
committed
Test with and filter_with explicitly
1 parent bb89f38 commit 9480006

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

src/lib.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,16 +492,14 @@ pub fn stream<Output>(sipper: impl Sipper<Output>) -> impl Stream<Item = Output>
492492
mod tests {
493493
use super::*;
494494

495-
use futures::channel::mpsc;
496-
497495
use tokio::task;
498496
use tokio::test;
499497

500-
type Progress = u32;
501-
502498
#[derive(Debug, PartialEq, Eq)]
503499
struct File(Vec<u8>);
504500

501+
type Progress = u32;
502+
505503
#[derive(Debug, PartialEq, Eq)]
506504
enum Error {
507505
Failed,
@@ -653,6 +651,36 @@ mod tests {
653651
assert_eq!(file, Err(Error::Failed));
654652
}
655653

654+
#[test]
655+
async fn it_can_be_mapped() {
656+
let mapper = |progress| progress * 2;
657+
658+
let download = download("https://iced.rs/logo.svg")
659+
.with(mapper)
660+
.collect::<Vec<_>>()
661+
.await;
662+
663+
assert_eq!(
664+
download.into_iter().sum::<u32>(),
665+
(0..=100).map(mapper).sum()
666+
);
667+
}
668+
669+
#[test]
670+
async fn it_can_be_filtered() {
671+
let filter = |progress| (progress % 2 == 0).then_some(progress);
672+
673+
let download = download("https://iced.rs/logo.svg")
674+
.filter_with(filter)
675+
.collect::<Vec<_>>()
676+
.await;
677+
678+
assert_eq!(
679+
download.into_iter().sum::<u32>(),
680+
(0..=100).filter_map(filter).sum()
681+
);
682+
}
683+
656684
#[test]
657685
async fn it_composes_nicely() {
658686
use futures::stream::{FuturesOrdered, StreamExt};

0 commit comments

Comments
 (0)