Skip to content

Commit

Permalink
fix(question): Better question parsing add tests for non questions
Browse files Browse the repository at this point in the history
Signed-off-by: dark0dave <dark0dave@mykolab.com>
  • Loading branch information
dark0dave committed Jul 5, 2024
1 parent ed57b12 commit 3a35dd6
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 80 deletions.
129 changes: 57 additions & 72 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mod_installer"
version = "6.0.1"
version = "6.0.3"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
27 changes: 20 additions & 7 deletions src/weidu_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ const WEIDU_CHOICE: [&str; 6] = [
"enter",
];

const WEIDU_CHOICE_SYMBOL: [char; 2] = ['?', ':'];

const WEIDU_COMPLETED_WITH_WARNINGS: &str = "installed with warnings";

const WEIDU_FAILED_WITH_ERROR: &str = "not installed due to errors";
Expand Down Expand Up @@ -73,8 +71,8 @@ pub fn parse_raw_output(
}
}
ParserState::LookingForInterestingOutput => {
let may_be_weidu_finished_state = detect_weidu_finished_state(&string);
if let Some(weidu_finished_state) = may_be_weidu_finished_state {
log::trace!("{}", string);
if let Some(weidu_finished_state) = detect_weidu_finished_state(&string) {
sender
.send(weidu_finished_state)
.expect("Failed to send process error event");
Expand Down Expand Up @@ -143,8 +141,7 @@ fn string_looks_like_question(weidu_output: &str) -> bool {
.iter()
.map(|choice| comparable_output.contains(choice))
.reduce(|a, b| a | b)
.unwrap_or(false)
|| WEIDU_CHOICE_SYMBOL.contains(&comparable_output.chars().last().unwrap_or_default());
.unwrap_or(false);
}

fn detect_weidu_finished_state(weidu_output: &str) -> Option<State> {
Expand Down Expand Up @@ -197,7 +194,23 @@ Example: C:\\Program Files (x86)\\BeamDog\\Games\\00806", "[N]o, [Q]uit or choos
assert_eq!(
string_looks_like_question(question),
true,
"String {} doesn't look like a string",
"String {} doesn't look like a question",
question
);
}
}

#[test]
fn is_not_a_question() {
let tests = vec![
"FAILURE:",
"NOT INSTALLED DUE TO ERRORS The BG1 NPC Project: Required Modifications",
];
for question in tests {
assert_eq!(
string_looks_like_question(question),
false,
"String {} does look like a question",
question
);
}
Expand Down

0 comments on commit 3a35dd6

Please sign in to comment.