@@ -526,170 +526,176 @@ declare_deprecated_lint! {
526
526
assert_eq ! ( expected, result) ;
527
527
}
528
528
529
- #[ test]
530
- fn test_replace_region ( ) {
531
- let text = "\n abc\n 123\n 789\n def\n ghi" ;
532
- let expected = FileChange {
533
- changed : true ,
534
- new_lines : "\n abc\n hello world\n def\n ghi" . to_string ( ) ,
535
- } ;
536
- let result = replace_region_in_text ( text, r#"^\s*abc$"# , r#"^\s*def"# , false , || {
537
- vec ! [ "hello world" . to_string( ) ]
538
- } ) ;
539
- assert_eq ! ( expected, result) ;
540
- }
529
+ #[ cfg( test) ]
530
+ mod tests {
531
+ use super :: * ;
532
+
533
+ #[ test]
534
+ fn test_replace_region ( ) {
535
+ let text = "\n abc\n 123\n 789\n def\n ghi" ;
536
+ let expected = FileChange {
537
+ changed : true ,
538
+ new_lines : "\n abc\n hello world\n def\n ghi" . to_string ( ) ,
539
+ } ;
540
+ let result = replace_region_in_text ( text, r#"^\s*abc$"# , r#"^\s*def"# , false , || {
541
+ vec ! [ "hello world" . to_string( ) ]
542
+ } ) ;
543
+ assert_eq ! ( expected, result) ;
544
+ }
541
545
542
- #[ test]
543
- fn test_replace_region_with_start ( ) {
544
- let text = "\n abc\n 123\n 789\n def\n ghi" ;
545
- let expected = FileChange {
546
- changed : true ,
547
- new_lines : "\n hello world\n def\n ghi" . to_string ( ) ,
548
- } ;
549
- let result = replace_region_in_text ( text, r#"^\s*abc$"# , r#"^\s*def"# , true , || {
550
- vec ! [ "hello world" . to_string( ) ]
551
- } ) ;
552
- assert_eq ! ( expected, result) ;
553
- }
546
+ #[ test]
547
+ fn test_replace_region_with_start ( ) {
548
+ let text = "\n abc\n 123\n 789\n def\n ghi" ;
549
+ let expected = FileChange {
550
+ changed : true ,
551
+ new_lines : "\n hello world\n def\n ghi" . to_string ( ) ,
552
+ } ;
553
+ let result = replace_region_in_text ( text, r#"^\s*abc$"# , r#"^\s*def"# , true , || {
554
+ vec ! [ "hello world" . to_string( ) ]
555
+ } ) ;
556
+ assert_eq ! ( expected, result) ;
557
+ }
554
558
555
- #[ test]
556
- fn test_replace_region_no_changes ( ) {
557
- let text = "123\n 456\n 789" ;
558
- let expected = FileChange {
559
- changed : false ,
560
- new_lines : "123\n 456\n 789" . to_string ( ) ,
561
- } ;
562
- let result = replace_region_in_text ( text, r#"^\s*123$"# , r#"^\s*456"# , false , Vec :: new) ;
563
- assert_eq ! ( expected, result) ;
564
- }
559
+ #[ test]
560
+ fn test_replace_region_no_changes ( ) {
561
+ let text = "123\n 456\n 789" ;
562
+ let expected = FileChange {
563
+ changed : false ,
564
+ new_lines : "123\n 456\n 789" . to_string ( ) ,
565
+ } ;
566
+ let result = replace_region_in_text ( text, r#"^\s*123$"# , r#"^\s*456"# , false , Vec :: new) ;
567
+ assert_eq ! ( expected, result) ;
568
+ }
565
569
566
- #[ test]
567
- fn test_usable_lints ( ) {
568
- let lints = vec ! [
569
- Lint :: new( "should_assert_eq" , "Deprecated" , "abc" , Some ( "Reason" ) , "module_name" ) ,
570
- Lint :: new( "should_assert_eq2" , "Not Deprecated" , "abc" , None , "module_name" ) ,
571
- Lint :: new( "should_assert_eq2" , "internal" , "abc" , None , "module_name" ) ,
572
- Lint :: new( "should_assert_eq2" , "internal_style" , "abc" , None , "module_name" ) ,
573
- ] ;
574
- let expected = vec ! [ Lint :: new(
575
- "should_assert_eq2" ,
576
- "Not Deprecated" ,
577
- "abc" ,
578
- None ,
579
- "module_name" ,
580
- ) ] ;
581
- assert_eq ! ( expected, Lint :: usable_lints( & lints) ) ;
582
- }
570
+ #[ test]
571
+ fn test_usable_lints ( ) {
572
+ let lints = vec ! [
573
+ Lint :: new( "should_assert_eq" , "Deprecated" , "abc" , Some ( "Reason" ) , "module_name" ) ,
574
+ Lint :: new( "should_assert_eq2" , "Not Deprecated" , "abc" , None , "module_name" ) ,
575
+ Lint :: new( "should_assert_eq2" , "internal" , "abc" , None , "module_name" ) ,
576
+ Lint :: new( "should_assert_eq2" , "internal_style" , "abc" , None , "module_name" ) ,
577
+ ] ;
578
+ let expected = vec ! [ Lint :: new(
579
+ "should_assert_eq2" ,
580
+ "Not Deprecated" ,
581
+ "abc" ,
582
+ None ,
583
+ "module_name" ,
584
+ ) ] ;
585
+ assert_eq ! ( expected, Lint :: usable_lints( & lints) ) ;
586
+ }
583
587
584
- #[ test]
585
- fn test_by_lint_group ( ) {
586
- let lints = vec ! [
587
- Lint :: new( "should_assert_eq" , "group1" , "abc" , None , "module_name" ) ,
588
- Lint :: new( "should_assert_eq2" , "group2" , "abc" , None , "module_name" ) ,
589
- Lint :: new( "incorrect_match" , "group1" , "abc" , None , "module_name" ) ,
590
- ] ;
591
- let mut expected: HashMap < String , Vec < Lint > > = HashMap :: new ( ) ;
592
- expected. insert (
593
- "group1" . to_string ( ) ,
594
- vec ! [
588
+ #[ test]
589
+ fn test_by_lint_group ( ) {
590
+ let lints = vec ! [
595
591
Lint :: new( "should_assert_eq" , "group1" , "abc" , None , "module_name" ) ,
592
+ Lint :: new( "should_assert_eq2" , "group2" , "abc" , None , "module_name" ) ,
596
593
Lint :: new( "incorrect_match" , "group1" , "abc" , None , "module_name" ) ,
597
- ] ,
598
- ) ;
599
- expected. insert (
600
- "group2" . to_string ( ) ,
601
- vec ! [ Lint :: new( "should_assert_eq2" , "group2" , "abc" , None , "module_name" ) ] ,
602
- ) ;
603
- assert_eq ! ( expected, Lint :: by_lint_group( lints. into_iter( ) ) ) ;
604
- }
605
-
606
- #[ test]
607
- fn test_gen_changelog_lint_list ( ) {
608
- let lints = vec ! [
609
- Lint :: new( "should_assert_eq" , "group1" , "abc" , None , "module_name" ) ,
610
- Lint :: new( "should_assert_eq2" , "group2" , "abc" , None , "module_name" ) ,
611
- ] ;
612
- let expected = vec ! [
613
- format!( "[`should_assert_eq`]: {}#should_assert_eq" , DOCS_LINK . to_string( ) ) ,
614
- format!( "[`should_assert_eq2`]: {}#should_assert_eq2" , DOCS_LINK . to_string( ) ) ,
615
- ] ;
616
- assert_eq ! ( expected, gen_changelog_lint_list( lints. iter( ) ) ) ;
617
- }
618
-
619
- #[ test]
620
- fn test_gen_deprecated ( ) {
621
- let lints = vec ! [
622
- Lint :: new(
623
- "should_assert_eq" ,
624
- "group1" ,
625
- "abc" ,
626
- Some ( "has been superseded by should_assert_eq2" ) ,
627
- "module_name" ,
628
- ) ,
629
- Lint :: new(
630
- "another_deprecated" ,
631
- "group2" ,
632
- "abc" ,
633
- Some ( "will be removed" ) ,
634
- "module_name" ,
635
- ) ,
636
- ] ;
594
+ ] ;
595
+ let mut expected: HashMap < String , Vec < Lint > > = HashMap :: new ( ) ;
596
+ expected. insert (
597
+ "group1" . to_string ( ) ,
598
+ vec ! [
599
+ Lint :: new( "should_assert_eq" , "group1" , "abc" , None , "module_name" ) ,
600
+ Lint :: new( "incorrect_match" , "group1" , "abc" , None , "module_name" ) ,
601
+ ] ,
602
+ ) ;
603
+ expected. insert (
604
+ "group2" . to_string ( ) ,
605
+ vec ! [ Lint :: new( "should_assert_eq2" , "group2" , "abc" , None , "module_name" ) ] ,
606
+ ) ;
607
+ assert_eq ! ( expected, Lint :: by_lint_group( lints. into_iter( ) ) ) ;
608
+ }
637
609
638
- let expected = GENERATED_FILE_COMMENT . to_string ( )
639
- + & [
640
- "{" ,
641
- " store.register_removed(" ,
642
- " \" clippy::should_assert_eq\" ," ,
643
- " \" has been superseded by should_assert_eq2\" ," ,
644
- " );" ,
645
- " store.register_removed(" ,
646
- " \" clippy::another_deprecated\" ," ,
647
- " \" will be removed\" ," ,
648
- " );" ,
649
- "}" ,
650
- ]
651
- . join ( "\n " )
652
- + "\n " ;
653
-
654
- assert_eq ! ( expected, gen_deprecated( lints. iter( ) ) ) ;
655
- }
610
+ #[ test]
611
+ fn test_gen_changelog_lint_list ( ) {
612
+ let lints = vec ! [
613
+ Lint :: new( "should_assert_eq" , "group1" , "abc" , None , "module_name" ) ,
614
+ Lint :: new( "should_assert_eq2" , "group2" , "abc" , None , "module_name" ) ,
615
+ ] ;
616
+ let expected = vec ! [
617
+ format!( "[`should_assert_eq`]: {}#should_assert_eq" , DOCS_LINK . to_string( ) ) ,
618
+ format!( "[`should_assert_eq2`]: {}#should_assert_eq2" , DOCS_LINK . to_string( ) ) ,
619
+ ] ;
620
+ assert_eq ! ( expected, gen_changelog_lint_list( lints. iter( ) ) ) ;
621
+ }
656
622
657
- #[ test]
658
- #[ should_panic]
659
- fn test_gen_deprecated_fail ( ) {
660
- let lints = vec ! [ Lint :: new( "should_assert_eq2" , "group2" , "abc" , None , "module_name" ) ] ;
661
- let _deprecated_lints = gen_deprecated ( lints. iter ( ) ) ;
662
- }
623
+ #[ test]
624
+ fn test_gen_deprecated ( ) {
625
+ let lints = vec ! [
626
+ Lint :: new(
627
+ "should_assert_eq" ,
628
+ "group1" ,
629
+ "abc" ,
630
+ Some ( "has been superseded by should_assert_eq2" ) ,
631
+ "module_name" ,
632
+ ) ,
633
+ Lint :: new(
634
+ "another_deprecated" ,
635
+ "group2" ,
636
+ "abc" ,
637
+ Some ( "will be removed" ) ,
638
+ "module_name" ,
639
+ ) ,
640
+ ] ;
641
+
642
+ let expected = GENERATED_FILE_COMMENT . to_string ( )
643
+ + & [
644
+ "{" ,
645
+ " store.register_removed(" ,
646
+ " \" clippy::should_assert_eq\" ," ,
647
+ " \" has been superseded by should_assert_eq2\" ," ,
648
+ " );" ,
649
+ " store.register_removed(" ,
650
+ " \" clippy::another_deprecated\" ," ,
651
+ " \" will be removed\" ," ,
652
+ " );" ,
653
+ "}" ,
654
+ ]
655
+ . join ( "\n " )
656
+ + "\n " ;
657
+
658
+ assert_eq ! ( expected, gen_deprecated( lints. iter( ) ) ) ;
659
+ }
663
660
664
- #[ test]
665
- fn test_gen_modules_list ( ) {
666
- let lints = vec ! [
667
- Lint :: new( "should_assert_eq" , "group1" , "abc" , None , "module_name" ) ,
668
- Lint :: new( "incorrect_stuff" , "group3" , "abc" , None , "another_module" ) ,
669
- ] ;
670
- let expected = GENERATED_FILE_COMMENT . to_string ( ) + & [ "mod another_module;" , "mod module_name;" ] . join ( "\n " ) + "\n " ;
671
- assert_eq ! ( expected, gen_modules_list( lints. iter( ) ) ) ;
672
- }
661
+ #[ test]
662
+ #[ should_panic]
663
+ fn test_gen_deprecated_fail ( ) {
664
+ let lints = vec ! [ Lint :: new( "should_assert_eq2" , "group2" , "abc" , None , "module_name" ) ] ;
665
+ let _deprecated_lints = gen_deprecated ( lints. iter ( ) ) ;
666
+ }
673
667
674
- #[ test]
675
- fn test_gen_lint_group_list ( ) {
676
- let lints = vec ! [
677
- Lint :: new( "abc" , "group1" , "abc" , None , "module_name" ) ,
678
- Lint :: new( "should_assert_eq" , "group1" , "abc" , None , "module_name" ) ,
679
- Lint :: new( "internal" , "internal_style" , "abc" , None , "module_name" ) ,
680
- ] ;
681
- let expected = GENERATED_FILE_COMMENT . to_string ( )
682
- + & [
683
- "store.register_group(true, \" clippy::group1\" , Some(\" clippy_group1\" ), vec![" ,
684
- " LintId::of(module_name::ABC)," ,
685
- " LintId::of(module_name::INTERNAL)," ,
686
- " LintId::of(module_name::SHOULD_ASSERT_EQ)," ,
687
- "])" ,
688
- ]
689
- . join ( "\n " )
690
- + "\n " ;
691
-
692
- let result = gen_lint_group_list ( "group1" , lints. iter ( ) ) ;
668
+ #[ test]
669
+ fn test_gen_modules_list ( ) {
670
+ let lints = vec ! [
671
+ Lint :: new( "should_assert_eq" , "group1" , "abc" , None , "module_name" ) ,
672
+ Lint :: new( "incorrect_stuff" , "group3" , "abc" , None , "another_module" ) ,
673
+ ] ;
674
+ let expected =
675
+ GENERATED_FILE_COMMENT . to_string ( ) + & [ "mod another_module;" , "mod module_name;" ] . join ( "\n " ) + "\n " ;
676
+ assert_eq ! ( expected, gen_modules_list( lints. iter( ) ) ) ;
677
+ }
693
678
694
- assert_eq ! ( expected, result) ;
679
+ #[ test]
680
+ fn test_gen_lint_group_list ( ) {
681
+ let lints = vec ! [
682
+ Lint :: new( "abc" , "group1" , "abc" , None , "module_name" ) ,
683
+ Lint :: new( "should_assert_eq" , "group1" , "abc" , None , "module_name" ) ,
684
+ Lint :: new( "internal" , "internal_style" , "abc" , None , "module_name" ) ,
685
+ ] ;
686
+ let expected = GENERATED_FILE_COMMENT . to_string ( )
687
+ + & [
688
+ "store.register_group(true, \" clippy::group1\" , Some(\" clippy_group1\" ), vec![" ,
689
+ " LintId::of(module_name::ABC)," ,
690
+ " LintId::of(module_name::INTERNAL)," ,
691
+ " LintId::of(module_name::SHOULD_ASSERT_EQ)," ,
692
+ "])" ,
693
+ ]
694
+ . join ( "\n " )
695
+ + "\n " ;
696
+
697
+ let result = gen_lint_group_list ( "group1" , lints. iter ( ) ) ;
698
+
699
+ assert_eq ! ( expected, result) ;
700
+ }
695
701
}
0 commit comments