Skip to content

Commit 70f971e

Browse files
committed
Rework TestProducer
1 parent fa497bd commit 70f971e

File tree

6 files changed

+376
-102
lines changed

6 files changed

+376
-102
lines changed

ufotofu/src/common/consumer/test_consumer.rs

+1-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use core::cmp::min;
22
use core::fmt::Debug;
3-
use core::marker::PhantomData;
43
use core::num::NonZeroUsize;
54

65
#[cfg(all(feature = "alloc", not(feature = "std")))]
@@ -20,7 +19,7 @@ use crate::local_nb::{
2019
};
2120
use crate::sync::{BufferedConsumer, BulkConsumer, Consumer};
2221

23-
/// If you need to test code that works with arbitrary consumers, use this consumer. You can control the sequence of items it produces, the size of the slices it presents with `expose_slots`, and the error it emits. Beyond manual control, the [`Arbitrary`] implementation lets you test against various consumer behaviours automatically.
22+
/// If you need to test code that works with arbitrary consumers, use this one. You can choose which error it should emit, when it emits its error, the size of the slices it presents with `expose_slots`, and when to its async functions should yield instead of returning immediately. Beyond manual control, the [`Arbitrary`] implementation lets you test against various consumer behaviours automatically.
2423
///
2524
/// Create new [`TestConsumer`](crate::common::consumer::TestConsumer)s either via a [`TestConsumerBuilder`] or via the implementation of [`Arbitrary`].
2625
///
@@ -258,7 +257,6 @@ impl<Error> TestConsumerBuilder<Error> {
258257
operations_until_error: self.operations_until_error,
259258
exposed_slot_sizes: self.exposed_slot_sizes.map(|sizes| (sizes, 0)),
260259
yielder: self.yield_pattern.map(TestYielder::new),
261-
phantom: PhantomData,
262260
}))
263261
}
264262
}
@@ -270,7 +268,6 @@ struct TestConsumer<Item, Final, Error> {
270268
operations_until_error: usize,
271269
exposed_slot_sizes: Option<(Box<[NonZeroUsize]>, usize /* current index*/)>,
272270
yielder: Option<TestYielder>,
273-
phantom: PhantomData<Final>,
274271
}
275272

276273
impl<Item, Final, Error> TestConsumer<Item, Final, Error> {
@@ -320,7 +317,6 @@ impl<Item: Debug, Final: Debug, Error: Debug> Debug for TestConsumer<Item, Final
320317
.field("operations_until_error", &self.operations_until_error)
321318
.field("exposed_slot_sizes", &self.exposed_slot_sizes)
322319
.field("yielder", &self.yielder)
323-
// .field("phantom", &self.phantom) // Manually implementing to omit this PhantomData
324320
.finish()
325321
}
326322
}
@@ -445,19 +441,3 @@ where
445441
BulkConsumer::consume_slots(self, amount)
446442
}
447443
}
448-
449-
#[cfg(test)]
450-
mod tests {
451-
use ufotofu::sync::consumer::*;
452-
use ufotofu::sync::*;
453-
454-
#[test]
455-
fn foo() {
456-
let mut con: TestConsumer<u8, (), ()> = TestConsumerBuilder::new((), 999)
457-
.exposed_slot_sizes(std::vec![76.try_into().unwrap(), 1.try_into().unwrap()].into())
458-
.build();
459-
assert_eq!(76, con.expose_slots().unwrap().len());
460-
assert_eq!(1, con.expose_slots().unwrap().len());
461-
assert_eq!(76, con.expose_slots().unwrap().len());
462-
}
463-
}

ufotofu/src/common/producer.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod scramble;
2121
#[cfg(feature = "dev")]
2222
pub use scramble::{ProduceOperations, Scramble_ as Scramble};
2323

24-
#[cfg(feature = "dev")]
24+
#[cfg(all(feature = "dev", feature = "alloc"))]
2525
mod test_producer;
26-
#[cfg(feature = "dev")]
27-
pub use test_producer::TestProducer_ as TestProducer;
26+
#[cfg(all(feature = "dev", feature = "alloc"))]
27+
pub use test_producer::{TestProducerBuilder, TestProducer_ as TestProducer};

ufotofu/src/common/producer/from_boxed_slice.rs

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ impl<T> FromBoxedSlice_<T> {
3535

3636
FromBoxedSlice_(invariant)
3737
}
38+
39+
/// Return a slice of the data which has not yet been produced.
40+
pub fn remaining(&self) -> &[T] {
41+
return &self.0.as_ref().0[self.0.as_ref().1..];
42+
}
3843
}
3944

4045
invarianted_impl_as_ref!(FromBoxedSlice_<T>; [T]);

0 commit comments

Comments
 (0)