pub struct MockByString { /* private fields */ }Expand description
On every call of its read_line method, a MockByString object pops and returns
another element from the Vec<String> it was instantiated with,
thus providing input for Laconic’s r (read) operator.
It is used by many unit tests that execute a script containing the r operator, thus
avoiding the test execution to wait for user input. E.g.:
use laconic::{Interpreter, input::MockByString};
let fake_input = vec![
"Rebonjour".to_string(),
"Bonjour".to_string(),
];
let mut interpreter = Interpreter::new(
Box::new(Vec::<u8>::new()),
Box::new(MockByString::new(fake_input)),
Box::new(string_io_and_mock::MockTextHandler::new())
);
let outcome_result = interpreter.execute("
r r
".to_string());
assert!(outcome_result.is_ok());
assert_eq!(
"Rebonjour".to_string(),
outcome_result.unwrap().string_representation());Implementations§
Trait Implementations§
Source§impl StdinOrMock for MockByString
impl StdinOrMock for MockByString
Auto Trait Implementations§
impl Freeze for MockByString
impl RefUnwindSafe for MockByString
impl Send for MockByString
impl Sync for MockByString
impl Unpin for MockByString
impl UnsafeUnpin for MockByString
impl UnwindSafe for MockByString
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more