blob: c72a6d80e203bfd4db0006993e781bd080b0574a [file] [log] [blame]
Alexander Kornienko43556bb2015-08-20 17:58:07 +00001// RUN: %python %S/check_clang_tidy.py %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} \
NAKAMURA Takumibc224b802015-08-19 13:22:58 +000065// RUN: ]}' -- -std=c++11 -fno-delayed-template-parsing
Alexander Kornienko76c28802015-08-19 11:15:36 +000066
67// FIXME: There should be more test cases for checking that references to class
68// FIXME: name, declaration contexts, forward declarations, etc, are correctly
69// FIXME: checked and renamed
70
71namespace FOO_NS {
72// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for namespace 'FOO_NS' [readability-identifier-naming]
73// CHECK-FIXES: {{^}}namespace foo_ns {{{$}}
74inline namespace InlineNamespace {
75// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for inline namespace 'InlineNamespace'
76// CHECK-FIXES: {{^}}inline namespace inline_namespace {{{$}}
77
78#define BLA int FOO_bar
79BLA;
80// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for global variable 'FOO_bar'
81// NO fix expected as FOO_bar is from macro expansion
82
83enum my_enumeration {
84// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for enum 'my_enumeration'
85// CHECK-FIXES: {{^}}enum EMyEnumeration {{{$}}
86 MyConstant = 1,
87// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for enum constant 'MyConstant'
88// CHECK-FIXES: {{^}} MY_CONSTANT = 1,{{$}}
89 your_CONST = 1,
90// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for enum constant 'your_CONST'
91// CHECK-FIXES: {{^}} YOUR_CONST = 1,{{$}}
92 THIS_ConstValue = 1,
93// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for enum constant 'THIS_ConstValue'
94// CHECK-FIXES: {{^}} THIS_CONST_VALUE = 1,{{$}}
95};
96
97constexpr int ConstExpr_variable = MyConstant;
98// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for constexpr variable 'ConstExpr_variable'
99// CHECK-FIXES: {{^}}constexpr int const_expr_variable = MY_CONSTANT;{{$}}
100
101class my_class {
102// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for class 'my_class'
103// CHECK-FIXES: {{^}}class CMyClass {{{$}}
104 my_class();
105
106 const int MEMBER_one_1 = ConstExpr_variable;
107// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: invalid case style for constant member 'MEMBER_one_1'
108// CHECK-FIXES: {{^}} const int member_one_1 = const_expr_variable;{{$}}
109 int member2 = 2;
110// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: invalid case style for private member 'member2'
111// CHECK-FIXES: {{^}} int __member2 = 2;{{$}}
112
113private:
114 int private_member = 3;
115// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for private member 'private_member'
116// CHECK-FIXES: {{^}} int __private_member = 3;{{$}}
117
118protected:
119 int ProtMember;
120// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for protected member 'ProtMember'
121// CHECK-FIXES: {{^}} int _ProtMember;{{$}}
122
123public:
124 int PubMem;
125// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for public member 'PubMem'
126// CHECK-FIXES: {{^}} int pub_mem;{{$}}
127
128 static const int classConstant;
129// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for class constant 'classConstant'
130// CHECK-FIXES: {{^}} static const int kClassConstant;{{$}}
131 static int ClassMember_2;
132// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for class member 'ClassMember_2'
133// CHECK-FIXES: {{^}} static int ClassMember2;{{$}}
134};
135
136const int my_class::classConstant = 4;
137// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for class constant 'classConstant'
138// CHECK-FIXES: {{^}}const int my_class::kClassConstant = 4;{{$}}
139// FIXME: The fixup should reflect class name fixups as well:
140// FIXME: {{^}}const int CMyClass::kClassConstant = 4;{{$}}
141
142int my_class::ClassMember_2 = 5;
143// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for class member 'ClassMember_2'
144// CHECK-FIXES: {{^}}int my_class::ClassMember2 = 5;{{$}}
145// FIXME: The fixup should reflect class name fixups as well:
146// FIXME: {{^}}int CMyClass::ClassMember2 = 5;{{$}}
147
148const int global_Constant = 6;
149// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for global constant 'global_Constant'
150// CHECK-FIXES: {{^}}const int GLOBAL_CONSTANT = 6;{{$}}
151int Global_variable = 7;
152// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for global variable 'Global_variable'
153// CHECK-FIXES: {{^}}int g_global_variable = 7;{{$}}
154
155void global_function(int PARAMETER_1, int const CONST_parameter) {
156// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for global function 'global_function'
157// CHECK-MESSAGES: :[[@LINE-2]]:22: warning: invalid case style for parameter 'PARAMETER_1'
158// CHECK-MESSAGES: :[[@LINE-3]]:39: warning: invalid case style for constant parameter 'CONST_parameter'
159// CHECK-FIXES: {{^}}void GlobalFunction(int a_parameter1, int const i_constParameter) {{{$}}
160 static const int THIS_static_ConsTant = 4;
161// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for static constant 'THIS_static_ConsTant'
162// CHECK-FIXES: {{^}} static const int THIS_STATIC_CONS_TANT = 4;{{$}}
163 static int THIS_static_variable;
164// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for static variable 'THIS_static_variable'
165// CHECK-FIXES: {{^}} static int s_thisStaticVariable;{{$}}
166 int const local_Constant = 3;
167// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for local constant 'local_Constant'
168// CHECK-FIXES: {{^}} int const kLocalConstant = 3;{{$}}
169 int LOCAL_VARIABLE;
170// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for local variable 'LOCAL_VARIABLE'
171// CHECK-FIXES: {{^}} int local_variable;{{$}}
172
173 int LOCAL_Array__[] = {0, 1, 2};
174// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for local variable 'LOCAL_Array__'
175// CHECK-FIXES: {{^}} int local_array[] = {0, 1, 2};{{$}}
176
177 for (auto _ : LOCAL_Array__) {
178 }
179}
180
181template<typename ... TYPE_parameters>
182// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for type template parameter 'TYPE_parameters'
183// CHECK-FIXES: {{^}}template<typename ... typeParameters_t>{{$}}
184void Global_Fun(TYPE_parameters... PARAMETER_PACK) {
185// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for global function 'Global_Fun'
186// CHECK-MESSAGES: :[[@LINE-2]]:17: warning: invalid case style for parameter pack 'PARAMETER_PACK'
187// CHECK-FIXES: {{^}}void GlobalFun(TYPE_parameters... parameterPack) {{{$}}
188 global_function(1, 2);
189// CHECK-FIXES: {{^}} GlobalFunction(1, 2);{{$}}
190 FOO_bar = Global_variable;
191// CHECK-FIXES: {{^}} FOO_bar = g_global_variable;{{$}}
192// NO fix expected for FOO_bar declared in macro expansion
193}
194
195template<template<typename> class TPL_parameter, int COUNT_params, typename ... TYPE_parameters>
196// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for template template parameter 'TPL_parameter'
197// CHECK-MESSAGES: :[[@LINE-2]]:50: warning: invalid case style for value template parameter 'COUNT_params'
198// CHECK-MESSAGES: :[[@LINE-3]]:68: warning: invalid case style for type template parameter 'TYPE_parameters'
199// CHECK-FIXES: {{^}}template<template<typename> class TplParameter, int countParams, typename ... typeParameters_t>{{$}}
200class test_CLASS {
201// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for class 'test_CLASS'
202// CHECK-FIXES: {{^}}class CTestClass {{{$}}
203};
204
205class abstract_class {
206// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for abstract class 'abstract_class'
207// CHECK-FIXES: {{^}}class AAbstractClass {{{$}}
208 virtual ~abstract_class() = 0;
209 virtual void VIRTUAL_METHOD();
210// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for virtual method 'VIRTUAL_METHOD'
211// CHECK-FIXES: {{^}} virtual void v_VIRTUAL_METHOD();{{$}}
212 void non_Virtual_METHOD() {}
213// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for private method 'non_Virtual_METHOD'
214// CHECK-FIXES: {{^}} void __non_Virtual_METHOD() {}{{$}}
215 static void CLASS_METHOD() {}
216// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for class method 'CLASS_METHOD'
217// CHECK-FIXES: {{^}} static void classMethod() {}{{$}}
218
219 constexpr int CST_expr_Method() { return 2; }
220// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for constexpr method 'CST_expr_Method'
221// CHECK-FIXES: {{^}} constexpr int cst_expr_method() { return 2; }{{$}}
222
223private:
224 void PRIVate_Method();
225// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for private method 'PRIVate_Method'
226// CHECK-FIXES: {{^}} void __PRIVate_Method();{{$}}
227protected:
228 void protected_Method();
229// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for protected method 'protected_Method'
230// CHECK-FIXES: {{^}} void _protected_Method();{{$}}
231public:
232 void public_Method();
233// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for method 'public_Method'
234// CHECK-FIXES: {{^}} void publicMethod();{{$}}
235};
236
237constexpr int CE_function() { return 3; }
238// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for constexpr function 'CE_function'
239// CHECK-FIXES: {{^}}constexpr int ce_function() { return 3; }{{$}}
240
241struct THIS___Structure {
242// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for struct 'THIS___Structure'
243// CHECK-FIXES: {{^}}struct this_structure {{{$}}
244 THIS___Structure();
245// FIXME: There should be a fixup for the constructor as well
246// FIXME: {{^}} this_structure();{{$}}
247
248 union __MyUnion_is_wonderful__ {};
249// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: invalid case style for union '__MyUnion_is_wonderful__'
250// CHECK-FIXES: {{^}} union UMyUnionIsWonderful {};{{$}}
251};
252
253typedef THIS___Structure struct_type;
254// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for typedef 'struct_type'
255// CHECK-FIXES: {{^}}typedef THIS___Structure struct_type_t;{{$}}
256// FIXME: The fixup should reflect structure name fixups as well:
257// FIXME: {{^}}typedef this_structure struct_type_t;{{$}}
258
259static void static_Function() {
260// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for function 'static_Function'
261// CHECK-FIXES: {{^}}static void staticFunction() {{{$}}
262}
263
264}
265}