Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
c-git committed Dec 16, 2023
1 parent e493e5e commit 52f7f70
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 0 deletions.
218 changes: 218 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ log = "0.4.20"
log4rs = "1.2.0"
one_log = { version = "*", path = "crates/one_log" }
regex = "1.10.2"
rstest = "0.18.2"
3 changes: 3 additions & 0 deletions crates/snake_case/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ log.workspace = true
log4rs.workspace = true
one_log.workspace = true
regex.workspace = true

[dev-dependencies]
rstest.workspace = true
22 changes: 22 additions & 0 deletions crates/snake_case/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,25 @@ fn convert_to_snake_case(org_str: &str) -> String {
let re = Regex::new("[^0-9a-zA-Z_ ]").unwrap();
re.replace_all(org_str, "").to_case(Case::Snake)
}

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

#[rstest]
#[case("Simple Case", "simple_case")]
#[case("With !@#$%^&*()_+/\\ Special *Chars", "with_special_chars")]
#[case(
"Task 2: Unanimously Legendary IDentifier (ULID) ",
"task_2_unanimously_legendary_i_dentifier_ulid"
)]
#[case(
"Task 2: Unanimously Legendary IDentifier [ULID] ",
"task_2_unanimously_legendary_i_dentifier_ulid"
)]
fn conversion(#[case] input: &str, #[case] expected: &str) {
let actual = convert_to_snake_case(input);
assert_eq!(actual, expected);
}
}

0 comments on commit 52f7f70

Please sign in to comment.