-
-
Save rust-play/adcb26e4d064873c4a197cc5ffbff95c to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn ccbreaker (value: &str) -> String { | |
value.chars() | |
.into_iter() | |
.map(|c| if c.is_uppercase() { format!(" {}", c.to_lowercase()) } else { c.to_string() }) | |
.collect::<String>() | |
} | |
#[cfg(test)] | |
mod tests { | |
use super::*; | |
#[test] | |
fn example_1() { | |
assert_eq!(ccbreaker("camelCasing"), "camel casing".to_string()); | |
} | |
#[test] | |
fn example_2() { | |
assert_eq!(ccbreaker("garbageTruck"), "garbage truck".to_string()); | |
} | |
#[test] | |
fn test_1() { | |
assert_eq!(ccbreaker("policeSiren"), "police siren".to_string()); | |
} | |
#[test] | |
fn test_2() { | |
assert_eq!(ccbreaker("camelCasingTest"), "camel casing test".to_string()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment