This commit is contained in:
Richard Feldman 2022-10-31 08:04:28 -04:00
parent eaa0824347
commit e9e4e710e2
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
2 changed files with 8 additions and 10 deletions

View file

@ -132,7 +132,7 @@ pub fn expect_success(input: &str, expected: &str) {
// The state.rs tests do that! // The state.rs tests do that!
let mut iter = out.stdout.lines().rev(); let mut iter = out.stdout.lines().rev();
let line = iter.next().unwrap(); let line = iter.next().unwrap();
let comment_index = line.rfind("#").unwrap_or_else(|| line.len()); let comment_index = line.rfind('#').unwrap_or(line.len());
let line_without_comment = line[0..comment_index].trim_end(); let line_without_comment = line[0..comment_index].trim_end();
// Sometimes the "# val1" wraps around to its own line; if this happens, // Sometimes the "# val1" wraps around to its own line; if this happens,

View file

@ -112,22 +112,21 @@ fn complete(input: &str, state: &mut ReplState, expected_step_result: Result<(&s
match state.step(input) { match state.step(input) {
Ok(string) => { Ok(string) => {
let escaped = std::string::String::from_utf8( let escaped =
strip_ansi_escapes::strip(string.trim()).unwrap().into(), std::string::String::from_utf8(strip_ansi_escapes::strip(string.trim()).unwrap())
) .unwrap();
.unwrap();
let comment_index = escaped.rfind('#').unwrap_or_else(|| escaped.len()); let comment_index = escaped.rfind('#').unwrap_or(escaped.len());
assert_eq!( assert_eq!(
expected_step_result.map(|(starts_with, _)| starts_with), expected_step_result.map(|(starts_with, _)| starts_with),
Ok(*&escaped[0..comment_index].trim()) Ok(escaped[0..comment_index].trim())
); );
assert_eq!( assert_eq!(
expected_step_result.map(|(_, ends_with)| ends_with), expected_step_result.map(|(_, ends_with)| ends_with),
// +1 because we want to skip over the '#' itself // +1 because we want to skip over the '#' itself
Ok(*&escaped[comment_index + 1..].trim()) Ok(escaped[comment_index + 1..].trim())
); );
} }
Err(err) => { Err(err) => {
@ -150,8 +149,7 @@ fn error(input: &str, state: &mut ReplState, expected_step_result: String) {
assert!(!is_incomplete(input)); assert!(!is_incomplete(input));
let escaped = state.step(input).map(|string| { let escaped = state.step(input).map(|string| {
std::string::String::from_utf8(strip_ansi_escapes::strip(string.trim()).unwrap().into()) std::string::String::from_utf8(strip_ansi_escapes::strip(string.trim()).unwrap()).unwrap()
.unwrap()
}); });
assert_eq!(Ok(expected_step_result), escaped); assert_eq!(Ok(expected_step_result), escaped);