Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: added test cases #41

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 68 additions & 2 deletions src/help/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ mod tests_of_help {
}

#[test]
fn new_and_add_text_with_indent() {
fn add_text_with_indent() {
let term_cols = linebreak::term_cols();
let mut text = "a".repeat(term_cols);
text.push_str("12345\n");
Expand Down Expand Up @@ -534,6 +534,40 @@ mod tests_of_help {
assert_eq!(line, None);
}

#[test]
fn add_text_with_indent_and_margins() {
let term_cols = linebreak::term_cols();
let mut text = "a".repeat(term_cols - 1 - 2);
text.push_str("12345\n");
text.push_str(&"b".repeat(term_cols - 8 - 1 - 2));
text.push_str("6789");

let mut help = Help::new();
help.add_text_with_indent_and_margins(text, 8, 1, 2);
let mut iter = help.iter();

let line = iter.next();
let mut expected = "a".repeat(term_cols - 1 - 2);
expected.insert_str(0, " ");
assert_eq!(line, Some(expected));

let line = iter.next();
let expected = " 12345".to_string();
assert_eq!(line, Some(expected));

let line = iter.next();
let mut expected = "b".repeat(term_cols - 8 - 1 - 2);
expected.insert_str(0, " ");
assert_eq!(line, Some(expected));

let line = iter.next();
let expected = " 6789".to_string();
assert_eq!(line, Some(expected));

let line = iter.next();
assert_eq!(line, None);
}

#[test]
fn add_text_if_text_is_empty() {
let mut help = Help::new();
Expand Down Expand Up @@ -936,7 +970,7 @@ mod tests_of_help {
}

#[test]
fn add_opts_with_margins_both_of_new_method_and_add_text_with_margins_methods() {
fn add_opts_with_margins_both_of_new_method_and_add_text_with_margins() {
use crate::OptCfgParam::*;

let cols = linebreak::term_cols();
Expand Down Expand Up @@ -1038,6 +1072,38 @@ mod tests_of_help {
assert_eq!(line, None);
}

#[test]
fn add_opts_with_indent_and_margins() {
use crate::OptCfgParam::*;

let cols = linebreak::term_cols();

let mut help = Help::new();
help.add_opts_with_indent_and_margins(
&[OptCfg::with([
names(&["foo-bar"]),
desc(&("a".repeat(cols))),
])],
6,
4,
2,
);

let mut iter = help.iter();

let line = iter.next();
assert_eq!(line, Some(" --foo-bar".to_string()));

let line = iter.next();
assert_eq!(line, Some(" ".repeat(10) + &"a".repeat(cols - 6 - 4 - 2)));

let line = iter.next();
assert_eq!(line, Some(" ".repeat(10) + &"a".repeat(6 + 4 + 2)));

let line = iter.next();
assert_eq!(line, None);
}

#[test]
fn add_opts_if_opts_are_multiple() {
use crate::OptCfgParam::*;
Expand Down