Skip to content

Commit

Permalink
fix(qustions): Better question parsing (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
dark0dave authored Jul 3, 2024
2 parents 3ee19ef + 6b0db30 commit 7df361f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
20 changes: 18 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
default_install_hook_types: [pre-commit, commit-msg]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
exclude: (?x)^(docs)
stages: [pre-commit]
- id: check-case-conflict
stages: [pre-commit]
- id: check-merge-conflict
stages: [pre-commit]
- id: detect-private-key
stages: [pre-commit]
- id: forbid-new-submodules
stages: [pre-commit]
- id: check-builtin-literals
stages: [pre-commit]

- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 3.0.0
hooks:
- id: forbid-binary
stages: [pre-commit]
exclude: (?x)^(docs)
- id: git-dirty
stages: [pre-commit]

- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.5
hooks:
- id: forbid-crlf
stages: [pre-commit]
- id: remove-crlf
stages: [pre-commit]

- repo: https://github.com/commitizen-tools/commitizen
rev: v3.22.0
rev: v3.27.0
hooks:
- id: commitizen
stages: [commit-msg]
Expand All @@ -33,12 +44,16 @@ repos:
rev: v1.0
hooks:
- id: fmt
stages: [pre-commit]
- id: cargo-check
stages: [pre-commit]
- id: clippy
stages: [pre-commit]

- repo: local
hooks:
- id: cargo-test
stages: [pre-commit]
name: cargo test
description: Run the test suite
entry: cargo test
Expand All @@ -47,8 +62,9 @@ repos:
pass_filenames: false

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.3.0
hooks:
- id: codespell
stages: [pre-commit]
args:
- '--ignore-words-list=crate'
27 changes: 16 additions & 11 deletions src/weidu_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ fn string_looks_like_question(weidu_output: &str) -> bool {
{
return false;
}
(WEIDU_CHOICE.contains(&comparable_output.as_str()))
|| WEIDU_CHOICE_SYMBOL.contains(&comparable_output.chars().last().unwrap_or_default())
|| comparable_output
.split(' ')
.take(1)
.any(|c| WEIDU_CHOICE.contains(&c))
return WEIDU_CHOICE
.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());
}

fn detect_weidu_finished_state(weidu_output: &str) -> Option<State> {
Expand Down Expand Up @@ -191,10 +191,15 @@ mod tests {

#[test]
fn is_a_question() {
let test = "Enter the full path to your Baldur's Gate installation then press Enter.";
assert_eq!(string_looks_like_question(test), true);
let test = "Enter the full path to your BG:EE+SoD installation then press Enter.\
Example: C:\\Program Files (x86)\\BeamDog\\Games\\00806";
assert_eq!(string_looks_like_question(test), true)
let tests = vec!["Enter the full path to your Baldur's Gate installation then press Enter.", "Enter the full path to your BG:EE+SoD installation then press Enter.\
Example: C:\\Program Files (x86)\\BeamDog\\Games\\00806", "[N]o, [Q]uit or choose one:", "Please enter the chance for items to randomly not be randomised as a integet number (e.g. 10 for 10%)"];
for question in tests {
assert_eq!(
string_looks_like_question(question),
true,
"String {} doesn't look like a string",
question
);
}
}
}

0 comments on commit 7df361f

Please sign in to comment.