@@ -61,7 +61,9 @@ fn is_upper_snake_case(ident: &str) -> bool {
61
61
62
62
fn is_camel_case ( ident : & str ) -> bool {
63
63
// We assume that the string is either snake case or camel case.
64
- ident. chars ( ) . all ( |c| c != '_' )
64
+ // `_` is allowed only at the beginning or in the end of identifier, not between characters.
65
+ ident. trim_matches ( '_' ) . chars ( ) . all ( |c| c != '_' )
66
+ && ident. chars ( ) . find ( |c| c. is_alphabetic ( ) ) . map ( |c| c. is_ascii_uppercase ( ) ) . unwrap_or ( true )
65
67
}
66
68
67
69
#[ cfg( test) ]
@@ -80,13 +82,18 @@ mod tests {
80
82
fn test_to_lower_snake_case ( ) {
81
83
check ( to_lower_snake_case, "lower_snake_case" , expect ! [ [ "" ] ] ) ;
82
84
check ( to_lower_snake_case, "UPPER_SNAKE_CASE" , expect ! [ [ "upper_snake_case" ] ] ) ;
85
+ check ( to_lower_snake_case, "Weird_Case" , expect ! [ [ "weird_case" ] ] ) ;
83
86
check ( to_lower_snake_case, "CamelCase" , expect ! [ [ "camel_case" ] ] ) ;
84
87
}
85
88
86
89
#[ test]
87
90
fn test_to_camel_case ( ) {
88
91
check ( to_camel_case, "CamelCase" , expect ! [ [ "" ] ] ) ;
92
+ check ( to_camel_case, "CamelCase_" , expect ! [ [ "" ] ] ) ;
93
+ check ( to_camel_case, "_CamelCase" , expect ! [ [ "" ] ] ) ;
89
94
check ( to_camel_case, "lower_snake_case" , expect ! [ [ "LowerSnakeCase" ] ] ) ;
90
95
check ( to_camel_case, "UPPER_SNAKE_CASE" , expect ! [ [ "UpperSnakeCase" ] ] ) ;
96
+ check ( to_camel_case, "Weird_Case" , expect ! [ [ "WeirdCase" ] ] ) ;
97
+ check ( to_camel_case, "name" , expect ! [ [ "Name" ] ] ) ;
91
98
}
92
99
}
0 commit comments