diff --git a/psogc_quest_tool/Cargo.toml b/psogc_quest_tool/Cargo.toml index 893b98e..5a103d2 100644 --- a/psogc_quest_tool/Cargo.toml +++ b/psogc_quest_tool/Cargo.toml @@ -11,4 +11,7 @@ anyhow = "1.0.40" crc = "1.8.1" [dependencies.psoutils] -path = "../psoutils" \ No newline at end of file +path = "../psoutils" + +[dev-dependencies] +claim = "0.5.0" diff --git a/psogc_quest_tool/src/info.rs b/psogc_quest_tool/src/info.rs index 1a6a9a2..e05dbc0 100644 --- a/psogc_quest_tool/src/info.rs +++ b/psogc_quest_tool/src/info.rs @@ -165,3 +165,48 @@ pub fn quest_info(args: &[String]) -> Result<()> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + use claim::*; + + // TODO: some way to match the specific error message string? or probably should just replace + // anyhow usage with a specific error type ... + + #[test] + pub fn no_args_fails_with_error() { + let args: &[String] = &[]; + assert_matches!(quest_info(args), Err(_)); + } + + #[test] + pub fn too_many_args_fails_with_error() { + let args = &["a".to_string(), "b".to_string(), "c".to_string()]; + assert_matches!(quest_info(args), Err(_)); + } + + #[test] + pub fn succeeds_with_single_file_arg() { + let args = &["../psoutils/test-assets/q058-ret-gc.online.qst".to_string()]; + assert_ok!(quest_info(args)); + } + + #[test] + pub fn succeeds_with_two_file_args() { + let args = &[ + "../psoutils/test-assets/q058-ret-gc.bin".to_string(), + "../psoutils/test-assets/q058-ret-gc.dat".to_string(), + ]; + assert_ok!(quest_info(args)); + } + + #[test] + pub fn fails_when_bin_dat_file_args_in_wrong_order() { + let args = &[ + "../psoutils/test-assets/q058-ret-gc.dat".to_string(), + "../psoutils/test-assets/q058-ret-gc.bin".to_string(), + ]; + assert_matches!(quest_info(args), Err(_)); + } +}