Vendor things
This commit is contained in:
parent
5deceec006
commit
977e3c17e5
19434 changed files with 10682014 additions and 0 deletions
370
third-party/vendor/Inflector/src/cases/camelcase/mod.rs
vendored
Normal file
370
third-party/vendor/Inflector/src/cases/camelcase/mod.rs
vendored
Normal file
|
|
@ -0,0 +1,370 @@
|
|||
#![deny(warnings)]
|
||||
use cases::case::*;
|
||||
|
||||
/// Converts a `&str` to camelCase `String`
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::camelcase::to_camel_case;
|
||||
/// let mock_string: &str = "fooBar";
|
||||
/// let expected_string: String = "fooBar".to_string();
|
||||
/// let asserted_string: String = to_camel_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::camelcase::to_camel_case;
|
||||
/// let mock_string: &str = "FOO_BAR";
|
||||
/// let expected_string: String = "fooBar".to_string();
|
||||
/// let asserted_string: String = to_camel_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::camelcase::to_camel_case;
|
||||
/// let mock_string: &str = "Foo Bar";
|
||||
/// let expected_string: String = "fooBar".to_string();
|
||||
/// let asserted_string: String = to_camel_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::camelcase::to_camel_case;
|
||||
/// let mock_string: &str = "foo_bar";
|
||||
/// let expected_string: String = "fooBar".to_string();
|
||||
/// let asserted_string: String = to_camel_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::camelcase::to_camel_case;
|
||||
/// let mock_string: &str = "Foo bar";
|
||||
/// let expected_string: String = "fooBar".to_string();
|
||||
/// let asserted_string: String = to_camel_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::camelcase::to_camel_case;
|
||||
/// let mock_string: &str = "foo-bar";
|
||||
/// let expected_string: String = "fooBar".to_string();
|
||||
/// let asserted_string: String = to_camel_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::camelcase::to_camel_case;
|
||||
/// let mock_string: &str = "FooBar";
|
||||
/// let expected_string: String = "fooBar".to_string();
|
||||
/// let asserted_string: String = to_camel_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::camelcase::to_camel_case;
|
||||
/// let mock_string: &str = "FooBar3";
|
||||
/// let expected_string: String = "fooBar3".to_string();
|
||||
/// let asserted_string: String = to_camel_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::camelcase::to_camel_case;
|
||||
/// let mock_string: &str = "Foo-Bar";
|
||||
/// let expected_string: String = "fooBar".to_string();
|
||||
/// let asserted_string: String = to_camel_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
pub fn to_camel_case(non_camelized_string: &str) -> String {
|
||||
let options = CamelOptions {
|
||||
new_word: false,
|
||||
last_char: ' ',
|
||||
first_word: false,
|
||||
injectable_char: ' ',
|
||||
has_seperator: false,
|
||||
inverted: false,
|
||||
};
|
||||
to_case_camel_like(&non_camelized_string, options)
|
||||
}
|
||||
|
||||
/// Determines if a `&str` is camelCase bool``
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::camelcase::is_camel_case;
|
||||
/// let mock_string: &str = "Foo";
|
||||
/// let asserted_bool: bool = is_camel_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::camelcase::is_camel_case;
|
||||
/// let mock_string: &str = "foo";
|
||||
/// let asserted_bool: bool = is_camel_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::camelcase::is_camel_case;
|
||||
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
|
||||
/// let asserted_bool: bool = is_camel_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::camelcase::is_camel_case;
|
||||
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_camel_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::camelcase::is_camel_case;
|
||||
/// let mock_string: &str = "fooBarIsAReallyReally3LongString";
|
||||
/// let asserted_bool: bool = is_camel_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::camelcase::is_camel_case;
|
||||
/// let mock_string: &str = "fooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_camel_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::camelcase::is_camel_case;
|
||||
/// let mock_string: &str = "FOO_BAR_STRING_THAT_IS_REALLY_REALLY_LONG";
|
||||
/// let asserted_bool: bool = is_camel_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::camelcase::is_camel_case;
|
||||
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long";
|
||||
/// let asserted_bool: bool = is_camel_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::camelcase::is_camel_case;
|
||||
/// let mock_string: &str = "Foo bar string that is really really long";
|
||||
/// let asserted_bool: bool = is_camel_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::camelcase::is_camel_case;
|
||||
/// let mock_string: &str = "Foo Bar Is A Really Really Long String";
|
||||
/// let asserted_bool: bool = is_camel_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
/// ```
|
||||
pub fn is_camel_case(test_string: &str) -> bool {
|
||||
to_camel_case(&test_string.clone()) == test_string
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "unstable", test))]
|
||||
mod benchmarks {
|
||||
extern crate test;
|
||||
use self::test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_camel0(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let test_string = "Foo bar";
|
||||
super::to_camel_case(test_string)
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_camel1(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let test_string = "foo_bar";
|
||||
super::to_camel_case(test_string)
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_camel2(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let test_string = "fooBar";
|
||||
super::to_camel_case(test_string)
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_is_camel(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let test_string: &str = "Foo bar";
|
||||
super::is_camel_case(test_string)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ::to_camel_case;
|
||||
use ::is_camel_case;
|
||||
|
||||
#[test]
|
||||
fn from_camel_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
let expected: String = "fooBar".to_owned();
|
||||
assert_eq!(to_camel_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
let expected: String = "fooBar".to_owned();
|
||||
assert_eq!(to_camel_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
let expected: String = "fooBar".to_owned();
|
||||
assert_eq!(to_camel_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
let expected: String = "fooBar".to_owned();
|
||||
assert_eq!(to_camel_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
let expected: String = "fooBar".to_owned();
|
||||
assert_eq!(to_camel_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
let expected: String = "fooBar".to_owned();
|
||||
assert_eq!(to_camel_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_screaming_snake_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
let expected: String = "fooBar".to_owned();
|
||||
assert_eq!(to_camel_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
let expected: String = "fooBar".to_owned();
|
||||
assert_eq!(to_camel_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_case_with_loads_of_space() {
|
||||
let convertable_string: String = "foo bar".to_owned();
|
||||
let expected: String = "fooBar".to_owned();
|
||||
assert_eq!(to_camel_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_name_with_a_dot() {
|
||||
let convertable_string: String = "Robert C. Martin".to_owned();
|
||||
let expected: String = "robertCMartin".to_owned();
|
||||
assert_eq!(to_camel_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn random_text_with_bad_chars() {
|
||||
let convertable_string: String = "Random text with *(bad) chars".to_owned();
|
||||
let expected: String = "randomTextWithBadChars".to_owned();
|
||||
assert_eq!(to_camel_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trailing_bad_chars() {
|
||||
let convertable_string: String = "trailing bad_chars*(()())".to_owned();
|
||||
let expected: String = "trailingBadChars".to_owned();
|
||||
assert_eq!(to_camel_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leading_bad_chars() {
|
||||
let convertable_string: String = "-!#$%leading bad chars".to_owned();
|
||||
let expected: String = "leadingBadChars".to_owned();
|
||||
assert_eq!(to_camel_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrapped_in_bad_chars() {
|
||||
let convertable_string: String = "-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
|
||||
let expected: String = "wrappedInBadChars".to_owned();
|
||||
assert_eq!(to_camel_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn has_a_sign() {
|
||||
let convertable_string: String = "has a + sign".to_owned();
|
||||
let expected: String = "hasASign".to_owned();
|
||||
assert_eq!(to_camel_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_camel_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
assert_eq!(is_camel_case(&convertable_string), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
assert_eq!(is_camel_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
assert_eq!(is_camel_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
assert_eq!(is_camel_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
assert_eq!(is_camel_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
assert_eq!(is_camel_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_screaming_snake_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
assert_eq!(is_camel_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
assert_eq!(is_camel_case(&convertable_string), false)
|
||||
}
|
||||
}
|
||||
|
||||
303
third-party/vendor/Inflector/src/cases/case/mod.rs
vendored
Normal file
303
third-party/vendor/Inflector/src/cases/case/mod.rs
vendored
Normal file
|
|
@ -0,0 +1,303 @@
|
|||
#![deny(warnings)]
|
||||
#[allow(unknown_lints)]
|
||||
#[allow(unused_imports)]
|
||||
use std::ascii::*;
|
||||
|
||||
pub struct CamelOptions {
|
||||
pub new_word: bool,
|
||||
pub last_char: char,
|
||||
pub first_word: bool,
|
||||
pub injectable_char: char,
|
||||
pub has_seperator: bool,
|
||||
pub inverted: bool,
|
||||
}
|
||||
|
||||
pub fn to_case_snake_like(convertable_string: &str, replace_with: &str, case: &str) -> String {
|
||||
let mut first_character: bool = true;
|
||||
let mut result: String = String::with_capacity(convertable_string.len() * 2);
|
||||
for char_with_index in trim_right(convertable_string).char_indices() {
|
||||
if char_is_seperator(&char_with_index.1) {
|
||||
if !first_character {
|
||||
first_character = true;
|
||||
result.push(replace_with.chars().nth(0).unwrap_or('_'));
|
||||
}
|
||||
} else if requires_seperator(char_with_index, first_character, &convertable_string) {
|
||||
first_character = false;
|
||||
result = snake_like_with_seperator(result, replace_with, &char_with_index.1, case)
|
||||
} else {
|
||||
first_character = false;
|
||||
result = snake_like_no_seperator(result, &char_with_index.1, case)
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
pub fn to_case_camel_like(convertable_string: &str, camel_options: CamelOptions) -> String {
|
||||
let mut new_word: bool = camel_options.new_word;
|
||||
let mut first_word: bool = camel_options.first_word;
|
||||
let mut last_char: char = camel_options.last_char;
|
||||
let mut found_real_char: bool = false;
|
||||
let mut result: String = String::with_capacity(convertable_string.len() * 2);
|
||||
for character in trim_right(convertable_string).chars() {
|
||||
if char_is_seperator(&character) && found_real_char {
|
||||
new_word = true;
|
||||
} else if !found_real_char && is_not_alphanumeric(character) {
|
||||
continue;
|
||||
} else if character.is_numeric() {
|
||||
found_real_char = true;
|
||||
new_word = true;
|
||||
result.push(character);
|
||||
} else if last_char_lower_current_is_upper_or_new_word(new_word, last_char, character) {
|
||||
found_real_char = true;
|
||||
new_word = false;
|
||||
result = append_on_new_word(result, first_word, character, &camel_options);
|
||||
first_word = false;
|
||||
} else {
|
||||
found_real_char = true;
|
||||
last_char = character;
|
||||
result.push(character.to_ascii_lowercase());
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn append_on_new_word(mut result: String, first_word: bool, character: char, camel_options: &CamelOptions) -> String {
|
||||
if not_first_word_and_has_seperator(first_word, camel_options.has_seperator) {
|
||||
result.push(camel_options.injectable_char);
|
||||
}
|
||||
if first_word_or_not_inverted(first_word, camel_options.inverted) {
|
||||
result.push(character.to_ascii_uppercase());
|
||||
} else {
|
||||
result.push(character.to_ascii_lowercase());
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
fn not_first_word_and_has_seperator(first_word: bool, has_seperator: bool) -> bool {
|
||||
has_seperator && !first_word
|
||||
}
|
||||
|
||||
fn first_word_or_not_inverted(first_word: bool, inverted: bool) -> bool {
|
||||
!inverted || first_word
|
||||
}
|
||||
|
||||
|
||||
fn last_char_lower_current_is_upper_or_new_word(new_word: bool, last_char: char, character: char) -> bool{
|
||||
new_word ||
|
||||
((last_char.is_lowercase() && character.is_uppercase()) &&
|
||||
(last_char != ' '))
|
||||
}
|
||||
|
||||
fn char_is_seperator(character: &char) -> bool {
|
||||
is_not_alphanumeric(*character)
|
||||
}
|
||||
|
||||
fn trim_right(convertable_string: &str) -> &str {
|
||||
convertable_string.trim_end_matches(is_not_alphanumeric)
|
||||
}
|
||||
|
||||
fn is_not_alphanumeric(character: char) -> bool {
|
||||
!character.is_alphanumeric()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn requires_seperator(char_with_index: (usize, char), first_character: bool, convertable_string: &str) -> bool {
|
||||
!first_character &&
|
||||
char_is_uppercase(char_with_index.1) &&
|
||||
next_or_previous_char_is_lowercase(convertable_string, char_with_index.0)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn snake_like_no_seperator(mut accumlator: String, current_char: &char, case: &str) -> String {
|
||||
if case == "lower" {
|
||||
accumlator.push(current_char.to_ascii_lowercase());
|
||||
accumlator
|
||||
} else {
|
||||
accumlator.push(current_char.to_ascii_uppercase());
|
||||
accumlator
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn snake_like_with_seperator(mut accumlator: String, replace_with: &str, current_char: &char, case: &str) -> String {
|
||||
if case == "lower" {
|
||||
accumlator.push(replace_with.chars().nth(0).unwrap_or('_'));
|
||||
accumlator.push(current_char.to_ascii_lowercase());
|
||||
accumlator
|
||||
} else {
|
||||
accumlator.push(replace_with.chars().nth(0).unwrap_or('_'));
|
||||
accumlator.push(current_char.to_ascii_uppercase());
|
||||
accumlator
|
||||
}
|
||||
}
|
||||
|
||||
fn next_or_previous_char_is_lowercase(convertable_string: &str, char_with_index: usize) -> bool {
|
||||
convertable_string.chars().nth(char_with_index + 1).unwrap_or('A').is_lowercase() ||
|
||||
convertable_string.chars().nth(char_with_index - 1).unwrap_or('A').is_lowercase()
|
||||
}
|
||||
|
||||
fn char_is_uppercase(test_char: char) -> bool {
|
||||
test_char == test_char.to_ascii_uppercase()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trim_bad_chars() {
|
||||
assert_eq!("abc", trim_right("abc----^"))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trim_bad_chars_when_none_are_bad() {
|
||||
assert_eq!("abc", trim_right("abc"))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_not_alphanumeric_on_is_alphanumeric() {
|
||||
assert!(!is_not_alphanumeric('a'))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_not_alphanumeric_on_is_not_alphanumeric() {
|
||||
assert!(is_not_alphanumeric('_'))
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_char_is_uppercase_when_it_is() {
|
||||
assert_eq!(char_is_uppercase('A'), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_char_is_uppercase_when_it_is_not() {
|
||||
assert_eq!(char_is_uppercase('a'), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_next_or_previous_char_is_lowercase_true() {
|
||||
assert_eq!(next_or_previous_char_is_lowercase("TestWWW", 3), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_next_or_previous_char_is_lowercase_false() {
|
||||
assert_eq!(next_or_previous_char_is_lowercase("TestWWW", 5), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snake_like_with_seperator_lowers() {
|
||||
assert_eq!(snake_like_with_seperator("".to_owned(), "^", &'c', "lower"), "^c".to_string())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snake_like_with_seperator_upper() {
|
||||
assert_eq!(snake_like_with_seperator("".to_owned(), "^", &'c', "upper"), "^C".to_string())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snake_like_no_seperator_lower() {
|
||||
assert_eq!(snake_like_no_seperator("".to_owned(), &'C', "lower"), "c".to_string())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snake_like_no_seperator_upper() {
|
||||
assert_eq!(snake_like_no_seperator("".to_owned(), &'c', "upper"), "C".to_string())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn requires_seperator_upper_not_first_wrap_is_safe_current_upper() {
|
||||
assert_eq!(requires_seperator((2, 'C'), false, "test"), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn requires_seperator_upper_not_first_wrap_is_safe_current_lower() {
|
||||
assert_eq!(requires_seperator((2, 'c'), false, "test"), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn requires_seperator_upper_first_wrap_is_safe_current_upper() {
|
||||
assert_eq!(requires_seperator((0, 'T'), true, "Test"), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn requires_seperator_upper_first_wrap_is_safe_current_lower() {
|
||||
assert_eq!(requires_seperator((0, 't'), true, "Test"), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn requires_seperator_upper_first_wrap_is_safe_current_lower_next_is_too() {
|
||||
assert_eq!(requires_seperator((0, 't'), true, "test"), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_char_is_seperator_dash() {
|
||||
assert_eq!(char_is_seperator(&'-'), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_char_is_seperator_underscore() {
|
||||
assert_eq!(char_is_seperator(&'_'), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_char_is_seperator_space() {
|
||||
assert_eq!(char_is_seperator(&' '), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_char_is_seperator_when_not() {
|
||||
assert_eq!(char_is_seperator(&'A'), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_last_char_lower_current_is_upper_or_new_word_with_new_word() {
|
||||
assert_eq!(last_char_lower_current_is_upper_or_new_word(true, ' ', '-'), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_last_char_lower_current_is_upper_or_new_word_last_char_space() {
|
||||
assert_eq!(last_char_lower_current_is_upper_or_new_word(false, ' ', '-'), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_last_char_lower_current_is_upper_or_new_word_last_char_lower_current_upper() {
|
||||
assert_eq!(last_char_lower_current_is_upper_or_new_word(false, 'a', 'A'), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_last_char_lower_current_is_upper_or_new_word_last_char_upper_current_upper() {
|
||||
assert_eq!(last_char_lower_current_is_upper_or_new_word(false, 'A', 'A'), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_last_char_lower_current_is_upper_or_new_word_last_char_upper_current_lower() {
|
||||
assert_eq!(last_char_lower_current_is_upper_or_new_word(false, 'A', 'a'), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_first_word_or_not_inverted_with_first_word() {
|
||||
assert_eq!(first_word_or_not_inverted(true, false), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_first_word_or_not_inverted_not_first_word_not_inverted() {
|
||||
assert_eq!(first_word_or_not_inverted(false, false), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_first_word_or_not_inverted_not_first_word_is_inverted() {
|
||||
assert_eq!(first_word_or_not_inverted(false, true), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_not_first_word_and_has_seperator_is_first_and_not_seperator() {
|
||||
assert_eq!(not_first_word_and_has_seperator(true, false), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_not_first_word_and_has_seperator_not_first_and_not_seperator() {
|
||||
assert_eq!(not_first_word_and_has_seperator(false, false), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_not_first_word_and_has_seperator_not_first_and_has_seperator() {
|
||||
assert_eq!(not_first_word_and_has_seperator(false, true), true)
|
||||
}
|
||||
393
third-party/vendor/Inflector/src/cases/classcase/mod.rs
vendored
Normal file
393
third-party/vendor/Inflector/src/cases/classcase/mod.rs
vendored
Normal file
|
|
@ -0,0 +1,393 @@
|
|||
#![deny(warnings)]
|
||||
use cases::case::*;
|
||||
#[cfg(feature = "heavyweight")]
|
||||
use string::singularize::to_singular;
|
||||
#[cfg(feature = "heavyweight")]
|
||||
/// Converts a `&str` to `ClassCase` `String`
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::to_class_case;
|
||||
/// let mock_string: &str = "FooBar";
|
||||
/// let expected_string: String = "FooBar".to_string();
|
||||
/// let asserted_string: String = to_class_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::to_class_case;
|
||||
/// let mock_string: &str = "FooBars";
|
||||
/// let expected_string: String = "FooBar".to_string();
|
||||
/// let asserted_string: String = to_class_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::to_class_case;
|
||||
/// let mock_string: &str = "Foo Bar";
|
||||
/// let expected_string: String = "FooBar".to_string();
|
||||
/// let asserted_string: String = to_class_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::to_class_case;
|
||||
/// let mock_string: &str = "foo-bar";
|
||||
/// let expected_string: String = "FooBar".to_string();
|
||||
/// let asserted_string: String = to_class_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::to_class_case;
|
||||
/// let mock_string: &str = "fooBar";
|
||||
/// let expected_string: String = "FooBar".to_string();
|
||||
/// let asserted_string: String = to_class_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::to_class_case;
|
||||
/// let mock_string: &str = "FOO_BAR";
|
||||
/// let expected_string: String = "FooBar".to_string();
|
||||
/// let asserted_string: String = to_class_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::to_class_case;
|
||||
/// let mock_string: &str = "foo_bar";
|
||||
/// let expected_string: String = "FooBar".to_string();
|
||||
/// let asserted_string: String = to_class_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::to_class_case;
|
||||
/// let mock_string: &str = "foo_bars";
|
||||
/// let expected_string: String = "FooBar".to_string();
|
||||
/// let asserted_string: String = to_class_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::to_class_case;
|
||||
/// let mock_string: &str = "Foo bar";
|
||||
/// let expected_string: String = "FooBar".to_string();
|
||||
/// let asserted_string: String = to_class_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
pub fn to_class_case(non_class_case_string: &str) -> String {
|
||||
let options = CamelOptions {
|
||||
new_word: true,
|
||||
last_char: ' ',
|
||||
first_word: false,
|
||||
injectable_char: ' ',
|
||||
has_seperator: false,
|
||||
inverted: false,
|
||||
};
|
||||
let class_plural = to_case_camel_like(non_class_case_string, options);
|
||||
let split: (&str, &str) =
|
||||
class_plural.split_at(class_plural.rfind(char::is_uppercase).unwrap_or(0));
|
||||
format!("{}{}", split.0, to_singular(split.1))
|
||||
}
|
||||
|
||||
#[cfg(feature = "heavyweight")]
|
||||
/// Determines if a `&str` is `ClassCase` `bool`
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::is_class_case;
|
||||
/// let mock_string: &str = "Foo";
|
||||
/// let asserted_bool: bool = is_class_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::is_class_case;
|
||||
/// let mock_string: &str = "foo";
|
||||
/// let asserted_bool: bool = is_class_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::is_class_case;
|
||||
/// let mock_string: &str = "FooBarIsAReallyReallyLongStrings";
|
||||
/// let asserted_bool: bool = is_class_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::is_class_case;
|
||||
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_class_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::is_class_case;
|
||||
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
|
||||
/// let asserted_bool: bool = is_class_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::is_class_case;
|
||||
/// let mock_string: &str = "foo_bar_is_a_really_really_long_strings";
|
||||
/// let asserted_bool: bool = is_class_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::is_class_case;
|
||||
/// let mock_string: &str = "fooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_class_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::is_class_case;
|
||||
/// let mock_string: &str = "FOO_BAR_STRING_THAT_IS_REALLY_REALLY_LONG";
|
||||
/// let asserted_bool: bool = is_class_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::is_class_case;
|
||||
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long";
|
||||
/// let asserted_bool: bool = is_class_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::is_class_case;
|
||||
/// let mock_string: &str = "Foo bar string that is really really long";
|
||||
/// let asserted_bool: bool = is_class_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::classcase::is_class_case;
|
||||
/// let mock_string: &str = "Foo Bar Is A Really Really Long String";
|
||||
/// let asserted_bool: bool = is_class_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
pub fn is_class_case(test_string: &str) -> bool {
|
||||
to_class_case(&test_string.clone()) == test_string
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "unstable", test))]
|
||||
#[cfg(feature = "heavyweight")]
|
||||
mod benchmarks {
|
||||
extern crate test;
|
||||
use self::test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_class_case(b: &mut Bencher) {
|
||||
b.iter(|| super::to_class_case("Foo bar"));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_is_class(b: &mut Bencher) {
|
||||
b.iter(|| super::is_class_case("Foo bar"));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_class_from_snake(b: &mut Bencher) {
|
||||
b.iter(|| super::to_class_case("foo_bar"));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(feature = "heavyweight")]
|
||||
mod tests {
|
||||
use ::to_class_case;
|
||||
use ::is_class_case;
|
||||
|
||||
#[test]
|
||||
fn from_camel_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
let expected: String = "FooBar".to_owned();
|
||||
assert_eq!(to_class_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
let expected: String = "FooBar".to_owned();
|
||||
assert_eq!(to_class_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
let expected: String = "FooBar".to_owned();
|
||||
assert_eq!(to_class_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
let expected: String = "FooBar".to_owned();
|
||||
assert_eq!(to_class_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
let expected: String = "FooBar".to_owned();
|
||||
assert_eq!(to_class_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
let expected: String = "FooBar".to_owned();
|
||||
assert_eq!(to_class_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_screaming_class_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
let expected: String = "FooBar".to_owned();
|
||||
assert_eq!(to_class_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
let expected: String = "FooBar".to_owned();
|
||||
assert_eq!(to_class_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_table_case() {
|
||||
let convertable_string: String = "foo_bars".to_owned();
|
||||
let expected: String = "FooBar".to_owned();
|
||||
assert_eq!(to_class_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_case_with_loads_of_space() {
|
||||
let convertable_string: String = "foo bar".to_owned();
|
||||
let expected: String = "FooBar".to_owned();
|
||||
assert_eq!(to_class_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_name_with_a_dot() {
|
||||
let convertable_string: String = "Robert C. Martin".to_owned();
|
||||
let expected: String = "RobertCMartin".to_owned();
|
||||
assert_eq!(to_class_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn random_text_with_bad_chars() {
|
||||
let convertable_string: String = "Random text with *(bad) chars".to_owned();
|
||||
let expected: String = "RandomTextWithBadChar".to_owned();
|
||||
assert_eq!(to_class_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trailing_bad_chars() {
|
||||
let convertable_string: String = "trailing bad_chars*(()())".to_owned();
|
||||
let expected: String = "TrailingBadChar".to_owned();
|
||||
assert_eq!(to_class_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leading_bad_chars() {
|
||||
let convertable_string: String = "-!#$%leading bad chars".to_owned();
|
||||
let expected: String = "LeadingBadChar".to_owned();
|
||||
assert_eq!(to_class_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrapped_in_bad_chars() {
|
||||
let convertable_string: String = "-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
|
||||
let expected: String = "WrappedInBadChar".to_owned();
|
||||
assert_eq!(to_class_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn has_a_sign() {
|
||||
let convertable_string: String = "has a + sign".to_owned();
|
||||
let expected: String = "HasASign".to_owned();
|
||||
assert_eq!(to_class_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_class_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
assert_eq!(is_class_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
assert_eq!(is_class_case(&convertable_string), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
assert_eq!(is_class_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
assert_eq!(is_class_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
assert_eq!(is_class_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
assert_eq!(is_class_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_screaming_snake_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
assert_eq!(is_class_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
assert_eq!(is_class_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_table_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
assert_eq!(is_class_case(&convertable_string), true)
|
||||
}
|
||||
}
|
||||
|
||||
262
third-party/vendor/Inflector/src/cases/kebabcase/mod.rs
vendored
Normal file
262
third-party/vendor/Inflector/src/cases/kebabcase/mod.rs
vendored
Normal file
|
|
@ -0,0 +1,262 @@
|
|||
#![deny(warnings)]
|
||||
use cases::case::*;
|
||||
/// Determines if a `&str` is `kebab-case`
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::kebabcase::is_kebab_case;
|
||||
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
|
||||
/// let asserted_bool: bool = is_kebab_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::kebabcase::is_kebab_case;
|
||||
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_kebab_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::kebabcase::is_kebab_case;
|
||||
/// let mock_string: &str = "fooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_kebab_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::kebabcase::is_kebab_case;
|
||||
/// let mock_string: &str = "FOO_BAR_STRING_THAT_IS_REALLY_REALLY_LONG";
|
||||
/// let asserted_bool: bool = is_kebab_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::kebabcase::is_kebab_case;
|
||||
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long";
|
||||
/// let asserted_bool: bool = is_kebab_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::kebabcase::is_kebab_case;
|
||||
/// let mock_string: &str = "Foo bar string that is really really long";
|
||||
/// let asserted_bool: bool = is_kebab_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::kebabcase::is_kebab_case;
|
||||
/// let mock_string: &str = "Foo Bar Is A Really Really Long String";
|
||||
/// let asserted_bool: bool = is_kebab_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
pub fn is_kebab_case(test_string: &str) -> bool {
|
||||
test_string == to_kebab_case(test_string.clone())
|
||||
}
|
||||
|
||||
/// Converts a `&str` to `kebab-case` `String`
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::kebabcase::to_kebab_case;
|
||||
/// let mock_string: &str = "foo-bar";
|
||||
/// let expected_string: String = "foo-bar".to_string();
|
||||
/// let asserted_string: String = to_kebab_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::kebabcase::to_kebab_case;
|
||||
/// let mock_string: &str = "FOO_BAR";
|
||||
/// let expected_string: String = "foo-bar".to_string();
|
||||
/// let asserted_string: String = to_kebab_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::kebabcase::to_kebab_case;
|
||||
/// let mock_string: &str = "foo_bar";
|
||||
/// let expected_string: String = "foo-bar".to_string();
|
||||
/// let asserted_string: String = to_kebab_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::kebabcase::to_kebab_case;
|
||||
/// let mock_string: &str = "Foo Bar";
|
||||
/// let expected_string: String = "foo-bar".to_string();
|
||||
/// let asserted_string: String = to_kebab_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::kebabcase::to_kebab_case;
|
||||
/// let mock_string: &str = "Foo bar";
|
||||
/// let expected_string: String = "foo-bar".to_string();
|
||||
/// let asserted_string: String = to_kebab_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::kebabcase::to_kebab_case;
|
||||
/// let mock_string: &str = "FooBar";
|
||||
/// let expected_string: String = "foo-bar".to_string();
|
||||
/// let asserted_string: String = to_kebab_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::kebabcase::to_kebab_case;
|
||||
/// let mock_string: &str = "fooBar";
|
||||
/// let expected_string: String = "foo-bar".to_string();
|
||||
/// let asserted_string: String = to_kebab_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
pub fn to_kebab_case(non_kebab_case_string: &str) -> String {
|
||||
to_case_snake_like(non_kebab_case_string, "-", "lower")
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "unstable", test))]
|
||||
mod benchmarks {
|
||||
extern crate test;
|
||||
use self::test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_kebab(b: &mut Bencher) {
|
||||
b.iter(|| super::to_kebab_case("Foo bar"));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_is_kebab(b: &mut Bencher) {
|
||||
b.iter(|| super::is_kebab_case("Foo bar"));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_kebab_from_snake(b: &mut Bencher) {
|
||||
b.iter(|| super::to_kebab_case("test_test_test"));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ::to_kebab_case;
|
||||
use ::is_kebab_case;
|
||||
|
||||
#[test]
|
||||
fn from_camel_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
let expected: String = "foo-bar".to_owned();
|
||||
assert_eq!(to_kebab_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
let expected: String = "foo-bar".to_owned();
|
||||
assert_eq!(to_kebab_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
let expected: String = "foo-bar".to_owned();
|
||||
assert_eq!(to_kebab_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
let expected: String = "foo-bar".to_owned();
|
||||
assert_eq!(to_kebab_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
let expected: String = "foo-bar".to_owned();
|
||||
assert_eq!(to_kebab_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
let expected: String = "foo-bar".to_owned();
|
||||
assert_eq!(to_kebab_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_screaming_snake_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
let expected: String = "foo-bar".to_owned();
|
||||
assert_eq!(to_kebab_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
let expected: String = "foo-bar".to_owned();
|
||||
assert_eq!(to_kebab_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_camel_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
assert_eq!(is_kebab_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
assert_eq!(is_kebab_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
assert_eq!(is_kebab_case(&convertable_string), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
assert_eq!(is_kebab_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
assert_eq!(is_kebab_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
assert_eq!(is_kebab_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_screaming_snake_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
assert_eq!(is_kebab_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
assert_eq!(is_kebab_case(&convertable_string), false)
|
||||
}
|
||||
}
|
||||
|
||||
52
third-party/vendor/Inflector/src/cases/mod.rs
vendored
Normal file
52
third-party/vendor/Inflector/src/cases/mod.rs
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
mod case;
|
||||
/// Provides conversion to and detection of class case strings.
|
||||
///
|
||||
/// This version singularizes strings.
|
||||
///
|
||||
/// Example string `ClassCase`
|
||||
pub mod classcase;
|
||||
|
||||
/// Provides conversion to and detection of camel case strings.
|
||||
///
|
||||
/// Example string `camelCase`
|
||||
pub mod camelcase;
|
||||
|
||||
/// Provides conversion to and detection of snake case strings.
|
||||
///
|
||||
/// Example string `snake_case`
|
||||
pub mod snakecase;
|
||||
|
||||
/// Provides conversion to and detection of screaming snake case strings.
|
||||
///
|
||||
/// Example string `SCREAMING_SNAKE_CASE`
|
||||
pub mod screamingsnakecase;
|
||||
|
||||
/// Provides conversion to and detection of kebab case strings.
|
||||
///
|
||||
/// Example string `kebab-case`
|
||||
pub mod kebabcase;
|
||||
|
||||
/// Provides conversion to and detection of train case strings.
|
||||
///
|
||||
/// Example string `Train-Case`
|
||||
pub mod traincase;
|
||||
|
||||
/// Provides conversion to and detection of sentence case strings.
|
||||
///
|
||||
/// Example string `Sentence case`
|
||||
pub mod sentencecase;
|
||||
|
||||
/// Provides conversion to and detection of title case strings.
|
||||
///
|
||||
/// Example string `Title Case`
|
||||
pub mod titlecase;
|
||||
|
||||
/// Provides conversion to and detection of table case strings.
|
||||
///
|
||||
/// Example string `table_cases`
|
||||
pub mod tablecase;
|
||||
|
||||
/// Provides conversion to pascal case strings.
|
||||
///
|
||||
/// Example string `PascalCase`
|
||||
pub mod pascalcase;
|
||||
360
third-party/vendor/Inflector/src/cases/pascalcase/mod.rs
vendored
Normal file
360
third-party/vendor/Inflector/src/cases/pascalcase/mod.rs
vendored
Normal file
|
|
@ -0,0 +1,360 @@
|
|||
#![deny(warnings)]
|
||||
use cases::case::*;
|
||||
/// Converts a `&str` to pascalCase `String`
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::pascalcase::to_pascal_case;
|
||||
/// let mock_string: &str = "fooBar";
|
||||
/// let expected_string: String = "FooBar".to_string();
|
||||
/// let asserted_string: String = to_pascal_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::pascalcase::to_pascal_case;
|
||||
/// let mock_string: &str = "FOO_BAR";
|
||||
/// let expected_string: String = "FooBar".to_string();
|
||||
/// let asserted_string: String = to_pascal_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::pascalcase::to_pascal_case;
|
||||
/// let mock_string: &str = "Foo Bar";
|
||||
/// let expected_string: String = "FooBar".to_string();
|
||||
/// let asserted_string: String = to_pascal_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::pascalcase::to_pascal_case;
|
||||
/// let mock_string: &str = "foo_bar";
|
||||
/// let expected_string: String = "FooBar".to_string();
|
||||
/// let asserted_string: String = to_pascal_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::pascalcase::to_pascal_case;
|
||||
/// let mock_string: &str = "Foo bar";
|
||||
/// let expected_string: String = "FooBar".to_string();
|
||||
/// let asserted_string: String = to_pascal_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::pascalcase::to_pascal_case;
|
||||
/// let mock_string: &str = "foo-bar";
|
||||
/// let expected_string: String = "FooBar".to_string();
|
||||
/// let asserted_string: String = to_pascal_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::pascalcase::to_pascal_case;
|
||||
/// let mock_string: &str = "FooBar";
|
||||
/// let expected_string: String = "FooBar".to_string();
|
||||
/// let asserted_string: String = to_pascal_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::pascalcase::to_pascal_case;
|
||||
/// let mock_string: &str = "FooBar3";
|
||||
/// let expected_string: String = "FooBar3".to_string();
|
||||
/// let asserted_string: String = to_pascal_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
pub fn to_pascal_case(non_pascalized_string: &str) -> String {
|
||||
let options = CamelOptions {
|
||||
new_word: true,
|
||||
last_char: ' ',
|
||||
first_word: false,
|
||||
injectable_char: ' ',
|
||||
has_seperator: false,
|
||||
inverted: false,
|
||||
};
|
||||
to_case_camel_like(non_pascalized_string, options)
|
||||
}
|
||||
|
||||
/// Determines if a `&str` is pascalCase bool``
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::pascalcase::is_pascal_case;
|
||||
/// let mock_string: &str = "Foo";
|
||||
/// let asserted_bool: bool = is_pascal_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::pascalcase::is_pascal_case;
|
||||
/// let mock_string: &str = "foo";
|
||||
/// let asserted_bool: bool = is_pascal_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::pascalcase::is_pascal_case;
|
||||
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
|
||||
/// let asserted_bool: bool = is_pascal_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::pascalcase::is_pascal_case;
|
||||
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_pascal_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::pascalcase::is_pascal_case;
|
||||
/// let mock_string: &str = "FooBarIsAReallyReally3LongString";
|
||||
/// let asserted_bool: bool = is_pascal_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::pascalcase::is_pascal_case;
|
||||
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_pascal_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::pascalcase::is_pascal_case;
|
||||
/// let mock_string: &str = "FOO_BAR_STRING_THAT_IS_REALLY_REALLY_LONG";
|
||||
/// let asserted_bool: bool = is_pascal_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::pascalcase::is_pascal_case;
|
||||
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long";
|
||||
/// let asserted_bool: bool = is_pascal_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::pascalcase::is_pascal_case;
|
||||
/// let mock_string: &str = "Foo bar string that is really really long";
|
||||
/// let asserted_bool: bool = is_pascal_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::pascalcase::is_pascal_case;
|
||||
/// let mock_string: &str = "Foo Bar Is A Really Really Long String";
|
||||
/// let asserted_bool: bool = is_pascal_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
/// ```
|
||||
pub fn is_pascal_case(test_string: &str) -> bool {
|
||||
to_pascal_case(test_string.clone()) == test_string
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "unstable", test))]
|
||||
mod benchmarks {
|
||||
extern crate test;
|
||||
use self::test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_pascal0(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let test_string = "Foo bar";
|
||||
super::to_pascal_case(test_string)
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_pascal1(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let test_string = "foo_bar";
|
||||
super::to_pascal_case(test_string)
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_pascal2(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let test_string = "fooBar";
|
||||
super::to_pascal_case(test_string)
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_is_pascal(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let test_string: &str = "Foo bar";
|
||||
super::is_pascal_case(test_string)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ::to_pascal_case;
|
||||
use ::is_pascal_case;
|
||||
|
||||
#[test]
|
||||
fn from_camel_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
let expected: String = "FooBar".to_owned();
|
||||
assert_eq!(to_pascal_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
let expected: String = "FooBar".to_owned();
|
||||
assert_eq!(to_pascal_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
let expected: String = "FooBar".to_owned();
|
||||
assert_eq!(to_pascal_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
let expected: String = "FooBar".to_owned();
|
||||
assert_eq!(to_pascal_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
let expected: String = "FooBar".to_owned();
|
||||
assert_eq!(to_pascal_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
let expected: String = "FooBar".to_owned();
|
||||
assert_eq!(to_pascal_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_screaming_snake_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
let expected: String = "FooBar".to_owned();
|
||||
assert_eq!(to_pascal_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
let expected: String = "FooBar".to_owned();
|
||||
assert_eq!(to_pascal_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_case_with_loads_of_space() {
|
||||
let convertable_string: String = "foo bar".to_owned();
|
||||
let expected: String = "FooBar".to_owned();
|
||||
assert_eq!(to_pascal_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_name_with_a_dot() {
|
||||
let convertable_string: String = "Robert C. Martin".to_owned();
|
||||
let expected: String = "RobertCMartin".to_owned();
|
||||
assert_eq!(to_pascal_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn random_text_with_bad_chars() {
|
||||
let convertable_string: String = "Random text with *(bad) chars".to_owned();
|
||||
let expected: String = "RandomTextWithBadChars".to_owned();
|
||||
assert_eq!(to_pascal_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trailing_bad_chars() {
|
||||
let convertable_string: String = "trailing bad_chars*(()())".to_owned();
|
||||
let expected: String = "TrailingBadChars".to_owned();
|
||||
assert_eq!(to_pascal_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leading_bad_chars() {
|
||||
let convertable_string: String = "-!#$%leading bad chars".to_owned();
|
||||
let expected: String = "LeadingBadChars".to_owned();
|
||||
assert_eq!(to_pascal_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrapped_in_bad_chars() {
|
||||
let convertable_string: String = "-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
|
||||
let expected: String = "WrappedInBadChars".to_owned();
|
||||
assert_eq!(to_pascal_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn has_a_sign() {
|
||||
let convertable_string: String = "has a + sign".to_owned();
|
||||
let expected: String = "HasASign".to_owned();
|
||||
assert_eq!(to_pascal_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_camel_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
assert_eq!(is_pascal_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
assert_eq!(is_pascal_case(&convertable_string), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
assert_eq!(is_pascal_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
assert_eq!(is_pascal_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
assert_eq!(is_pascal_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
assert_eq!(is_pascal_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_screaming_snake_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
assert_eq!(is_pascal_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
assert_eq!(is_pascal_case(&convertable_string), false)
|
||||
}
|
||||
}
|
||||
253
third-party/vendor/Inflector/src/cases/screamingsnakecase/mod.rs
vendored
Normal file
253
third-party/vendor/Inflector/src/cases/screamingsnakecase/mod.rs
vendored
Normal file
|
|
@ -0,0 +1,253 @@
|
|||
#![deny(warnings)]
|
||||
use cases::case::*;
|
||||
/// Converts a `&str` to `SCREAMING_SNAKE_CASE` `String`
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::screamingsnakecase::to_screaming_snake_case;
|
||||
/// let mock_string: &str = "foo_bar";
|
||||
/// let expected_string: String = "FOO_BAR".to_string();
|
||||
/// let asserted_string: String = to_screaming_snake_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::screamingsnakecase::to_screaming_snake_case;
|
||||
/// let mock_string: &str = "HTTP Foo bar";
|
||||
/// let expected_string: String = "HTTP_FOO_BAR".to_string();
|
||||
/// let asserted_string: String = to_screaming_snake_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::screamingsnakecase::to_screaming_snake_case;
|
||||
/// let mock_string: &str = "Foo bar";
|
||||
/// let expected_string: String = "FOO_BAR".to_string();
|
||||
/// let asserted_string: String = to_screaming_snake_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::screamingsnakecase::to_screaming_snake_case;
|
||||
/// let mock_string: &str = "Foo Bar";
|
||||
/// let expected_string: String = "FOO_BAR".to_string();
|
||||
/// let asserted_string: String = to_screaming_snake_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::screamingsnakecase::to_screaming_snake_case;
|
||||
/// let mock_string: &str = "FooBar";
|
||||
/// let expected_string: String = "FOO_BAR".to_string();
|
||||
/// let asserted_string: String = to_screaming_snake_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::screamingsnakecase::to_screaming_snake_case;
|
||||
/// let mock_string: &str = "fooBar";
|
||||
/// let expected_string: String = "FOO_BAR".to_string();
|
||||
/// let asserted_string: String = to_screaming_snake_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::screamingsnakecase::to_screaming_snake_case;
|
||||
/// let mock_string: &str = "fooBar3";
|
||||
/// let expected_string: String = "FOO_BAR_3".to_string();
|
||||
/// let asserted_string: String = to_screaming_snake_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
pub fn to_screaming_snake_case(non_snake_case_string: &str) -> String {
|
||||
to_case_snake_like(non_snake_case_string, "_", "upper")
|
||||
}
|
||||
|
||||
/// Determines of a `&str` is `SCREAMING_SNAKE_CASE`
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::screamingsnakecase::is_screaming_snake_case;
|
||||
/// let mock_string: &str = "Foo bar string that is really really long";
|
||||
/// let asserted_bool: bool = is_screaming_snake_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::screamingsnakecase::is_screaming_snake_case;
|
||||
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
|
||||
/// let asserted_bool: bool = is_screaming_snake_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::screamingsnakecase::is_screaming_snake_case;
|
||||
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_screaming_snake_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::screamingsnakecase::is_screaming_snake_case;
|
||||
/// let mock_string: &str = "Foo Bar Is A Really Really Long String";
|
||||
/// let asserted_bool: bool = is_screaming_snake_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::screamingsnakecase::is_screaming_snake_case;
|
||||
/// let mock_string: &str = "fooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_screaming_snake_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::screamingsnakecase::is_screaming_snake_case;
|
||||
/// let mock_string: &str = "FOO_BAR_STRING_THAT_IS_REALLY_REALLY_LONG";
|
||||
/// let asserted_bool: bool = is_screaming_snake_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::screamingsnakecase::is_screaming_snake_case;
|
||||
/// let mock_string: &str = "FOO_BAR1_STRING_THAT_IS_REALLY_REALLY_LONG";
|
||||
/// let asserted_bool: bool = is_screaming_snake_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::screamingsnakecase::is_screaming_snake_case;
|
||||
/// let mock_string: &str = "FOO_BAR_1_STRING_THAT_IS_REALLY_REALLY_LONG";
|
||||
/// let asserted_bool: bool = is_screaming_snake_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
///
|
||||
/// ```
|
||||
pub fn is_screaming_snake_case(test_string: &str) -> bool {
|
||||
test_string == to_screaming_snake_case(test_string.clone())
|
||||
}
|
||||
|
||||
|
||||
#[cfg(all(feature = "unstable", test))]
|
||||
mod benchmarks {
|
||||
extern crate test;
|
||||
use self::test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_screaming_snake(b: &mut Bencher) {
|
||||
b.iter(|| super::to_screaming_snake_case("Foo bar"));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_is_screaming_snake(b: &mut Bencher) {
|
||||
b.iter(|| super::is_screaming_snake_case("Foo bar"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ::to_screaming_snake_case;
|
||||
use ::is_screaming_snake_case;
|
||||
|
||||
#[test]
|
||||
fn from_camel_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
let expected: String = "FOO_BAR".to_owned();
|
||||
assert_eq!(to_screaming_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
let expected: String = "FOO_BAR".to_owned();
|
||||
assert_eq!(to_screaming_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
let expected: String = "FOO_BAR".to_owned();
|
||||
assert_eq!(to_screaming_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
let expected: String = "FOO_BAR".to_owned();
|
||||
assert_eq!(to_screaming_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
let expected: String = "FOO_BAR".to_owned();
|
||||
assert_eq!(to_screaming_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
let expected: String = "FOO_BAR".to_owned();
|
||||
assert_eq!(to_screaming_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_screaming_screaming_snake_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
let expected: String = "FOO_BAR".to_owned();
|
||||
assert_eq!(to_screaming_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
let expected: String = "FOO_BAR".to_owned();
|
||||
assert_eq!(to_screaming_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_camel_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
assert_eq!(is_screaming_snake_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
assert_eq!(is_screaming_snake_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
assert_eq!(is_screaming_snake_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
assert_eq!(is_screaming_snake_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
assert_eq!(is_screaming_snake_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
assert_eq!(is_screaming_snake_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_screaming_screaming_snake_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
assert_eq!(is_screaming_snake_case(&convertable_string), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
assert_eq!(is_screaming_snake_case(&convertable_string), false)
|
||||
}
|
||||
}
|
||||
313
third-party/vendor/Inflector/src/cases/sentencecase/mod.rs
vendored
Normal file
313
third-party/vendor/Inflector/src/cases/sentencecase/mod.rs
vendored
Normal file
|
|
@ -0,0 +1,313 @@
|
|||
#![deny(warnings)]
|
||||
use cases::case::*;
|
||||
/// Converts a `&str` to `Sentence case` `String`
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::sentencecase::to_sentence_case;
|
||||
/// let mock_string: &str = "Foo bar";
|
||||
/// let expected_string: String = "Foo bar".to_string();
|
||||
/// let asserted_string: String = to_sentence_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::sentencecase::to_sentence_case;
|
||||
/// let mock_string: &str = "FooBar";
|
||||
/// let expected_string: String = "Foo bar".to_string();
|
||||
/// let asserted_string: String = to_sentence_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::sentencecase::to_sentence_case;
|
||||
/// let mock_string: &str = "fooBar";
|
||||
/// let expected_string: String = "Foo bar".to_string();
|
||||
/// let asserted_string: String = to_sentence_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::sentencecase::to_sentence_case;
|
||||
/// let mock_string: &str = "FOO_BAR";
|
||||
/// let expected_string: String = "Foo bar".to_string();
|
||||
/// let asserted_string: String = to_sentence_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::sentencecase::to_sentence_case;
|
||||
/// let mock_string: &str = "foo_bar";
|
||||
/// let expected_string: String = "Foo bar".to_string();
|
||||
/// let asserted_string: String = to_sentence_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::sentencecase::to_sentence_case;
|
||||
/// let mock_string: &str = "foo-bar";
|
||||
/// let expected_string: String = "Foo bar".to_string();
|
||||
/// let asserted_string: String = to_sentence_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
pub fn to_sentence_case(non_sentence_case_string: &str) -> String {
|
||||
let options = CamelOptions {
|
||||
new_word: true,
|
||||
last_char: ' ',
|
||||
first_word: true,
|
||||
injectable_char: ' ',
|
||||
has_seperator: true,
|
||||
inverted: true,
|
||||
};
|
||||
to_case_camel_like(non_sentence_case_string, options)
|
||||
}
|
||||
/// Determines of a `&str` is `Sentence case`
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::sentencecase::is_sentence_case;
|
||||
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
|
||||
/// let asserted_bool: bool = is_sentence_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::sentencecase::is_sentence_case;
|
||||
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_sentence_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::sentencecase::is_sentence_case;
|
||||
/// let mock_string: &str = "fooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_sentence_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::sentencecase::is_sentence_case;
|
||||
/// let mock_string: &str = "Foo Bar Is A Really Really Long String";
|
||||
/// let asserted_bool: bool = is_sentence_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::sentencecase::is_sentence_case;
|
||||
/// let mock_string: &str = "FOO_BAR_STRING_THAT_IS_REALLY_REALLY_LONG";
|
||||
/// let asserted_bool: bool = is_sentence_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::sentencecase::is_sentence_case;
|
||||
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long";
|
||||
/// let asserted_bool: bool = is_sentence_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::sentencecase::is_sentence_case;
|
||||
/// let mock_string: &str = "Foo";
|
||||
/// let asserted_bool: bool = is_sentence_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::sentencecase::is_sentence_case;
|
||||
/// let mock_string: &str = "foo";
|
||||
/// let asserted_bool: bool = is_sentence_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::sentencecase::is_sentence_case;
|
||||
/// let mock_string: &str = "Foo bar string that is really really long";
|
||||
/// let asserted_bool: bool = is_sentence_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
///
|
||||
/// ```
|
||||
pub fn is_sentence_case(test_string: &str) -> bool {
|
||||
test_string == to_sentence_case(test_string.clone())
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "unstable", test))]
|
||||
mod benchmarks {
|
||||
extern crate test;
|
||||
use self::test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_sentence(b: &mut Bencher) {
|
||||
b.iter(|| super::to_sentence_case("Foo BAR"));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_is_sentence(b: &mut Bencher) {
|
||||
b.iter(|| super::is_sentence_case("Foo bar"));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_sentence_from_snake(b: &mut Bencher) {
|
||||
b.iter(|| super::to_sentence_case("foo_bar"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ::to_sentence_case;
|
||||
use ::is_sentence_case;
|
||||
|
||||
#[test]
|
||||
fn from_camel_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
let expected: String = "Foo bar".to_owned();
|
||||
assert_eq!(to_sentence_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
let expected: String = "Foo bar".to_owned();
|
||||
assert_eq!(to_sentence_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
let expected: String = "Foo bar".to_owned();
|
||||
assert_eq!(to_sentence_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
let expected: String = "Foo bar".to_owned();
|
||||
assert_eq!(to_sentence_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
let expected: String = "Foo bar".to_owned();
|
||||
assert_eq!(to_sentence_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
let expected: String = "Foo bar".to_owned();
|
||||
assert_eq!(to_sentence_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_screaming_snake_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
let expected: String = "Foo bar".to_owned();
|
||||
assert_eq!(to_sentence_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
let expected: String = "Foo bar".to_owned();
|
||||
assert_eq!(to_sentence_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_case_with_loads_of_space() {
|
||||
let convertable_string: String = "foo bar".to_owned();
|
||||
let expected: String = "Foo bar".to_owned();
|
||||
assert_eq!(to_sentence_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_name_with_a_dot() {
|
||||
let convertable_string: String = "Robert C. Martin".to_owned();
|
||||
let expected: String = "Robert c martin".to_owned();
|
||||
assert_eq!(to_sentence_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn random_text_with_bad_chars() {
|
||||
let convertable_string: String = "Random text with *(bad) chars".to_owned();
|
||||
let expected: String = "Random text with bad chars".to_owned();
|
||||
assert_eq!(to_sentence_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trailing_bad_chars() {
|
||||
let convertable_string: String = "trailing bad_chars*(()())".to_owned();
|
||||
let expected: String = "Trailing bad chars".to_owned();
|
||||
assert_eq!(to_sentence_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leading_bad_chars() {
|
||||
let convertable_string: String = "-!#$%leading bad chars".to_owned();
|
||||
let expected: String = "Leading bad chars".to_owned();
|
||||
assert_eq!(to_sentence_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrapped_in_bad_chars() {
|
||||
let convertable_string: String = "-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
|
||||
let expected: String = "Wrapped in bad chars".to_owned();
|
||||
assert_eq!(to_sentence_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn has_a_sign() {
|
||||
let convertable_string: String = "has a + sign".to_owned();
|
||||
let expected: String = "Has a sign".to_owned();
|
||||
assert_eq!(to_sentence_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_camel_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
assert_eq!(is_sentence_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
assert_eq!(is_sentence_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
assert_eq!(is_sentence_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
assert_eq!(is_sentence_case(&convertable_string), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
assert_eq!(is_sentence_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
assert_eq!(is_sentence_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_screaming_snake_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
assert_eq!(is_sentence_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
assert_eq!(is_sentence_case(&convertable_string), false)
|
||||
}
|
||||
}
|
||||
334
third-party/vendor/Inflector/src/cases/snakecase/mod.rs
vendored
Normal file
334
third-party/vendor/Inflector/src/cases/snakecase/mod.rs
vendored
Normal file
|
|
@ -0,0 +1,334 @@
|
|||
#![deny(warnings)]
|
||||
use cases::case::*;
|
||||
/// Converts a `&str` to `snake_case` `String`
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::snakecase::to_snake_case;
|
||||
/// let mock_string: &str = "foo_bar";
|
||||
/// let expected_string: String = "foo_bar".to_string();
|
||||
/// let asserted_string: String = to_snake_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::snakecase::to_snake_case;
|
||||
/// let mock_string: &str = "HTTP Foo bar";
|
||||
/// let expected_string: String = "http_foo_bar".to_string();
|
||||
/// let asserted_string: String = to_snake_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::snakecase::to_snake_case;
|
||||
/// let mock_string: &str = "HTTPFooBar";
|
||||
/// let expected_string: String = "http_foo_bar".to_string();
|
||||
/// let asserted_string: String = to_snake_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::snakecase::to_snake_case;
|
||||
/// let mock_string: &str = "Foo bar";
|
||||
/// let expected_string: String = "foo_bar".to_string();
|
||||
/// let asserted_string: String = to_snake_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::snakecase::to_snake_case;
|
||||
/// let mock_string: &str = "Foo Bar";
|
||||
/// let expected_string: String = "foo_bar".to_string();
|
||||
/// let asserted_string: String = to_snake_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::snakecase::to_snake_case;
|
||||
/// let mock_string: &str = "FooBar";
|
||||
/// let expected_string: String = "foo_bar".to_string();
|
||||
/// let asserted_string: String = to_snake_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::snakecase::to_snake_case;
|
||||
/// let mock_string: &str = "FOO_BAR";
|
||||
/// let expected_string: String = "foo_bar".to_string();
|
||||
/// let asserted_string: String = to_snake_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::snakecase::to_snake_case;
|
||||
/// let mock_string: &str = "fooBar";
|
||||
/// let expected_string: String = "foo_bar".to_string();
|
||||
/// let asserted_string: String = to_snake_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::snakecase::to_snake_case;
|
||||
/// let mock_string: &str = "fooBar3";
|
||||
/// let expected_string: String = "foo_bar_3".to_string();
|
||||
/// let asserted_string: String = to_snake_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
pub fn to_snake_case(non_snake_case_string: &str) -> String {
|
||||
to_case_snake_like(non_snake_case_string, "_", "lower")
|
||||
}
|
||||
|
||||
/// Determines of a `&str` is `snake_case`
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::snakecase::is_snake_case;
|
||||
/// let mock_string: &str = "Foo bar string that is really really long";
|
||||
/// let asserted_bool: bool = is_snake_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::snakecase::is_snake_case;
|
||||
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
|
||||
/// let asserted_bool: bool = is_snake_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::snakecase::is_snake_case;
|
||||
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_snake_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::snakecase::is_snake_case;
|
||||
/// let mock_string: &str = "Foo Bar Is A Really Really Long String";
|
||||
/// let asserted_bool: bool = is_snake_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::snakecase::is_snake_case;
|
||||
/// let mock_string: &str = "FOO_BAR_IS_A_REALLY_REALLY_LONG_STRING";
|
||||
/// let asserted_bool: bool = is_snake_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::snakecase::is_snake_case;
|
||||
/// let mock_string: &str = "fooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_snake_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::snakecase::is_snake_case;
|
||||
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long";
|
||||
/// let asserted_bool: bool = is_snake_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::snakecase::is_snake_case;
|
||||
/// let mock_string: &str = "foo_bar1_string_that_is_really_really_long";
|
||||
/// let asserted_bool: bool = is_snake_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::snakecase::is_snake_case;
|
||||
/// let mock_string: &str = "foo_bar_1_string_that_is_really_really_long";
|
||||
/// let asserted_bool: bool = is_snake_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
///
|
||||
/// ```
|
||||
pub fn is_snake_case(test_string: &str) -> bool {
|
||||
test_string == to_snake_case(test_string.clone())
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "unstable", test))]
|
||||
mod benchmarks {
|
||||
extern crate test;
|
||||
use self::test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_snake_from_title(b: &mut Bencher) {
|
||||
b.iter(|| super::to_snake_case("Foo bar"));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_snake_from_camel(b: &mut Bencher) {
|
||||
b.iter(|| super::to_snake_case("fooBar"));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_snake_from_snake(b: &mut Bencher) {
|
||||
b.iter(|| super::to_snake_case("foo_bar_bar_bar"));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_is_snake(b: &mut Bencher) {
|
||||
b.iter(|| super::is_snake_case("Foo bar"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ::to_snake_case;
|
||||
use ::is_snake_case;
|
||||
|
||||
#[test]
|
||||
fn from_camel_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
let expected: String = "foo_bar".to_owned();
|
||||
assert_eq!(to_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
let expected: String = "foo_bar".to_owned();
|
||||
assert_eq!(to_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
let expected: String = "foo_bar".to_owned();
|
||||
assert_eq!(to_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
let expected: String = "foo_bar".to_owned();
|
||||
assert_eq!(to_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
let expected: String = "foo_bar".to_owned();
|
||||
assert_eq!(to_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
let expected: String = "foo_bar".to_owned();
|
||||
assert_eq!(to_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_screaming_snake_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
let expected: String = "foo_bar".to_owned();
|
||||
assert_eq!(to_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
let expected: String = "foo_bar".to_owned();
|
||||
assert_eq!(to_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_case_with_loads_of_space() {
|
||||
let convertable_string: String = "foo bar".to_owned();
|
||||
let expected: String = "foo_bar".to_owned();
|
||||
assert_eq!(to_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_name_with_a_dot() {
|
||||
let convertable_string: String = "Robert C. Martin".to_owned();
|
||||
let expected: String = "robert_c_martin".to_owned();
|
||||
assert_eq!(to_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn random_text_with_bad_chars() {
|
||||
let convertable_string: String = "Random text with *(bad) chars".to_owned();
|
||||
let expected: String = "random_text_with_bad_chars".to_owned();
|
||||
assert_eq!(to_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trailing_bad_chars() {
|
||||
let convertable_string: String = "trailing bad_chars*(()())".to_owned();
|
||||
let expected: String = "trailing_bad_chars".to_owned();
|
||||
assert_eq!(to_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leading_bad_chars() {
|
||||
let convertable_string: String = "-!#$%leading bad chars".to_owned();
|
||||
let expected: String = "leading_bad_chars".to_owned();
|
||||
assert_eq!(to_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrapped_in_bad_chars() {
|
||||
let convertable_string: String = "-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
|
||||
let expected: String = "wrapped_in_bad_chars".to_owned();
|
||||
assert_eq!(to_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn has_a_sign() {
|
||||
let convertable_string: String = "has a + sign".to_owned();
|
||||
let expected: String = "has_a_sign".to_owned();
|
||||
assert_eq!(to_snake_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_camel_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
assert_eq!(is_snake_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
assert_eq!(is_snake_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
assert_eq!(is_snake_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
assert_eq!(is_snake_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
assert_eq!(is_snake_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
assert_eq!(is_snake_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_screaming_snake_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
assert_eq!(is_snake_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
assert_eq!(is_snake_case(&convertable_string), true)
|
||||
}
|
||||
}
|
||||
271
third-party/vendor/Inflector/src/cases/tablecase/mod.rs
vendored
Normal file
271
third-party/vendor/Inflector/src/cases/tablecase/mod.rs
vendored
Normal file
|
|
@ -0,0 +1,271 @@
|
|||
#![deny(warnings)]
|
||||
#[cfg(feature = "heavyweight")]
|
||||
use string::pluralize::to_plural;
|
||||
#[cfg(feature = "heavyweight")]
|
||||
use cases::case::*;
|
||||
#[cfg(feature = "heavyweight")]
|
||||
/// Converts a `&str` to `table-case` `String`
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::tablecase::to_table_case;
|
||||
/// let mock_string: &str = "foo-bar";
|
||||
/// let expected_string: String = "foo_bars".to_string();
|
||||
/// let asserted_string: String = to_table_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::tablecase::to_table_case;
|
||||
/// let mock_string: &str = "FOO_BAR";
|
||||
/// let expected_string: String = "foo_bars".to_string();
|
||||
/// let asserted_string: String = to_table_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::tablecase::to_table_case;
|
||||
/// let mock_string: &str = "foo_bar";
|
||||
/// let expected_string: String = "foo_bars".to_string();
|
||||
/// let asserted_string: String = to_table_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::tablecase::to_table_case;
|
||||
/// let mock_string: &str = "Foo Bar";
|
||||
/// let expected_string: String = "foo_bars".to_string();
|
||||
/// let asserted_string: String = to_table_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::tablecase::to_table_case;
|
||||
/// let mock_string: &str = "Foo bar";
|
||||
/// let expected_string: String = "foo_bars".to_string();
|
||||
/// let asserted_string: String = to_table_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::tablecase::to_table_case;
|
||||
/// let mock_string: &str = "FooBar";
|
||||
/// let expected_string: String = "foo_bars".to_string();
|
||||
/// let asserted_string: String = to_table_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::tablecase::to_table_case;
|
||||
/// let mock_string: &str = "fooBar";
|
||||
/// let expected_string: String = "foo_bars".to_string();
|
||||
/// let asserted_string: String = to_table_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
/// ```
|
||||
pub fn to_table_case(non_table_case_string: &str) -> String {
|
||||
let snaked: String = to_case_snake_like(non_table_case_string, "_", "lower");
|
||||
let split: (&str, &str) = snaked.split_at(snaked.rfind('_').unwrap_or(0));
|
||||
format!("{}{}", split.0, to_plural(split.1))
|
||||
}
|
||||
|
||||
#[cfg(feature = "heavyweight")]
|
||||
/// Determines if a `&str` is `table-case`
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::tablecase::is_table_case;
|
||||
/// let mock_string: &str = "foo_bar_strings";
|
||||
/// let asserted_bool: bool = is_table_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::tablecase::is_table_case;
|
||||
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
|
||||
/// let asserted_bool: bool = is_table_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::tablecase::is_table_case;
|
||||
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_table_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::tablecase::is_table_case;
|
||||
/// let mock_string: &str = "fooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_table_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::tablecase::is_table_case;
|
||||
/// let mock_string: &str = "FOO_BAR_STRING_THAT_IS_REALLY_REALLY_LONG";
|
||||
/// let asserted_bool: bool = is_table_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::tablecase::is_table_case;
|
||||
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long";
|
||||
/// let asserted_bool: bool = is_table_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::tablecase::is_table_case;
|
||||
/// let mock_string: &str = "Foo bar string that is really really long";
|
||||
/// let asserted_bool: bool = is_table_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::tablecase::is_table_case;
|
||||
/// let mock_string: &str = "Foo Bar Is A Really Really Long String";
|
||||
/// let asserted_bool: bool = is_table_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
/// ```
|
||||
pub fn is_table_case(test_string: &str) -> bool {
|
||||
to_table_case(&test_string.clone()) == test_string
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "unstable", test))]
|
||||
#[cfg(feature = "heavyweight")]
|
||||
mod benchmarks {
|
||||
extern crate test;
|
||||
use self::test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_table_case(b: &mut Bencher) {
|
||||
b.iter(|| super::to_table_case("Foo bar"));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_is_table_case(b: &mut Bencher) {
|
||||
b.iter(|| super::is_table_case("Foo bar"));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(feature = "heavyweight")]
|
||||
mod tests {
|
||||
use ::to_table_case;
|
||||
use ::is_table_case;
|
||||
|
||||
#[test]
|
||||
fn from_camel_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
let expected: String = "foo_bars".to_owned();
|
||||
assert_eq!(to_table_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
let expected: String = "foo_bars".to_owned();
|
||||
assert_eq!(to_table_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
let expected: String = "foo_bars".to_owned();
|
||||
assert_eq!(to_table_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
let expected: String = "foo_bars".to_owned();
|
||||
assert_eq!(to_table_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
let expected: String = "foo_bars".to_owned();
|
||||
assert_eq!(to_table_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
let expected: String = "foo_bars".to_owned();
|
||||
assert_eq!(to_table_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_screaming_snake_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
let expected: String = "foo_bars".to_owned();
|
||||
assert_eq!(to_table_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
let expected: String = "foo_bars".to_owned();
|
||||
assert_eq!(to_table_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_table_case() {
|
||||
let convertable_string: String = "foo_bars".to_owned();
|
||||
let expected: String = "foo_bars".to_owned();
|
||||
assert_eq!(to_table_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_camel_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
assert_eq!(is_table_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
assert_eq!(is_table_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
assert_eq!(is_table_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
assert_eq!(is_table_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
assert_eq!(is_table_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
assert_eq!(is_table_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_screaming_snake_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
assert_eq!(is_table_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
assert_eq!(is_table_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_table_case() {
|
||||
let convertable_string: String = "foo_bars".to_owned();
|
||||
assert_eq!(is_table_case(&convertable_string), true)
|
||||
}
|
||||
}
|
||||
308
third-party/vendor/Inflector/src/cases/titlecase/mod.rs
vendored
Normal file
308
third-party/vendor/Inflector/src/cases/titlecase/mod.rs
vendored
Normal file
|
|
@ -0,0 +1,308 @@
|
|||
#![deny(warnings)]
|
||||
use cases::case::*;
|
||||
/// Converts a `&str` to `Title Case` `String`
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::titlecase::to_title_case;
|
||||
/// let mock_string: &str = "Foo bar";
|
||||
/// let expected_string: String = "Foo Bar".to_string();
|
||||
/// let asserted_string: String = to_title_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::titlecase::to_title_case;
|
||||
/// let mock_string: &str = "FooBar";
|
||||
/// let expected_string: String = "Foo Bar".to_string();
|
||||
/// let asserted_string: String = to_title_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::titlecase::to_title_case;
|
||||
/// let mock_string: &str = "fooBar";
|
||||
/// let expected_string: String = "Foo Bar".to_string();
|
||||
/// let asserted_string: String = to_title_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::titlecase::to_title_case;
|
||||
/// let mock_string: &str = "FOO_BAR";
|
||||
/// let expected_string: String = "Foo Bar".to_string();
|
||||
/// let asserted_string: String = to_title_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::titlecase::to_title_case;
|
||||
/// let mock_string: &str = "foo_bar";
|
||||
/// let expected_string: String = "Foo Bar".to_string();
|
||||
/// let asserted_string: String = to_title_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::titlecase::to_title_case;
|
||||
/// let mock_string: &str = "foo-bar";
|
||||
/// let expected_string: String = "Foo Bar".to_string();
|
||||
/// let asserted_string: String = to_title_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
pub fn to_title_case(non_title_case_string: &str) -> String {
|
||||
let options = CamelOptions {
|
||||
new_word: true,
|
||||
last_char: ' ',
|
||||
first_word: true,
|
||||
injectable_char: ' ',
|
||||
has_seperator: true,
|
||||
inverted: false,
|
||||
};
|
||||
to_case_camel_like(non_title_case_string, options)
|
||||
}
|
||||
|
||||
/// Determines if a `&str` is `Title Case`
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::titlecase::is_title_case;
|
||||
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
|
||||
/// let asserted_bool: bool = is_title_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::titlecase::is_title_case;
|
||||
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_title_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::titlecase::is_title_case;
|
||||
/// let mock_string: &str = "fooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_title_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::titlecase::is_title_case;
|
||||
/// let mock_string: &str = "FOO_BAR_STRING_THAT_IS_REALLY_REALLY_LONG";
|
||||
/// let asserted_bool: bool = is_title_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::titlecase::is_title_case;
|
||||
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long";
|
||||
/// let asserted_bool: bool = is_title_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::titlecase::is_title_case;
|
||||
/// let mock_string: &str = "Foo bar string that is really really long";
|
||||
/// let asserted_bool: bool = is_title_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::titlecase::is_title_case;
|
||||
/// let mock_string: &str = "foo";
|
||||
/// let asserted_bool: bool = is_title_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
/// ```
|
||||
/// use inflector::cases::titlecase::is_title_case;
|
||||
/// let mock_string: &str = "Foo Bar String That Is Really Really Long";
|
||||
/// let asserted_bool: bool = is_title_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
///
|
||||
/// ```
|
||||
pub fn is_title_case(test_string: &str) -> bool {
|
||||
test_string == to_title_case(test_string.clone())
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "unstable", test))]
|
||||
mod benchmarks {
|
||||
extern crate test;
|
||||
use self::test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_title(b: &mut Bencher) {
|
||||
b.iter(|| super::to_title_case("Foo BAR"));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_is_title(b: &mut Bencher) {
|
||||
b.iter(|| super::is_title_case("Foo bar"));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_title_from_snake(b: &mut Bencher) {
|
||||
b.iter(|| super::to_title_case("foo_bar"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ::to_title_case;
|
||||
use ::is_title_case;
|
||||
|
||||
#[test]
|
||||
fn from_camel_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
let expected: String = "Foo Bar".to_owned();
|
||||
assert_eq!(to_title_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
let expected: String = "Foo Bar".to_owned();
|
||||
assert_eq!(to_title_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
let expected: String = "Foo Bar".to_owned();
|
||||
assert_eq!(to_title_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
let expected: String = "Foo Bar".to_owned();
|
||||
assert_eq!(to_title_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
let expected: String = "Foo Bar".to_owned();
|
||||
assert_eq!(to_title_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
let expected: String = "Foo Bar".to_owned();
|
||||
assert_eq!(to_title_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_screaming_snake_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
let expected: String = "Foo Bar".to_owned();
|
||||
assert_eq!(to_title_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
let expected: String = "Foo Bar".to_owned();
|
||||
assert_eq!(to_title_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_case_with_loads_of_space() {
|
||||
let convertable_string: String = "foo bar".to_owned();
|
||||
let expected: String = "Foo Bar".to_owned();
|
||||
assert_eq!(to_title_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_name_with_a_dot() {
|
||||
let convertable_string: String = "Robert C. Martin".to_owned();
|
||||
let expected: String = "Robert C Martin".to_owned();
|
||||
assert_eq!(to_title_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn random_text_with_bad_chars() {
|
||||
let convertable_string: String = "Random text with *(bad) chars".to_owned();
|
||||
let expected: String = "Random Text With Bad Chars".to_owned();
|
||||
assert_eq!(to_title_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trailing_bad_chars() {
|
||||
let convertable_string: String = "trailing bad_chars*(()())".to_owned();
|
||||
let expected: String = "Trailing Bad Chars".to_owned();
|
||||
assert_eq!(to_title_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leading_bad_chars() {
|
||||
let convertable_string: String = "-!#$%leading bad chars".to_owned();
|
||||
let expected: String = "Leading Bad Chars".to_owned();
|
||||
assert_eq!(to_title_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrapped_in_bad_chars() {
|
||||
let convertable_string: String = "-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
|
||||
let expected: String = "Wrapped In Bad Chars".to_owned();
|
||||
assert_eq!(to_title_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn has_a_sign() {
|
||||
let convertable_string: String = "has a + sign".to_owned();
|
||||
let expected: String = "Has A Sign".to_owned();
|
||||
assert_eq!(to_title_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_camel_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
assert_eq!(is_title_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
assert_eq!(is_title_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
assert_eq!(is_title_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
assert_eq!(is_title_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
assert_eq!(is_title_case(&convertable_string), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
assert_eq!(is_title_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_screaming_snake_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
assert_eq!(is_title_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
assert_eq!(is_title_case(&convertable_string), false)
|
||||
}
|
||||
}
|
||||
|
||||
320
third-party/vendor/Inflector/src/cases/traincase/mod.rs
vendored
Normal file
320
third-party/vendor/Inflector/src/cases/traincase/mod.rs
vendored
Normal file
|
|
@ -0,0 +1,320 @@
|
|||
#![deny(warnings)]
|
||||
use cases::case::*;
|
||||
/// Determines if a `&str` is `Train-Case`
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::traincase::is_train_case;
|
||||
/// let mock_string: &str = "Foo-Bar-String-That-Is-Really-Really-Long";
|
||||
/// let asserted_bool: bool = is_train_case(mock_string);
|
||||
/// assert!(asserted_bool == true);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::traincase::is_train_case;
|
||||
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
|
||||
/// let asserted_bool: bool = is_train_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::traincase::is_train_case;
|
||||
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_train_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::traincase::is_train_case;
|
||||
/// let mock_string: &str = "fooBarIsAReallyReallyLongString";
|
||||
/// let asserted_bool: bool = is_train_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::traincase::is_train_case;
|
||||
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long";
|
||||
/// let asserted_bool: bool = is_train_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::traincase::is_train_case;
|
||||
/// let mock_string: &str = "Foo bar string that is really really long";
|
||||
/// let asserted_bool: bool = is_train_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::traincase::is_train_case;
|
||||
/// let mock_string: &str = "Foo Bar Is A Really Really Long String";
|
||||
/// let asserted_bool: bool = is_train_case(mock_string);
|
||||
/// assert!(asserted_bool == false);
|
||||
///
|
||||
/// ```
|
||||
pub fn is_train_case(test_string: &str) -> bool {
|
||||
test_string == to_train_case(test_string.clone())
|
||||
}
|
||||
|
||||
|
||||
/// Converts a `&str` to `Train-Case` `String`
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::traincase::to_train_case;
|
||||
/// let mock_string: &str = "foo-bar";
|
||||
/// let expected_string: String = "Foo-Bar".to_string();
|
||||
/// let asserted_string: String = to_train_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::traincase::to_train_case;
|
||||
/// let mock_string: &str = "FOO_BAR";
|
||||
/// let expected_string: String = "Foo-Bar".to_string();
|
||||
/// let asserted_string: String = to_train_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::traincase::to_train_case;
|
||||
/// let mock_string: &str = "foo_bar";
|
||||
/// let expected_string: String = "Foo-Bar".to_string();
|
||||
/// let asserted_string: String = to_train_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::traincase::to_train_case;
|
||||
/// let mock_string: &str = "Foo Bar";
|
||||
/// let expected_string: String = "Foo-Bar".to_string();
|
||||
/// let asserted_string: String = to_train_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::traincase::to_train_case;
|
||||
/// let mock_string: &str = "Foo bar";
|
||||
/// let expected_string: String = "Foo-Bar".to_string();
|
||||
/// let asserted_string: String = to_train_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::traincase::to_train_case;
|
||||
/// let mock_string: &str = "FooBar";
|
||||
/// let expected_string: String = "Foo-Bar".to_string();
|
||||
/// let asserted_string: String = to_train_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use inflector::cases::traincase::to_train_case;
|
||||
/// let mock_string: &str = "fooBar";
|
||||
/// let expected_string: String = "Foo-Bar".to_string();
|
||||
/// let asserted_string: String = to_train_case(mock_string);
|
||||
/// assert!(asserted_string == expected_string);
|
||||
///
|
||||
/// ```
|
||||
pub fn to_train_case(non_train_case_string: &str) -> String {
|
||||
let options = CamelOptions {
|
||||
new_word: true,
|
||||
last_char: ' ',
|
||||
first_word: true,
|
||||
injectable_char: '-',
|
||||
has_seperator: true,
|
||||
inverted: false,
|
||||
};
|
||||
to_case_camel_like(non_train_case_string, options)
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "unstable", test))]
|
||||
mod benchmarks {
|
||||
extern crate test;
|
||||
use self::test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_train(b: &mut Bencher) {
|
||||
b.iter(|| super::to_train_case("Foo bar"));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_is_train(b: &mut Bencher) {
|
||||
b.iter(|| super::is_train_case("Foo bar"));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_train_from_snake(b: &mut Bencher) {
|
||||
b.iter(|| super::to_train_case("test_test_test"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ::to_train_case;
|
||||
use ::is_train_case;
|
||||
|
||||
#[test]
|
||||
fn from_camel_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
let expected: String = "Foo-Bar".to_owned();
|
||||
assert_eq!(to_train_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
let expected: String = "Foo-Bar".to_owned();
|
||||
assert_eq!(to_train_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
let expected: String = "Foo-Bar".to_owned();
|
||||
assert_eq!(to_train_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
let expected: String = "Foo-Bar".to_owned();
|
||||
assert_eq!(to_train_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
let expected: String = "Foo-Bar".to_owned();
|
||||
assert_eq!(to_train_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
let expected: String = "Foo-Bar".to_owned();
|
||||
assert_eq!(to_train_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_screaming_snake_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
let expected: String = "Foo-Bar".to_owned();
|
||||
assert_eq!(to_train_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
let expected: String = "Foo-Bar".to_owned();
|
||||
assert_eq!(to_train_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_case_with_loads_of_space() {
|
||||
let convertable_string: String = "foo bar".to_owned();
|
||||
let expected: String = "Foo-Bar".to_owned();
|
||||
assert_eq!(to_train_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_name_with_a_dot() {
|
||||
let convertable_string: String = "Robert C. Martin".to_owned();
|
||||
let expected: String = "Robert-C-Martin".to_owned();
|
||||
assert_eq!(to_train_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn random_text_with_bad_chars() {
|
||||
let convertable_string: String = "Random text with *(bad) chars".to_owned();
|
||||
let expected: String = "Random-Text-With-Bad-Chars".to_owned();
|
||||
assert_eq!(to_train_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trailing_bad_chars() {
|
||||
let convertable_string: String = "trailing bad_chars*(()())".to_owned();
|
||||
let expected: String = "Trailing-Bad-Chars".to_owned();
|
||||
assert_eq!(to_train_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leading_bad_chars() {
|
||||
let convertable_string: String = "-!#$%leading bad chars".to_owned();
|
||||
let expected: String = "Leading-Bad-Chars".to_owned();
|
||||
assert_eq!(to_train_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrapped_in_bad_chars() {
|
||||
let convertable_string: String = "-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
|
||||
let expected: String = "Wrapped-In-Bad-Chars".to_owned();
|
||||
assert_eq!(to_train_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn has_a_sign() {
|
||||
let convertable_string: String = "has a + sign".to_owned();
|
||||
let expected: String = "Has-A-Sign".to_owned();
|
||||
assert_eq!(to_train_case(&convertable_string), expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_camel_case() {
|
||||
let convertable_string: String = "fooBar".to_owned();
|
||||
assert_eq!(is_train_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_pascal_case() {
|
||||
let convertable_string: String = "FooBar".to_owned();
|
||||
assert_eq!(is_train_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_kebab_case() {
|
||||
let convertable_string: String = "foo-bar".to_owned();
|
||||
assert_eq!(is_train_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_sentence_case() {
|
||||
let convertable_string: String = "Foo bar".to_owned();
|
||||
assert_eq!(is_train_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_title_case() {
|
||||
let convertable_string: String = "Foo Bar".to_owned();
|
||||
assert_eq!(is_train_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_train_case() {
|
||||
let convertable_string: String = "Foo-Bar".to_owned();
|
||||
assert_eq!(is_train_case(&convertable_string), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_screaming_snake_case() {
|
||||
let convertable_string: String = "FOO_BAR".to_owned();
|
||||
assert_eq!(is_train_case(&convertable_string), false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_correct_from_snake_case() {
|
||||
let convertable_string: String = "foo_bar".to_owned();
|
||||
assert_eq!(is_train_case(&convertable_string), false)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue