Skip to content

Commit

Permalink
Merge pull request #103 from mobusoperandi/ResultAndNextPrompt
Browse files Browse the repository at this point in the history
refactor: variant ReplSessionExpecting::ResultAndNextPrompt
  • Loading branch information
ubbabeck authored May 12, 2024
2 parents 20318f1 + bbf3201 commit 19a721b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
21 changes: 10 additions & 11 deletions src/app/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl State {

let output = match &mut session_live.expecting {
ReplSessionExpecting::Nothing => anyhow::bail!("not expecting, got {:?}", ch as char),
ReplSessionExpecting::Prompt(acc) => {
ReplSessionExpecting::InitialPrompt(acc) => {
acc.push(ch.into());
let string = String::from_utf8(strip_ansi_escapes::strip(acc)?)?;

Expand All @@ -153,40 +153,39 @@ impl State {
vec![]
} else if Self::sanitize(acc)? == expected.as_str() {
session_live.expecting = if let Some(expected_result) = expected_result {
ReplSessionExpecting::Result {
ReplSessionExpecting::ResultAndNextPrompt {
acc: String::new(),
expected_result: expected_result.clone(),
}
} else {
ReplSessionExpecting::Prompt(String::new())
ReplSessionExpecting::InitialPrompt(String::new())
};
vec![]
} else {
anyhow::bail!("actual: {acc:?}, expected: {expected:?}");
}
}
ReplSessionExpecting::Result {
ReplSessionExpecting::ResultAndNextPrompt {
acc,
expected_result,
} => 'arm: {
acc.push(ch.into());

let Some(stripped_crlf_twice) = acc.strip_suffix("\r\n\r\n") else {
let sanitized = Self::sanitize(acc)?;

let Some(result) = sanitized.strip_suffix("\n\nnix-repl> ") else {
break 'arm vec![];
};

let sanitized = Self::sanitize(stripped_crlf_twice)?;

if sanitized != expected_result.as_str() {
if result != expected_result.as_str() {
anyhow::bail!(indoc::formatdoc! {"
{id}
actual (sanitized): {sanitized}
actual (sanitized): {result}
expected : {expected_result}"
})
}

session_live.expecting = ReplSessionExpecting::Prompt(String::new());
vec![]
self.next_query(&id)?
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/app/state/repl_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ pub(crate) struct ReplSessionLive {
#[derive(Debug)]
pub(crate) enum ReplSessionExpecting {
Nothing,
Prompt(String),
InitialPrompt(String),
Echo {
acc: String,
last_query: ReplQuery,
expected_result: Option<ExpectedResult>,
},
Result {
ResultAndNextPrompt {
acc: String,
expected_result: ExpectedResult,
},
Expand All @@ -61,7 +61,7 @@ impl ReplSessionLive {
pub(crate) fn new(entries: ReplExampleEntries) -> Self {
Self {
iterator: entries.into_iter(),
expecting: ReplSessionExpecting::Prompt(String::new()),
expecting: ReplSessionExpecting::InitialPrompt(String::new()),
}
}
}
Expand Down

0 comments on commit 19a721b

Please sign in to comment.