@@ -722,4 +722,254 @@ make_backup = false
722722 assert_eq ! ( config. imports_granularity( ) , ImportGranularity :: Module ) ;
723723 }
724724 }
725+
726+ #[ cfg( test) ]
727+ mod use_small_heuristics {
728+ use super :: * ;
729+
730+ #[ test]
731+ fn test_default_sets_correct_widths ( ) {
732+ let toml = r#"
733+ use_small_heuristics = "Default"
734+ max_width = 200
735+ "# ;
736+ let config = Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
737+ assert_eq ! ( config. array_width( ) , 120 ) ;
738+ assert_eq ! ( config. attr_fn_like_width( ) , 140 ) ;
739+ assert_eq ! ( config. chain_width( ) , 120 ) ;
740+ assert_eq ! ( config. fn_call_width( ) , 120 ) ;
741+ assert_eq ! ( config. single_line_if_else_max_width( ) , 100 ) ;
742+ assert_eq ! ( config. struct_lit_width( ) , 36 ) ;
743+ assert_eq ! ( config. struct_variant_width( ) , 70 ) ;
744+ }
745+
746+ #[ test]
747+ fn test_max_sets_correct_widths ( ) {
748+ let toml = r#"
749+ use_small_heuristics = "Max"
750+ max_width = 120
751+ "# ;
752+ let config = Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
753+ assert_eq ! ( config. array_width( ) , 120 ) ;
754+ assert_eq ! ( config. attr_fn_like_width( ) , 120 ) ;
755+ assert_eq ! ( config. chain_width( ) , 120 ) ;
756+ assert_eq ! ( config. fn_call_width( ) , 120 ) ;
757+ assert_eq ! ( config. single_line_if_else_max_width( ) , 120 ) ;
758+ assert_eq ! ( config. struct_lit_width( ) , 120 ) ;
759+ assert_eq ! ( config. struct_variant_width( ) , 120 ) ;
760+ }
761+
762+ #[ test]
763+ fn test_off_sets_correct_widths ( ) {
764+ let toml = r#"
765+ use_small_heuristics = "Off"
766+ max_width = 100
767+ "# ;
768+ let config = Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
769+ assert_eq ! ( config. array_width( ) , usize :: max_value( ) ) ;
770+ assert_eq ! ( config. attr_fn_like_width( ) , usize :: max_value( ) ) ;
771+ assert_eq ! ( config. chain_width( ) , usize :: max_value( ) ) ;
772+ assert_eq ! ( config. fn_call_width( ) , usize :: max_value( ) ) ;
773+ assert_eq ! ( config. single_line_if_else_max_width( ) , 0 ) ;
774+ assert_eq ! ( config. struct_lit_width( ) , 0 ) ;
775+ assert_eq ! ( config. struct_variant_width( ) , 0 ) ;
776+ }
777+
778+ #[ test]
779+ fn test_override_works_with_default ( ) {
780+ let toml = r#"
781+ use_small_heuristics = "Default"
782+ array_width = 20
783+ attr_fn_like_width = 40
784+ chain_width = 20
785+ fn_call_width = 90
786+ single_line_if_else_max_width = 40
787+ struct_lit_width = 30
788+ struct_variant_width = 34
789+ "# ;
790+ let config = Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
791+ assert_eq ! ( config. array_width( ) , 20 ) ;
792+ assert_eq ! ( config. attr_fn_like_width( ) , 40 ) ;
793+ assert_eq ! ( config. chain_width( ) , 20 ) ;
794+ assert_eq ! ( config. fn_call_width( ) , 90 ) ;
795+ assert_eq ! ( config. single_line_if_else_max_width( ) , 40 ) ;
796+ assert_eq ! ( config. struct_lit_width( ) , 30 ) ;
797+ assert_eq ! ( config. struct_variant_width( ) , 34 ) ;
798+ }
799+
800+ #[ test]
801+ fn test_override_with_max ( ) {
802+ let toml = r#"
803+ use_small_heuristics = "Max"
804+ array_width = 20
805+ attr_fn_like_width = 40
806+ chain_width = 20
807+ fn_call_width = 90
808+ single_line_if_else_max_width = 40
809+ struct_lit_width = 30
810+ struct_variant_width = 34
811+ "# ;
812+ let config = Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
813+ assert_eq ! ( config. array_width( ) , 20 ) ;
814+ assert_eq ! ( config. attr_fn_like_width( ) , 40 ) ;
815+ assert_eq ! ( config. chain_width( ) , 20 ) ;
816+ assert_eq ! ( config. fn_call_width( ) , 90 ) ;
817+ assert_eq ! ( config. single_line_if_else_max_width( ) , 40 ) ;
818+ assert_eq ! ( config. struct_lit_width( ) , 30 ) ;
819+ assert_eq ! ( config. struct_variant_width( ) , 34 ) ;
820+ }
821+
822+ #[ test]
823+ fn test_override_with_off ( ) {
824+ let toml = r#"
825+ use_small_heuristics = "Off"
826+ array_width = 20
827+ attr_fn_like_width = 40
828+ chain_width = 20
829+ fn_call_width = 90
830+ single_line_if_else_max_width = 40
831+ struct_lit_width = 30
832+ struct_variant_width = 34
833+ "# ;
834+ let config = Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
835+ assert_eq ! ( config. array_width( ) , 20 ) ;
836+ assert_eq ! ( config. attr_fn_like_width( ) , 40 ) ;
837+ assert_eq ! ( config. chain_width( ) , 20 ) ;
838+ assert_eq ! ( config. fn_call_width( ) , 90 ) ;
839+ assert_eq ! ( config. single_line_if_else_max_width( ) , 40 ) ;
840+ assert_eq ! ( config. struct_lit_width( ) , 30 ) ;
841+ assert_eq ! ( config. struct_variant_width( ) , 34 ) ;
842+ }
843+
844+ #[ test]
845+ #[ should_panic( expected = "`fn_call_width` cannot have a value that exceeds `max_width" ) ]
846+ fn test_panics_when_fn_call_width_config_exceeds_max_width ( ) {
847+ let toml = r#"
848+ max_width = 80
849+ fn_call_width = 90
850+ "# ;
851+ Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
852+ }
853+
854+ #[ test]
855+ #[ should_panic(
856+ expected = "`attr_fn_like_width` cannot have a value that exceeds `max_width"
857+ ) ]
858+ fn test_panics_when_attr_fn_like_width_config_exceeds_max_width ( ) {
859+ let toml = r#"
860+ max_width = 80
861+ attr_fn_like_width = 90
862+ "# ;
863+ Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
864+ }
865+
866+ #[ test]
867+ #[ should_panic( expected = "`struct_lit_width` cannot have a value that exceeds `max_width" ) ]
868+ fn test_panics_when_struct_lit_config_exceeds_max_width ( ) {
869+ let toml = r#"
870+ max_width = 80
871+ struct_lit_width = 90
872+ "# ;
873+ Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
874+ }
875+
876+ #[ test]
877+ #[ should_panic(
878+ expected = "`struct_variant_width` cannot have a value that exceeds `max_width"
879+ ) ]
880+ fn test_panics_when_struct_variant_width_config_exceeds_max_width ( ) {
881+ let toml = r#"
882+ max_width = 80
883+ struct_variant_width = 90
884+ "# ;
885+ Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
886+ }
887+
888+ #[ test]
889+ #[ should_panic( expected = "`array_width` cannot have a value that exceeds `max_width" ) ]
890+ fn test_panics_when_array_width_config_exceeds_max_width ( ) {
891+ let toml = r#"
892+ max_width = 80
893+ array_width = 90
894+ "# ;
895+ Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
896+ }
897+
898+ #[ test]
899+ #[ should_panic( expected = "`chain_width` cannot have a value that exceeds `max_width" ) ]
900+ fn test_panics_when_chain_width_config_exceeds_max_width ( ) {
901+ let toml = r#"
902+ max_width = 80
903+ chain_width = 90
904+ "# ;
905+ Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
906+ }
907+
908+ #[ test]
909+ #[ should_panic(
910+ expected = "`single_line_if_else_max_width` cannot have a value that exceeds `max_width"
911+ ) ]
912+ fn test_panics_when_single_line_if_else_max_width_config_exceeds_max_width ( ) {
913+ let toml = r#"
914+ max_width = 80
915+ single_line_if_else_max_width = 90
916+ "# ;
917+ Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
918+ }
919+
920+ #[ test]
921+ #[ should_panic( expected = "`fn_call_width` cannot have a value that exceeds `max_width" ) ]
922+ fn test_panics_when_fn_call_width_override_exceeds_max_width ( ) {
923+ let mut config = Config :: default ( ) ;
924+ config. override_value ( "fn_call_width" , "101" ) ;
925+ }
926+
927+ #[ test]
928+ #[ should_panic(
929+ expected = "`attr_fn_like_width` cannot have a value that exceeds `max_width"
930+ ) ]
931+ fn test_panics_when_attr_fn_like_width_override_exceeds_max_width ( ) {
932+ let mut config = Config :: default ( ) ;
933+ config. override_value ( "attr_fn_like_width" , "101" ) ;
934+ }
935+
936+ #[ test]
937+ #[ should_panic( expected = "`struct_lit_width` cannot have a value that exceeds `max_width" ) ]
938+ fn test_panics_when_struct_lit_override_exceeds_max_width ( ) {
939+ let mut config = Config :: default ( ) ;
940+ config. override_value ( "struct_lit_width" , "101" ) ;
941+ }
942+
943+ #[ test]
944+ #[ should_panic(
945+ expected = "`struct_variant_width` cannot have a value that exceeds `max_width"
946+ ) ]
947+ fn test_panics_when_struct_variant_width_override_exceeds_max_width ( ) {
948+ let mut config = Config :: default ( ) ;
949+ config. override_value ( "struct_variant_width" , "101" ) ;
950+ }
951+
952+ #[ test]
953+ #[ should_panic( expected = "`array_width` cannot have a value that exceeds `max_width" ) ]
954+ fn test_panics_when_array_width_override_exceeds_max_width ( ) {
955+ let mut config = Config :: default ( ) ;
956+ config. override_value ( "array_width" , "101" ) ;
957+ }
958+
959+ #[ test]
960+ #[ should_panic( expected = "`chain_width` cannot have a value that exceeds `max_width" ) ]
961+ fn test_panics_when_chain_width_override_exceeds_max_width ( ) {
962+ let mut config = Config :: default ( ) ;
963+ config. override_value ( "chain_width" , "101" ) ;
964+ }
965+
966+ #[ test]
967+ #[ should_panic(
968+ expected = "`single_line_if_else_max_width` cannot have a value that exceeds `max_width"
969+ ) ]
970+ fn test_panics_when_single_line_if_else_max_width_override_exceeds_max_width ( ) {
971+ let mut config = Config :: default ( ) ;
972+ config. override_value ( "single_line_if_else_max_width" , "101" ) ;
973+ }
974+ }
725975}
0 commit comments