Skip to content

Commit a2577a4

Browse files
committed
add test for non_snake_case case
1 parent 3a1083b commit a2577a4

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

clippy_utils/src/str_utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,10 @@ pub fn to_snake_case(name: &str) -> String {
262262
/// Returns a `CamelCase` version of the input
263263
/// ```
264264
/// use clippy_utils::str_utils::to_camel_case;
265-
/// assert_eq!(to_snake_case("abc_def"), "AbcDef");
266-
/// assert_eq!(to_snake_case("a_b_c_d"), "ABCD");
267-
/// assert_eq!(to_snake_case("abc_d_d"), "AbcDD");
268-
/// assert_eq!(to_snake_case("abc1_d_d"), "Abc1DD");
265+
/// assert_eq!(to_camel_case("abc_def"), "AbcDef");
266+
/// assert_eq!(to_camel_case("a_b_c_d"), "ABCD");
267+
/// assert_eq!(to_camel_case("abc_d_d"), "AbcDD");
268+
/// assert_eq!(to_camel_case("abc1_d_d"), "Abc1DD");
269269
/// ```
270270
pub fn to_camel_case(item_name: &str) -> String {
271271
let mut s = String::new();

tests/ui/struct_fields.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ struct DoublePostfix {
4545
c_some_data: bool,
4646
}
4747

48+
#[allow(non_snake_case)]
49+
struct NotSnakeCase {
50+
//~^ ERROR: all fields have the same postfix: `someData`
51+
a_someData: bool,
52+
b_someData: bool,
53+
c_someData: bool,
54+
}
55+
#[allow(non_snake_case)]
56+
struct NotSnakeCase2 {
57+
//~^ ERROR: all fields have the same prefix: `someData`
58+
someData_c: bool,
59+
someData_b: bool,
60+
someData_a_b: bool,
61+
}
62+
4863
// no error, threshold is 3 fiels by default
4964
struct Fooo {
5065
foo: u8,

tests/ui/struct_fields.stderr

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,34 @@ LL | | }
6565
|
6666
= help: remove the postfixes
6767

68+
error: all fields have the same postfix: `someData`
69+
--> $DIR/struct_fields.rs:49:1
70+
|
71+
LL | / struct NotSnakeCase {
72+
LL | |
73+
LL | | a_someData: bool,
74+
LL | | b_someData: bool,
75+
LL | | c_someData: bool,
76+
LL | | }
77+
| |_^
78+
|
79+
= help: remove the postfixes
80+
81+
error: all fields have the same prefix: `someData`
82+
--> $DIR/struct_fields.rs:56:1
83+
|
84+
LL | / struct NotSnakeCase2 {
85+
LL | |
86+
LL | | someData_c: bool,
87+
LL | | someData_b: bool,
88+
LL | | someData_a_b: bool,
89+
LL | | }
90+
| |_^
91+
|
92+
= help: remove the prefixes
93+
6894
error: all fields have the same prefix: `prefix`
69-
--> $DIR/struct_fields.rs:54:1
95+
--> $DIR/struct_fields.rs:69:1
7096
|
7197
LL | / struct NonCaps {
7298
LL | |
@@ -79,7 +105,7 @@ LL | | }
79105
= help: remove the prefixes
80106

81107
error: all fields have the same prefix: `_type`
82-
--> $DIR/struct_fields.rs:104:5
108+
--> $DIR/struct_fields.rs:119:5
83109
|
84110
LL | / struct DoLint {
85111
LL | |
@@ -93,7 +119,7 @@ LL | | }
93119
= help: remove the prefixes
94120

95121
error: all fields have the same postfix: `type`
96-
--> $DIR/struct_fields.rs:112:5
122+
--> $DIR/struct_fields.rs:127:5
97123
|
98124
LL | / struct DoLintToo {
99125
LL | |
@@ -105,5 +131,5 @@ LL | | }
105131
|
106132
= help: remove the postfixes
107133

108-
error: aborting due to 9 previous errors
134+
error: aborting due to 11 previous errors
109135

0 commit comments

Comments
 (0)