Skip to content

Commit 03b9b38

Browse files
committed
test(help): Show styled wrapping behavior
1 parent 037e7e9 commit 03b9b38

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clap_builder/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ unicode-width = { version = "0.2.0", optional = true }
7171
static_assertions = "1.1.0"
7272
unic-emoji-char = "0.9.0"
7373
color-print = "0.3.6"
74+
snapbox = { version = "0.6.16" }
7475

7576
[lints]
7677
workspace = true

clap_builder/src/builder/styled_str.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,43 @@ impl std::fmt::Display for StyledStr {
209209
Ok(())
210210
}
211211
}
212+
213+
#[cfg(test)]
214+
#[cfg(feature = "wrap_help")]
215+
mod wrap_tests {
216+
use super::*;
217+
218+
use snapbox::assert_data_eq;
219+
use snapbox::str;
220+
221+
#[test]
222+
#[cfg(feature = "wrap_help")]
223+
fn wrap_unstyled() {
224+
let style = anstyle::Style::new();
225+
let input = format!("{style}12345{style:#} {style}12345{style:#} {style}12345{style:#} {style}12345{style:#}");
226+
let mut actual = StyledStr::new();
227+
actual.push_string(input);
228+
actual.wrap(20);
229+
assert_data_eq!(
230+
actual.ansi().to_string(),
231+
str![[r#"
232+
12345 12345 12345
233+
12345
234+
"#]]
235+
);
236+
}
237+
238+
#[test]
239+
#[cfg(feature = "wrap_help")]
240+
fn wrap_styled() {
241+
let style = anstyle::Style::new().bold();
242+
let input = format!("{style}12345{style:#} {style}12345{style:#} {style}12345{style:#} {style}12345{style:#}");
243+
let mut actual = StyledStr::new();
244+
actual.push_string(input);
245+
actual.wrap(20);
246+
assert_data_eq!(
247+
actual.ansi().to_string(),
248+
str!["12345 12345 12345 12345"]
249+
);
250+
}
251+
}

0 commit comments

Comments
 (0)