From a2577a4a524c2393e99a1ed0c52d7f87e8e5d097 Mon Sep 17 00:00:00 2001 From: jonboh Date: Thu, 28 Sep 2023 22:07:08 +0200 Subject: [PATCH] add test for non_snake_case case --- clippy_utils/src/str_utils.rs | 8 ++++---- tests/ui/struct_fields.rs | 15 +++++++++++++++ tests/ui/struct_fields.stderr | 34 ++++++++++++++++++++++++++++++---- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/clippy_utils/src/str_utils.rs b/clippy_utils/src/str_utils.rs index 75498e17f335..69c25b427e1c 100644 --- a/clippy_utils/src/str_utils.rs +++ b/clippy_utils/src/str_utils.rs @@ -262,10 +262,10 @@ pub fn to_snake_case(name: &str) -> String { /// Returns a `CamelCase` version of the input /// ``` /// use clippy_utils::str_utils::to_camel_case; -/// assert_eq!(to_snake_case("abc_def"), "AbcDef"); -/// assert_eq!(to_snake_case("a_b_c_d"), "ABCD"); -/// assert_eq!(to_snake_case("abc_d_d"), "AbcDD"); -/// assert_eq!(to_snake_case("abc1_d_d"), "Abc1DD"); +/// assert_eq!(to_camel_case("abc_def"), "AbcDef"); +/// assert_eq!(to_camel_case("a_b_c_d"), "ABCD"); +/// assert_eq!(to_camel_case("abc_d_d"), "AbcDD"); +/// assert_eq!(to_camel_case("abc1_d_d"), "Abc1DD"); /// ``` pub fn to_camel_case(item_name: &str) -> String { let mut s = String::new(); diff --git a/tests/ui/struct_fields.rs b/tests/ui/struct_fields.rs index 8e5d901a0ce9..f08916db3299 100644 --- a/tests/ui/struct_fields.rs +++ b/tests/ui/struct_fields.rs @@ -45,6 +45,21 @@ struct DoublePostfix { c_some_data: bool, } +#[allow(non_snake_case)] +struct NotSnakeCase { + //~^ ERROR: all fields have the same postfix: `someData` + a_someData: bool, + b_someData: bool, + c_someData: bool, +} +#[allow(non_snake_case)] +struct NotSnakeCase2 { + //~^ ERROR: all fields have the same prefix: `someData` + someData_c: bool, + someData_b: bool, + someData_a_b: bool, +} + // no error, threshold is 3 fiels by default struct Fooo { foo: u8, diff --git a/tests/ui/struct_fields.stderr b/tests/ui/struct_fields.stderr index cbbe456b30bc..8ecd4d0e3343 100644 --- a/tests/ui/struct_fields.stderr +++ b/tests/ui/struct_fields.stderr @@ -65,8 +65,34 @@ LL | | } | = help: remove the postfixes +error: all fields have the same postfix: `someData` + --> $DIR/struct_fields.rs:49:1 + | +LL | / struct NotSnakeCase { +LL | | +LL | | a_someData: bool, +LL | | b_someData: bool, +LL | | c_someData: bool, +LL | | } + | |_^ + | + = help: remove the postfixes + +error: all fields have the same prefix: `someData` + --> $DIR/struct_fields.rs:56:1 + | +LL | / struct NotSnakeCase2 { +LL | | +LL | | someData_c: bool, +LL | | someData_b: bool, +LL | | someData_a_b: bool, +LL | | } + | |_^ + | + = help: remove the prefixes + error: all fields have the same prefix: `prefix` - --> $DIR/struct_fields.rs:54:1 + --> $DIR/struct_fields.rs:69:1 | LL | / struct NonCaps { LL | | @@ -79,7 +105,7 @@ LL | | } = help: remove the prefixes error: all fields have the same prefix: `_type` - --> $DIR/struct_fields.rs:104:5 + --> $DIR/struct_fields.rs:119:5 | LL | / struct DoLint { LL | | @@ -93,7 +119,7 @@ LL | | } = help: remove the prefixes error: all fields have the same postfix: `type` - --> $DIR/struct_fields.rs:112:5 + --> $DIR/struct_fields.rs:127:5 | LL | / struct DoLintToo { LL | | @@ -105,5 +131,5 @@ LL | | } | = help: remove the postfixes -error: aborting due to 9 previous errors +error: aborting due to 11 previous errors