1- use crate :: lint:: rules:: tests:: common:: assert_snippet;
2- use crate :: lint:: rules:: instantiate_rules;
3- use crate :: lint:: LintCfg ;
1+ mod nsp_funpar;
2+ mod nsp_inparen;
3+ mod nsp_trailing;
4+ mod nsp_unary;
5+ mod sp_braces;
6+ mod sp_punct;
47
58// Put whitespace (space or newline):
69// SP.reserved around reserved words, such as if, else, default,
@@ -15,51 +18,6 @@ if(this_some_integer == 0x666)
1518}
1619" ;
1720
18- // SP.braces around braces ({ and })
19- static SP_BRACES : & str = "
20- method this_is_some_method() {return 0;}
21-
22- method this_is_empty_method() { }
23-
24- bank pcie_config {register command {field mem {
25- method pcie_write(uint64 value) {
26- if (value != 0) {value = value + 1;}
27- default(value);
28- map_memory_alt();
29- }
30- }
31- }
32- }
33- " ;
34- #[ test]
35- fn style_check_sp_braces ( ) {
36- let mut cfg = LintCfg :: default ( ) ;
37- let mut rules = instantiate_rules ( & cfg) ;
38- assert_snippet ( SP_BRACES , 6 , & rules) ;
39- // Test rule disable
40- cfg. sp_brace = None ;
41- rules = instantiate_rules ( & cfg) ;
42- assert_snippet ( SP_BRACES , 0 , & rules) ;
43-
44- }
45-
46- static SP_BRACES_02 : & str = "
47- typedef struct {uint16 idx;} hqm_cq_list_release_ctx_t;
48-
49- typedef layout \" little-endian\" {bitfields 1 {uint1 cq @ [0:0];} byte;} q_t;
50- " ;
51- #[ test]
52- fn style_check_sp_braces_02 ( ) {
53- let mut cfg = LintCfg :: default ( ) ;
54- let mut rules = instantiate_rules ( & cfg) ;
55- assert_snippet ( SP_BRACES_02 , 6 , & rules) ;
56- // Test rule disable
57- cfg. sp_brace = None ;
58- rules = instantiate_rules ( & cfg) ;
59- assert_snippet ( SP_BRACES_02 , 0 , & rules) ;
60-
61- }
62-
6321// SP.binop around binary operators except the dereferencing operators dot
6422// (a.b) and arrow (a->b)
6523#[ allow( dead_code) ]
@@ -79,27 +37,6 @@ local int this_some_integer = (flag?5:7));
7937}
8038" ;
8139
82- // SP.punct after but not before colon, semicolon and comma
83- #[ allow( dead_code) ]
84- static SP_PUNCT : & str = "
85- method this_is_some_method(bool flag ,int8 var) {
86- local int this_some_integer = 0x666 ;
87- if(this_some_integer == 0x666)
88- return;
89- some_func(arg1 ,arg2 ,arg3 ,arg4);
90- }
91- " ;
92- #[ test]
93- fn style_check_sp_punct_rule ( ) {
94- let mut cfg = LintCfg :: default ( ) ;
95- let mut rules = instantiate_rules ( & cfg) ;
96- assert_snippet ( SP_PUNCT , 9 , & rules) ;
97- // Test rule disable
98- cfg. sp_punct = None ;
99- rules = instantiate_rules ( & cfg) ;
100- assert_snippet ( SP_PUNCT , 0 , & rules) ;
101- }
102-
10340// SP.ptrdecl between a type and the * marking a pointer
10441#[ allow( dead_code) ]
10542static SP_PTRDECL : & str = "
@@ -120,65 +57,6 @@ if(!dummy_obj)//Not null
12057}
12158" ;
12259
123- // There should be no space:
124- // NSP.funpar between a function/method name and its opening parenthesis
125- static NSP_FUNPAR : & str = "
126- method this_is_some_method (conf_object_t *dummy_obj) {
127- if(!dummy_obj)
128- other_method_called ();
129- }
130- " ;
131- #[ test]
132- fn style_check_nsp_funpar ( ) {
133- let mut cfg = LintCfg :: default ( ) ;
134- let mut rules = instantiate_rules ( & cfg) ;
135- assert_snippet ( NSP_FUNPAR , 2 , & rules) ;
136- // Test rule disable
137- cfg. nsp_funpar = None ;
138- rules = instantiate_rules ( & cfg) ;
139- assert_snippet ( NSP_FUNPAR , 0 , & rules) ;
140- }
141-
142- // NSP.inparen immediately inside parentheses or brackets
143- static NSP_INPAREN : & str = "
144- method this_is_some_method( conf_object_t *dummy_obj ) {
145- if( !dummy_obj[ 0 ] )
146- return;
147- }
148- " ;
149- #[ test]
150- fn style_check_nsp_inparen ( ) {
151- let mut cfg = LintCfg :: default ( ) ;
152- let mut rules = instantiate_rules ( & cfg) ;
153- assert_snippet ( NSP_INPAREN , 6 , & rules) ;
154- // Test rule disable
155- cfg. nsp_inparen = None ;
156- rules = instantiate_rules ( & cfg) ;
157- assert_snippet ( NSP_INPAREN , 0 , & rules) ;
158- }
159-
160- // NSP.unary between a unary operator and its operand
161- static NSP_UNARY : & str = "
162- method this_is_some_method(conf_object_t *dummy_obj) {
163- if(! dummy_obj)
164- return;
165- local uint64 p = & dummy_obj;
166- p ++;
167- -- p;
168- local int64 neg = - 1;
169- }
170- " ;
171- #[ test]
172- fn style_check_nsp_unary ( ) {
173- let mut cfg = LintCfg :: default ( ) ;
174- let mut rules = instantiate_rules ( & cfg) ;
175- assert_snippet ( NSP_UNARY , 5 , & rules) ;
176- // Test rule disable
177- cfg. nsp_unary = None ;
178- rules = instantiate_rules ( & cfg) ;
179- assert_snippet ( NSP_UNARY , 0 , & rules) ;
180- }
181-
18260// NSP.ptrdecl after the * marking a pointer in a declaration
18361#[ allow( dead_code) ]
18462static NSP_PTRDECL : & str = "
@@ -187,24 +65,3 @@ if(!dummy_obj)
18765 return;
18866}
18967" ;
190-
191- // Adding trailing whitespace removal to spacing rules:
192- // no whitespaces should be left at the end of a line between the last token
193- // and the newline \n
194- static NSP_TRAILING : & str = "
195- method this_is_some_method(int64 num) {
196- local int this_some_integer = 0x666;
197- if (this_some_integer == 0x666)
198- return;
199- }
200- " ;
201- #[ test]
202- fn style_check_nsp_trailing ( ) {
203- let mut cfg = LintCfg :: default ( ) ;
204- let mut rules = instantiate_rules ( & cfg) ;
205- assert_snippet ( NSP_TRAILING , 4 , & rules) ;
206- // Test rule disable
207- cfg. nsp_trailing = None ;
208- rules = instantiate_rules ( & cfg) ;
209- assert_snippet ( NSP_TRAILING , 0 , & rules) ;
210- }
0 commit comments