Skip to content

Commit 6723c96

Browse files
authored
test: added test cases (#41)
1 parent 9c81f1e commit 6723c96

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

src/help/mod.rs

+68-2
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ mod tests_of_help {
502502
}
503503

504504
#[test]
505-
fn new_and_add_text_with_indent() {
505+
fn add_text_with_indent() {
506506
let term_cols = linebreak::term_cols();
507507
let mut text = "a".repeat(term_cols);
508508
text.push_str("12345\n");
@@ -534,6 +534,40 @@ mod tests_of_help {
534534
assert_eq!(line, None);
535535
}
536536

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+
537571
#[test]
538572
fn add_text_if_text_is_empty() {
539573
let mut help = Help::new();
@@ -936,7 +970,7 @@ mod tests_of_help {
936970
}
937971

938972
#[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() {
940974
use crate::OptCfgParam::*;
941975

942976
let cols = linebreak::term_cols();
@@ -1038,6 +1072,38 @@ mod tests_of_help {
10381072
assert_eq!(line, None);
10391073
}
10401074

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+
10411107
#[test]
10421108
fn add_opts_if_opts_are_multiple() {
10431109
use crate::OptCfgParam::*;

0 commit comments

Comments
 (0)