@@ -502,7 +502,7 @@ mod tests_of_help {
502
502
}
503
503
504
504
#[ test]
505
- fn new_and_add_text_with_indent ( ) {
505
+ fn add_text_with_indent ( ) {
506
506
let term_cols = linebreak:: term_cols ( ) ;
507
507
let mut text = "a" . repeat ( term_cols) ;
508
508
text. push_str ( "12345\n " ) ;
@@ -534,6 +534,40 @@ mod tests_of_help {
534
534
assert_eq ! ( line, None ) ;
535
535
}
536
536
537
+ #[ test]
538
+ fn add_text_with_indent_and_margins ( ) {
539
+ let term_cols = linebreak:: term_cols ( ) ;
540
+ let mut text = "a" . repeat ( term_cols - 1 - 2 ) ;
541
+ text. push_str ( "12345\n " ) ;
542
+ text. push_str ( & "b" . repeat ( term_cols - 8 - 1 - 2 ) ) ;
543
+ text. push_str ( "6789" ) ;
544
+
545
+ let mut help = Help :: new ( ) ;
546
+ help. add_text_with_indent_and_margins ( text, 8 , 1 , 2 ) ;
547
+ let mut iter = help. iter ( ) ;
548
+
549
+ let line = iter. next ( ) ;
550
+ let mut expected = "a" . repeat ( term_cols - 1 - 2 ) ;
551
+ expected. insert_str ( 0 , " " ) ;
552
+ assert_eq ! ( line, Some ( expected) ) ;
553
+
554
+ let line = iter. next ( ) ;
555
+ let expected = " 12345" . to_string ( ) ;
556
+ assert_eq ! ( line, Some ( expected) ) ;
557
+
558
+ let line = iter. next ( ) ;
559
+ let mut expected = "b" . repeat ( term_cols - 8 - 1 - 2 ) ;
560
+ expected. insert_str ( 0 , " " ) ;
561
+ assert_eq ! ( line, Some ( expected) ) ;
562
+
563
+ let line = iter. next ( ) ;
564
+ let expected = " 6789" . to_string ( ) ;
565
+ assert_eq ! ( line, Some ( expected) ) ;
566
+
567
+ let line = iter. next ( ) ;
568
+ assert_eq ! ( line, None ) ;
569
+ }
570
+
537
571
#[ test]
538
572
fn add_text_if_text_is_empty ( ) {
539
573
let mut help = Help :: new ( ) ;
@@ -936,7 +970,7 @@ mod tests_of_help {
936
970
}
937
971
938
972
#[ test]
939
- fn add_opts_with_margins_both_of_new_method_and_add_text_with_margins_methods ( ) {
973
+ fn add_opts_with_margins_both_of_new_method_and_add_text_with_margins ( ) {
940
974
use crate :: OptCfgParam :: * ;
941
975
942
976
let cols = linebreak:: term_cols ( ) ;
@@ -1038,6 +1072,38 @@ mod tests_of_help {
1038
1072
assert_eq ! ( line, None ) ;
1039
1073
}
1040
1074
1075
+ #[ test]
1076
+ fn add_opts_with_indent_and_margins ( ) {
1077
+ use crate :: OptCfgParam :: * ;
1078
+
1079
+ let cols = linebreak:: term_cols ( ) ;
1080
+
1081
+ let mut help = Help :: new ( ) ;
1082
+ help. add_opts_with_indent_and_margins (
1083
+ & [ OptCfg :: with ( [
1084
+ names ( & [ "foo-bar" ] ) ,
1085
+ desc ( & ( "a" . repeat ( cols) ) ) ,
1086
+ ] ) ] ,
1087
+ 6 ,
1088
+ 4 ,
1089
+ 2 ,
1090
+ ) ;
1091
+
1092
+ let mut iter = help. iter ( ) ;
1093
+
1094
+ let line = iter. next ( ) ;
1095
+ assert_eq ! ( line, Some ( " --foo-bar" . to_string( ) ) ) ;
1096
+
1097
+ let line = iter. next ( ) ;
1098
+ assert_eq ! ( line, Some ( " " . repeat( 10 ) + & "a" . repeat( cols - 6 - 4 - 2 ) ) ) ;
1099
+
1100
+ let line = iter. next ( ) ;
1101
+ assert_eq ! ( line, Some ( " " . repeat( 10 ) + & "a" . repeat( 6 + 4 + 2 ) ) ) ;
1102
+
1103
+ let line = iter. next ( ) ;
1104
+ assert_eq ! ( line, None ) ;
1105
+ }
1106
+
1041
1107
#[ test]
1042
1108
fn add_opts_if_opts_are_multiple ( ) {
1043
1109
use crate :: OptCfgParam :: * ;
0 commit comments