diff --git a/src/component.rs b/src/component.rs index 6a7f672..248d563 100644 --- a/src/component.rs +++ b/src/component.rs @@ -6,6 +6,7 @@ use crate::error::Error; +use std::collections::VecDeque; use std::fmt; use std::marker::Send; use std::ops::{Deref, DerefMut}; @@ -93,35 +94,35 @@ impl fmt::Debug for Expect { #[derive(Debug)] pub struct TestComponent { - in_buffer: Vec, - out_buffer: Vec, - expect_buffer: Vec, + in_buffer: VecDeque, + out_buffer: VecDeque, + expect_buffer: VecDeque, } impl TestComponent { pub fn new(in_buffer: Vec) -> Self { TestComponent { - in_buffer, - out_buffer: Vec::new(), - expect_buffer: Vec::new(), + in_buffer: VecDeque::from(in_buffer), + out_buffer: VecDeque::new(), + expect_buffer: VecDeque::new(), } } /// Adds elements to be expected, in the order they're being added pub fn expect>(&mut self, el: E) { - self.expect_buffer.push(Expect::Element(el.into())) + self.expect_buffer.push_back(Expect::Element(el.into())) } pub fn expect_with(&mut self, callback: F) { self.expect_buffer - .push(Expect::Callback(Box::new(callback))) + .push_back(Expect::Callback(Box::new(callback))) } /// Asserts expected output and actual output are the same pub fn assert(&mut self) { loop { - let out = self.out_buffer.pop(); - let expected = self.expect_buffer.pop(); + let out = self.out_buffer.pop_front(); + let expected = self.expect_buffer.pop_front(); match (out, expected) { (None, None) => break, @@ -139,7 +140,7 @@ impl TestComponent { } fn _send_stanza + Send>(&mut self, el: E) -> Result<(), Error> { - Ok(self.out_buffer.push(el.into())) + Ok(self.out_buffer.push_back(el.into())) } } @@ -148,7 +149,7 @@ impl Stream for TestComponent { fn poll_next(mut self: Pin<&mut Self>, _cx: &mut Context) -> Poll> { while self.in_buffer.len() > 0 { - return Poll::Ready(self.in_buffer.pop()); + return Poll::Ready(self.in_buffer.pop_front()); } Poll::Ready(None)