Skip to content

Instantly share code, notes, and snippets.

@pmkroeker
Forked from rust-play/playground.rs
Created June 3, 2020 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmkroeker/7fd24c51f9361af65c337d24922ad8e0 to your computer and use it in GitHub Desktop.
Save pmkroeker/7fd24c51f9361af65c337d24922ad8e0 to your computer and use it in GitHub Desktop.
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