blob: cd7e46119470e6baf1e581c46c490aead86b2012 [file] [log] [blame]
Manuel Klimek8f9e4442015-10-22 14:54:50 +00001// RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
Alexander Kornienko76c28802015-08-19 11:15:36 +00002// RUN: -config='{CheckOptions: [ \
3// RUN: {key: readability-identifier-naming.AbstractClassCase, value: CamelCase}, \
4// RUN: {key: readability-identifier-naming.AbstractClassPrefix, value: 'A'}, \
5// RUN: {key: readability-identifier-naming.ClassCase, value: CamelCase}, \
6// RUN: {key: readability-identifier-naming.ClassPrefix, value: 'C'}, \
7// RUN: {key: readability-identifier-naming.ClassConstantCase, value: CamelCase}, \
8// RUN: {key: readability-identifier-naming.ClassConstantPrefix, value: 'k'}, \
9// RUN: {key: readability-identifier-naming.ClassMemberCase, value: CamelCase}, \
10// RUN: {key: readability-identifier-naming.ClassMethodCase, value: camelBack}, \
11// RUN: {key: readability-identifier-naming.ConstantCase, value: UPPER_CASE}, \
12// RUN: {key: readability-identifier-naming.ConstantSuffix, value: '_CST'}, \
13// RUN: {key: readability-identifier-naming.ConstexprFunctionCase, value: lower_case}, \
14// RUN: {key: readability-identifier-naming.ConstexprMethodCase, value: lower_case}, \
15// RUN: {key: readability-identifier-naming.ConstexprVariableCase, value: lower_case}, \
16// RUN: {key: readability-identifier-naming.EnumCase, value: CamelCase}, \
17// RUN: {key: readability-identifier-naming.EnumPrefix, value: 'E'}, \
18// RUN: {key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE}, \
19// RUN: {key: readability-identifier-naming.FunctionCase, value: camelBack}, \
20// RUN: {key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE}, \
21// RUN: {key: readability-identifier-naming.GlobalFunctionCase, value: CamelCase}, \
22// RUN: {key: readability-identifier-naming.GlobalVariableCase, value: lower_case}, \
23// RUN: {key: readability-identifier-naming.GlobalVariablePrefix, value: 'g_'}, \
24// RUN: {key: readability-identifier-naming.InlineNamespaceCase, value: lower_case}, \
25// RUN: {key: readability-identifier-naming.LocalConstantCase, value: CamelCase}, \
26// RUN: {key: readability-identifier-naming.LocalConstantPrefix, value: 'k'}, \
27// RUN: {key: readability-identifier-naming.LocalVariableCase, value: lower_case}, \
28// RUN: {key: readability-identifier-naming.MemberCase, value: CamelCase}, \
29// RUN: {key: readability-identifier-naming.MemberPrefix, value: 'm_'}, \
30// RUN: {key: readability-identifier-naming.ConstantMemberCase, value: lower_case}, \
31// RUN: {key: readability-identifier-naming.PrivateMemberPrefix, value: '__'}, \
32// RUN: {key: readability-identifier-naming.ProtectedMemberPrefix, value: '_'}, \
33// RUN: {key: readability-identifier-naming.PublicMemberCase, value: lower_case}, \
34// RUN: {key: readability-identifier-naming.MethodCase, value: camelBack}, \
35// RUN: {key: readability-identifier-naming.PrivateMethodPrefix, value: '__'}, \
36// RUN: {key: readability-identifier-naming.ProtectedMethodPrefix, value: '_'}, \
37// RUN: {key: readability-identifier-naming.NamespaceCase, value: lower_case}, \
38// RUN: {key: readability-identifier-naming.ParameterCase, value: camelBack}, \
39// RUN: {key: readability-identifier-naming.ParameterPrefix, value: 'a_'}, \
40// RUN: {key: readability-identifier-naming.ConstantParameterCase, value: camelBack}, \
41// RUN: {key: readability-identifier-naming.ConstantParameterPrefix, value: 'i_'}, \
42// RUN: {key: readability-identifier-naming.ParameterPackCase, value: camelBack}, \
43// RUN: {key: readability-identifier-naming.PureFunctionCase, value: lower_case}, \
44// RUN: {key: readability-identifier-naming.PureMethodCase, value: camelBack}, \
45// RUN: {key: readability-identifier-naming.StaticConstantCase, value: UPPER_CASE}, \
46// RUN: {key: readability-identifier-naming.StaticVariableCase, value: camelBack}, \
47// RUN: {key: readability-identifier-naming.StaticVariablePrefix, value: 's_'}, \
48// RUN: {key: readability-identifier-naming.StructCase, value: lower_case}, \
49// RUN: {key: readability-identifier-naming.TemplateParameterCase, value: UPPER_CASE}, \
50// RUN: {key: readability-identifier-naming.TemplateTemplateParameterCase, value: CamelCase}, \
51// RUN: {key: readability-identifier-naming.TemplateUsingCase, value: lower_case}, \
52// RUN: {key: readability-identifier-naming.TemplateUsingPrefix, value: 'u_'}, \
53// RUN: {key: readability-identifier-naming.TypeTemplateParameterCase, value: camelBack}, \
54// RUN: {key: readability-identifier-naming.TypeTemplateParameterSuffix, value: '_t'}, \
55// RUN: {key: readability-identifier-naming.TypedefCase, value: lower_case}, \
56// RUN: {key: readability-identifier-naming.TypedefSuffix, value: '_t'}, \
57// RUN: {key: readability-identifier-naming.UnionCase, value: CamelCase}, \
58// RUN: {key: readability-identifier-naming.UnionPrefix, value: 'U'}, \
59// RUN: {key: readability-identifier-naming.UsingCase, value: lower_case}, \
60// RUN: {key: readability-identifier-naming.ValueTemplateParameterCase, value: camelBack}, \
61// RUN: {key: readability-identifier-naming.VariableCase, value: lower_case}, \
62// RUN: {key: readability-identifier-naming.VirtualMethodCase, value: UPPER_CASE}, \
63// RUN: {key: readability-identifier-naming.VirtualMethodPrefix, value: 'v_'}, \
64// RUN: {key: readability-identifier-naming.IgnoreFailedSplit, value: 0} \
Alexander Kornienko30c423b2015-10-01 09:19:40 +000065// RUN: ]}' -- -std=c++11 -fno-delayed-template-parsing \
66// RUN: -I%S/Inputs/readability-identifier-naming \
67// RUN: -isystem %S/Inputs/readability-identifier-naming/system
Alexander Kornienko76c28802015-08-19 11:15:36 +000068
Alexander Kornienko3d777682015-09-28 08:59:12 +000069// clang-format off
70
Alexander Kornienko30c423b2015-10-01 09:19:40 +000071#include <system-header.h>
72#include "user-header.h"
73// NO warnings or fixes expected from declarations within header files without
74// the -header-filter= option
75
Alexander Kornienko76c28802015-08-19 11:15:36 +000076namespace FOO_NS {
77// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for namespace 'FOO_NS' [readability-identifier-naming]
78// CHECK-FIXES: {{^}}namespace foo_ns {{{$}}
79inline namespace InlineNamespace {
80// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for inline namespace 'InlineNamespace'
81// CHECK-FIXES: {{^}}inline namespace inline_namespace {{{$}}
82
Alexander Kornienko30c423b2015-10-01 09:19:40 +000083SYSTEM_NS::structure g_s1;
84// NO warnings or fixes expected as SYSTEM_NS and structure are declared in a header file
85
86USER_NS::object g_s2;
87// NO warnings or fixes expected as USER_NS and object are declared in a header file
88
89SYSTEM_MACRO(var1);
90// NO warnings or fixes expected as var1 is from macro expansion
91
92USER_MACRO(var2);
93// NO warnings or fixes expected as var2 is declared in a macro expansion
94
95int global;
96#define USE_IN_MACRO(m) auto use_##m = m
97USE_IN_MACRO(global);
98// NO warnings or fixes expected as global is used in a macro expansion
99
Alexander Kornienko76c28802015-08-19 11:15:36 +0000100#define BLA int FOO_bar
101BLA;
Alexander Kornienko30c423b2015-10-01 09:19:40 +0000102// NO warnings or fixes expected as FOO_bar is from macro expansion
Alexander Kornienko76c28802015-08-19 11:15:36 +0000103
104enum my_enumeration {
105// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for enum 'my_enumeration'
106// CHECK-FIXES: {{^}}enum EMyEnumeration {{{$}}
107 MyConstant = 1,
108// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for enum constant 'MyConstant'
109// CHECK-FIXES: {{^}} MY_CONSTANT = 1,{{$}}
110 your_CONST = 1,
111// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for enum constant 'your_CONST'
112// CHECK-FIXES: {{^}} YOUR_CONST = 1,{{$}}
113 THIS_ConstValue = 1,
114// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for enum constant 'THIS_ConstValue'
115// CHECK-FIXES: {{^}} THIS_CONST_VALUE = 1,{{$}}
116};
117
118constexpr int ConstExpr_variable = MyConstant;
119// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for constexpr variable 'ConstExpr_variable'
120// CHECK-FIXES: {{^}}constexpr int const_expr_variable = MY_CONSTANT;{{$}}
121
122class my_class {
123// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for class 'my_class'
124// CHECK-FIXES: {{^}}class CMyClass {{{$}}
125 my_class();
Alexander Kornienko30c423b2015-10-01 09:19:40 +0000126// CHECK-FIXES: {{^}} CMyClass();{{$}}
127
128 ~
129 my_class();
130// (space in destructor token test, we could check trigraph but they will be deprecated)
131// CHECK-FIXES: {{^}} ~{{$}}
132// CHECK-FIXES: {{^}} CMyClass();{{$}}
Alexander Kornienko76c28802015-08-19 11:15:36 +0000133
134 const int MEMBER_one_1 = ConstExpr_variable;
135// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: invalid case style for constant member 'MEMBER_one_1'
136// CHECK-FIXES: {{^}} const int member_one_1 = const_expr_variable;{{$}}
137 int member2 = 2;
138// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: invalid case style for private member 'member2'
139// CHECK-FIXES: {{^}} int __member2 = 2;{{$}}
140
141private:
142 int private_member = 3;
143// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for private member 'private_member'
144// CHECK-FIXES: {{^}} int __private_member = 3;{{$}}
145
146protected:
147 int ProtMember;
148// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for protected member 'ProtMember'
149// CHECK-FIXES: {{^}} int _ProtMember;{{$}}
150
151public:
152 int PubMem;
153// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for public member 'PubMem'
154// CHECK-FIXES: {{^}} int pub_mem;{{$}}
155
156 static const int classConstant;
157// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for class constant 'classConstant'
158// CHECK-FIXES: {{^}} static const int kClassConstant;{{$}}
159 static int ClassMember_2;
160// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for class member 'ClassMember_2'
161// CHECK-FIXES: {{^}} static int ClassMember2;{{$}}
162};
163
164const int my_class::classConstant = 4;
165// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for class constant 'classConstant'
Alexander Kornienko30c423b2015-10-01 09:19:40 +0000166// CHECK-FIXES: {{^}}const int CMyClass::kClassConstant = 4;{{$}}
Alexander Kornienko76c28802015-08-19 11:15:36 +0000167
168int my_class::ClassMember_2 = 5;
169// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for class member 'ClassMember_2'
Alexander Kornienko30c423b2015-10-01 09:19:40 +0000170// CHECK-FIXES: {{^}}int CMyClass::ClassMember2 = 5;{{$}}
171
172class my_derived_class : public virtual my_class {};
173// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for class 'my_derived_class'
174// CHECK-FIXES: {{^}}class CMyDerivedClass : public virtual CMyClass {};{{$}}
175
176class CMyWellNamedClass {};
177// No warning expected as this class is well named.
178
179template<typename T>
180// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for type template parameter 'T'
181// CHECK-FIXES: {{^}}template<typename t_t>{{$}}
182class my_templated_class : CMyWellNamedClass {};
183// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for class 'my_templated_class'
184// CHECK-FIXES: {{^}}class CMyTemplatedClass : CMyWellNamedClass {};{{$}}
185
186template<typename T>
187// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for type template parameter 'T'
188// CHECK-FIXES: {{^}}template<typename t_t>{{$}}
189class my_other_templated_class : my_templated_class< my_class>, private my_derived_class {};
190// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for class 'my_other_templated_class'
191// CHECK-FIXES: {{^}}class CMyOtherTemplatedClass : CMyTemplatedClass< CMyClass>, private CMyDerivedClass {};{{$}}
192
193template<typename t_t>
194using MYSUPER_TPL = my_other_templated_class <:: FOO_NS ::my_class>;
195// CHECK-FIXES: {{^}}using MYSUPER_TPL = CMyOtherTemplatedClass <:: foo_ns ::CMyClass>;{{$}}
Alexander Kornienko76c28802015-08-19 11:15:36 +0000196
197const int global_Constant = 6;
198// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for global constant 'global_Constant'
199// CHECK-FIXES: {{^}}const int GLOBAL_CONSTANT = 6;{{$}}
200int Global_variable = 7;
201// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for global variable 'Global_variable'
202// CHECK-FIXES: {{^}}int g_global_variable = 7;{{$}}
203
204void global_function(int PARAMETER_1, int const CONST_parameter) {
205// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for global function 'global_function'
206// CHECK-MESSAGES: :[[@LINE-2]]:22: warning: invalid case style for parameter 'PARAMETER_1'
207// CHECK-MESSAGES: :[[@LINE-3]]:39: warning: invalid case style for constant parameter 'CONST_parameter'
208// CHECK-FIXES: {{^}}void GlobalFunction(int a_parameter1, int const i_constParameter) {{{$}}
209 static const int THIS_static_ConsTant = 4;
210// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for static constant 'THIS_static_ConsTant'
211// CHECK-FIXES: {{^}} static const int THIS_STATIC_CONS_TANT = 4;{{$}}
212 static int THIS_static_variable;
213// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for static variable 'THIS_static_variable'
214// CHECK-FIXES: {{^}} static int s_thisStaticVariable;{{$}}
215 int const local_Constant = 3;
216// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for local constant 'local_Constant'
217// CHECK-FIXES: {{^}} int const kLocalConstant = 3;{{$}}
218 int LOCAL_VARIABLE;
219// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for local variable 'LOCAL_VARIABLE'
220// CHECK-FIXES: {{^}} int local_variable;{{$}}
221
222 int LOCAL_Array__[] = {0, 1, 2};
223// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for local variable 'LOCAL_Array__'
224// CHECK-FIXES: {{^}} int local_array[] = {0, 1, 2};{{$}}
225
226 for (auto _ : LOCAL_Array__) {
227 }
228}
229
230template<typename ... TYPE_parameters>
231// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for type template parameter 'TYPE_parameters'
232// CHECK-FIXES: {{^}}template<typename ... typeParameters_t>{{$}}
233void Global_Fun(TYPE_parameters... PARAMETER_PACK) {
234// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for global function 'Global_Fun'
235// CHECK-MESSAGES: :[[@LINE-2]]:17: warning: invalid case style for parameter pack 'PARAMETER_PACK'
Alexander Kornienko30c423b2015-10-01 09:19:40 +0000236// CHECK-FIXES: {{^}}void GlobalFun(typeParameters_t... parameterPack) {{{$}}
Alexander Kornienko76c28802015-08-19 11:15:36 +0000237 global_function(1, 2);
238// CHECK-FIXES: {{^}} GlobalFunction(1, 2);{{$}}
239 FOO_bar = Global_variable;
240// CHECK-FIXES: {{^}} FOO_bar = g_global_variable;{{$}}
241// NO fix expected for FOO_bar declared in macro expansion
242}
243
244template<template<typename> class TPL_parameter, int COUNT_params, typename ... TYPE_parameters>
245// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for template template parameter 'TPL_parameter'
246// CHECK-MESSAGES: :[[@LINE-2]]:50: warning: invalid case style for value template parameter 'COUNT_params'
247// CHECK-MESSAGES: :[[@LINE-3]]:68: warning: invalid case style for type template parameter 'TYPE_parameters'
248// CHECK-FIXES: {{^}}template<template<typename> class TplParameter, int countParams, typename ... typeParameters_t>{{$}}
249class test_CLASS {
250// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for class 'test_CLASS'
251// CHECK-FIXES: {{^}}class CTestClass {{{$}}
252};
253
254class abstract_class {
255// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for abstract class 'abstract_class'
256// CHECK-FIXES: {{^}}class AAbstractClass {{{$}}
257 virtual ~abstract_class() = 0;
Alexander Kornienko30c423b2015-10-01 09:19:40 +0000258// CHECK-FIXES: {{^}} virtual ~AAbstractClass() = 0;{{$}}
Alexander Kornienko76c28802015-08-19 11:15:36 +0000259 virtual void VIRTUAL_METHOD();
260// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for virtual method 'VIRTUAL_METHOD'
261// CHECK-FIXES: {{^}} virtual void v_VIRTUAL_METHOD();{{$}}
262 void non_Virtual_METHOD() {}
263// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for private method 'non_Virtual_METHOD'
264// CHECK-FIXES: {{^}} void __non_Virtual_METHOD() {}{{$}}
Alexander Kornienko30c423b2015-10-01 09:19:40 +0000265
266public:
Alexander Kornienko76c28802015-08-19 11:15:36 +0000267 static void CLASS_METHOD() {}
268// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for class method 'CLASS_METHOD'
269// CHECK-FIXES: {{^}} static void classMethod() {}{{$}}
270
271 constexpr int CST_expr_Method() { return 2; }
272// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for constexpr method 'CST_expr_Method'
273// CHECK-FIXES: {{^}} constexpr int cst_expr_method() { return 2; }{{$}}
274
275private:
276 void PRIVate_Method();
277// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for private method 'PRIVate_Method'
278// CHECK-FIXES: {{^}} void __PRIVate_Method();{{$}}
279protected:
280 void protected_Method();
281// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for protected method 'protected_Method'
282// CHECK-FIXES: {{^}} void _protected_Method();{{$}}
283public:
284 void public_Method();
285// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for method 'public_Method'
286// CHECK-FIXES: {{^}} void publicMethod();{{$}}
287};
288
289constexpr int CE_function() { return 3; }
290// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for constexpr function 'CE_function'
291// CHECK-FIXES: {{^}}constexpr int ce_function() { return 3; }{{$}}
292
293struct THIS___Structure {
294// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for struct 'THIS___Structure'
295// CHECK-FIXES: {{^}}struct this_structure {{{$}}
296 THIS___Structure();
Alexander Kornienko30c423b2015-10-01 09:19:40 +0000297// CHECK-FIXES: {{^}} this_structure();{{$}}
Alexander Kornienko76c28802015-08-19 11:15:36 +0000298
299 union __MyUnion_is_wonderful__ {};
300// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: invalid case style for union '__MyUnion_is_wonderful__'
301// CHECK-FIXES: {{^}} union UMyUnionIsWonderful {};{{$}}
302};
303
304typedef THIS___Structure struct_type;
305// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for typedef 'struct_type'
Alexander Kornienko30c423b2015-10-01 09:19:40 +0000306// CHECK-FIXES: {{^}}typedef this_structure struct_type_t;{{$}}
Alexander Kornienko76c28802015-08-19 11:15:36 +0000307
308static void static_Function() {
309// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for function 'static_Function'
310// CHECK-FIXES: {{^}}static void staticFunction() {{{$}}
Alexander Kornienko30c423b2015-10-01 09:19:40 +0000311
312 ::FOO_NS::InlineNamespace::abstract_class::CLASS_METHOD();
313// CHECK-FIXES: {{^}} ::foo_ns::inline_namespace::AAbstractClass::classMethod();{{$}}
314 ::FOO_NS::InlineNamespace::static_Function();
315// CHECK-FIXES: {{^}} ::foo_ns::inline_namespace::staticFunction();{{$}}
316
317 using ::FOO_NS::InlineNamespace::CE_function;
318// CHECK-FIXES: {{^}} using ::foo_ns::inline_namespace::ce_function;{{$}}
Alexander Kornienko76c28802015-08-19 11:15:36 +0000319}
320
321}
322}