add new test helper

This commit is contained in:
Bennet Bleßmann
2025-01-27 21:27:29 +01:00
committed by Bennet Bleßmann
parent bd1f8bb37e
commit e1246f0c83
2 changed files with 24 additions and 4 deletions

View File

@@ -78,7 +78,7 @@ impl OutputStreamConfig {
#[derive(Debug)]
enum InputStreamConfigInner {
String(String),
String(Cow<'static, str>),
Stdin,
Channel(Receiver<Vec<u8>>),
}
@@ -97,7 +97,7 @@ pub struct InputStreamConfig {
impl InputStreamConfig {
/// Gets input from string.
pub fn string(s: impl Into<String>) -> Self {
pub fn string(s: impl Into<Cow<'static, str>>) -> Self {
Self {
inner: InputStreamConfigInner::String(s.into()),
}
@@ -123,7 +123,10 @@ impl InputStreamConfig {
fn into_stream(self, arena: &mut Arena, add_history: bool) -> Stream {
match self.inner {
InputStreamConfigInner::String(s) => Stream::from_owned_string(s, arena),
InputStreamConfigInner::String(s) => match s {
Cow::Owned(s) => Stream::from_owned_string(s, arena),
Cow::Borrowed(s) => Stream::from_static_string(s, arena),
},
InputStreamConfigInner::Stdin => Stream::stdin(arena, add_history),
InputStreamConfigInner::Channel(channel) => Stream::input_channel(channel, arena),
}
@@ -156,7 +159,7 @@ impl StreamConfig {
/// Binds the output and error streams to memory buffers and has an empty input.
pub fn in_memory() -> Self {
StreamConfig {
user_input: InputStreamConfig::string(""),
user_input: InputStreamConfig::string(String::new()),
user_output: OutputStreamConfig::memory(),
user_error: OutputStreamConfig::memory(),
}