use fluxion_core::{FluxionError, StreamItem};
use fluxion_stream::SkipItemsExt;
use fluxion_test_utils::{helpers::unwrap_stream, test_channel_with_errors, Sequenced};
#[tokio::test]
async fn test_skip_propagates_errors() -> anyhow::Result<()> {
let (tx, stream) = test_channel_with_errors::<Sequenced<i32>>();
let mut result = stream.skip_items(2);
tx.unbounded_send(StreamItem::Value(Sequenced::new(1)))?; tx.unbounded_send(StreamItem::Error(FluxionError::stream_error("error")))?; tx.unbounded_send(StreamItem::Value(Sequenced::new(2)))?; tx.unbounded_send(StreamItem::Error(FluxionError::stream_error("error2")))?;
let item1 = unwrap_stream(&mut result, 100).await;
assert!(matches!(item1, StreamItem::Value(_)));
let item2 = unwrap_stream(&mut result, 100).await;
assert!(matches!(item2, StreamItem::Error(_)));
Ok(())
}
#[tokio::test]
async fn test_skip_counts_errors_as_items() -> anyhow::Result<()> {
let (tx, stream) = test_channel_with_errors::<Sequenced<i32>>();
let mut result = stream.skip_items(3);
tx.unbounded_send(StreamItem::Error(FluxionError::stream_error("error1")))?;
tx.unbounded_send(StreamItem::Error(FluxionError::stream_error("error2")))?;
tx.unbounded_send(StreamItem::Error(FluxionError::stream_error("error3")))?;
tx.unbounded_send(StreamItem::Value(Sequenced::new(1)))?;
let item1 = unwrap_stream(&mut result, 100).await;
assert!(matches!(item1, StreamItem::Value(_)));
if let StreamItem::Value(v) = item1 {
assert_eq!(v.into_inner(), 1);
}
Ok(())
}