@@ -519,215 +519,3 @@ impl Rule for NspTrailingRule {
519519 "Found trailing whitespace on row"
520520 }
521521}
522-
523- #[ cfg( test) ]
524- pub mod tests {
525-
526- use crate :: lint:: rules:: tests:: assert_snippet;
527- use crate :: lint:: rules:: instantiate_rules;
528- use crate :: lint:: LintCfg ;
529-
530- // Put whitespace (space or newline):
531- // SP.reserved around reserved words, such as if, else, default,
532- // size, const and in, except when a reserved word is used as an identifier
533- // (e.g., local uint8 *data;)
534- pub static SP_RESERVED : & str = "
535- method this_is_some_method() {
536- local int this_some_integer = 0x666;
537- if(this_some_integer == 0x666)
538- return;
539- }
540- " ;
541-
542- // SP.braces around braces ({ and })
543- pub static SP_BRACES : & str = "
544- method this_is_some_method() {return 0;}
545-
546- method this_is_empty_method() { }
547-
548- bank pcie_config {register command {field mem {
549- method pcie_write(uint64 value) {
550- if (value != 0) {value = value + 1;
551- }
552- default(value);
553- map_memory_alt();}
554- }}}
555- " ;
556- #[ test]
557- fn style_check_sp_braces ( ) {
558- let mut cfg = LintCfg :: default ( ) ;
559- let mut rules = instantiate_rules ( & cfg) ;
560- assert_snippet ( SP_BRACES , 8 , & rules) ;
561- // Test rule disable
562- cfg. sp_brace = None ;
563- rules = instantiate_rules ( & cfg) ;
564- assert_snippet ( SP_BRACES , 0 , & rules) ;
565-
566- }
567-
568- pub static SP_BRACES_02 : & str = "
569- typedef struct {uint16 idx;} hqm_cq_list_release_ctx_t;
570-
571- typedef layout \" little-endian\" {bitfields 8 {uint2 rsvd @ [7:6];
572- uint1 error_f @ [5:5];
573- uint1 int_arm @ [4:4];
574- uint1 qe_valid @ [3:3];
575- uint1 qe_frag @ [2:2];
576- uint1 qe_comp @ [1:1];
577- uint1 cq_token @ [0:0];} byte;} prod_qe_cmd_t;
578- " ;
579- #[ test]
580- fn style_check_sp_braces_02 ( ) {
581- let mut cfg = LintCfg :: default ( ) ;
582- let mut rules = instantiate_rules ( & cfg) ;
583- assert_snippet ( SP_BRACES_02 , 6 , & rules) ;
584- // Test rule disable
585- cfg. sp_brace = None ;
586- rules = instantiate_rules ( & cfg) ;
587- assert_snippet ( SP_BRACES_02 , 0 , & rules) ;
588-
589- }
590-
591- // SP.binop around binary operators except the dereferencing operators dot
592- // (a.b) and arrow (a->b)
593- pub static SP_BINOP : & str = "
594- method this_is_some_method() {
595- local int this_some_integer = 5+6;
596- if (this_some_integer == 0x666)
597- this_some_integer = this.val;
598- }
599- " ;
600-
601- // SP.ternary around ? and : in the ternary ?: operator
602- pub static SP_TERNARY : & str = "
603- method this_is_some_method(bool flag) {
604- local int this_some_integer = (flag?5:7));
605- }
606- " ;
607-
608- // SP.punct after but not before colon, semicolon and comma
609- pub static SP_PUNCT : & str = "
610- method this_is_some_method(bool flag ,int8 var) {
611- local int this_some_integer = 0x666 ;
612- if(this_some_integer == 0x666)
613- return;
614- some_func(arg1 ,arg2 ,arg3 ,arg4);
615- }
616- " ;
617- #[ test]
618- fn style_check_sp_punct_rule ( ) {
619- let mut cfg = LintCfg :: default ( ) ;
620- let mut rules = instantiate_rules ( & cfg) ;
621- assert_snippet ( SP_PUNCT , 9 , & rules) ;
622- // Test rule disable
623- cfg. sp_punct = None ;
624- rules = instantiate_rules ( & cfg) ;
625- assert_snippet ( SP_PUNCT , 0 , & rules) ;
626- }
627-
628- // SP.ptrdecl between a type and the * marking a pointer
629- pub static SP_PTRDECL : & str = "
630- method this_is_some_method(conf_object_t* dummy_obj) {
631- if(!dummy_obj)
632- return;
633- }
634- " ;
635-
636- // SP.comment around the comment delimiters //, /* and **/
637- pub static SP_COMMENT : & str = "
638- /*Function
639- documentation*/
640- method this_is_some_method(conf_object_t *dummy_obj) {
641- if(!dummy_obj)//Not null
642- return;
643- }
644- " ;
645-
646- // There should be no space:
647- // NSP.funpar between a function/method name and its opening parenthesis
648- pub static NSP_FUNPAR : & str = "
649- method this_is_some_method (conf_object_t *dummy_obj) {
650- if(!dummy_obj)
651- other_method_called ();
652- }
653- " ;
654- #[ test]
655- fn style_check_nsp_funpar ( ) {
656- let mut cfg = LintCfg :: default ( ) ;
657- let mut rules = instantiate_rules ( & cfg) ;
658- assert_snippet ( NSP_FUNPAR , 2 , & rules) ;
659- // Test rule disable
660- cfg. nsp_funpar = None ;
661- rules = instantiate_rules ( & cfg) ;
662- assert_snippet ( NSP_FUNPAR , 0 , & rules) ;
663- }
664-
665- // NSP.inparen immediately inside parentheses or brackets
666- pub static NSP_INPAREN : & str = "
667- method this_is_some_method( conf_object_t *dummy_obj ) {
668- if( !dummy_obj[ 0 ] )
669- return;
670- }
671- " ;
672- #[ test]
673- fn style_check_nsp_inparen ( ) {
674- let mut cfg = LintCfg :: default ( ) ;
675- let mut rules = instantiate_rules ( & cfg) ;
676- assert_snippet ( NSP_INPAREN , 6 , & rules) ;
677- // Test rule disable
678- cfg. nsp_inparen = None ;
679- rules = instantiate_rules ( & cfg) ;
680- assert_snippet ( NSP_INPAREN , 0 , & rules) ;
681- }
682-
683- // NSP.unary between a unary operator and its operand
684- pub static NSP_UNARY : & str = "
685- method this_is_some_method(conf_object_t *dummy_obj) {
686- if(! dummy_obj)
687- return;
688- local uint64 p = & dummy_obj;
689- p ++;
690- -- p;
691- local int64 neg = - 1;
692- }
693- " ;
694- #[ test]
695- fn style_check_nsp_unary ( ) {
696- let mut cfg = LintCfg :: default ( ) ;
697- let mut rules = instantiate_rules ( & cfg) ;
698- assert_snippet ( NSP_UNARY , 5 , & rules) ;
699- // Test rule disable
700- cfg. nsp_unary = None ;
701- rules = instantiate_rules ( & cfg) ;
702- assert_snippet ( NSP_UNARY , 0 , & rules) ;
703- }
704-
705- // NSP.ptrdecl after the * marking a pointer in a declaration
706- pub static NSP_PTRDECL : & str = "
707- method this_is_some_method(conf_object_t * dummy_obj) {
708- if(!dummy_obj)
709- return;
710- }
711- " ;
712-
713- // Adding trailing whitespace removal to spacing rules:
714- // no whitespaces should be left at the end of a line between the last token
715- // and the newline \n
716- pub static NSP_TRAILING : & str = "
717- method this_is_some_method(int64 num) {
718- local int this_some_integer = 0x666;
719- if (this_some_integer == 0x666)
720- return;
721- }
722- " ;
723- #[ test]
724- fn style_check_nsp_trailing ( ) {
725- let mut cfg = LintCfg :: default ( ) ;
726- let mut rules = instantiate_rules ( & cfg) ;
727- assert_snippet ( NSP_TRAILING , 4 , & rules) ;
728- // Test rule disable
729- cfg. nsp_trailing = None ;
730- rules = instantiate_rules ( & cfg) ;
731- assert_snippet ( NSP_TRAILING , 0 , & rules) ;
732- }
733- }
0 commit comments