Skip to content

Commit

Permalink
簡単なテストコードとtestingライブラリの導入
Browse files Browse the repository at this point in the history
参考になりそうな簡単なテストコードと独断ですがtestingライブラリを導入しました
  • Loading branch information
qwerty2501 committed May 15, 2022
1 parent 6f0c612 commit a30130b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/voicevox_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ derive-new = "0.5.9"
once_cell = "1.10.0"
thiserror = "1.0.31"

[dev-dependencies]
rstest = "0.12.0"
pretty_assertions = "1.2.1"

[build-dependencies]
cbindgen = "0.23.0"
18 changes: 18 additions & 0 deletions crates/voicevox_core/src/c_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::sync::Mutex;
*/

#[repr(C)]
#[derive(Debug, PartialEq)]
#[allow(non_camel_case_types)]
pub enum VoicevoxResultCode {
// C でのenum定義に合わせて大文字で定義している
Expand Down Expand Up @@ -214,3 +215,20 @@ pub extern "C" fn voicevox_error_result_to_message(
) -> *const c_char {
internal::voicevox_error_result_to_message(result_code).as_ptr() as *const c_char
}

#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;

#[rstest]
#[case(Ok(()), VoicevoxResultCode::VOICEVOX_RESULT_SUCCEED)]
#[case(
Err(Error::NotLoadedOpenjtalkDict),
VoicevoxResultCode::VOICEVOX_RESULT_NOT_LOADED_OPENJTALK_DICT
)]
fn convert_result_works(#[case] result: Result<()>, #[case] expected: VoicevoxResultCode) {
let (_, actual) = convert_result(result);
assert_eq!(expected, actual);
}
}
3 changes: 3 additions & 0 deletions crates/voicevox_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ mod result;

use error::*;
use result::*;

#[cfg(test)]
use rstest::*;

0 comments on commit a30130b

Please sign in to comment.