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