Skip to content

Commit 1ab65ce

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

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,37 @@ 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!(actual.ansi().to_string(), str![[r#"
230+
12345 12345 12345
231+
12345
232+
"#]]);
233+
}
234+
235+
#[test]
236+
#[cfg(feature = "wrap_help")]
237+
fn wrap_styled() {
238+
let style = anstyle::Style::new().bold();
239+
let input = format!("{style}12345{style:#} {style}12345{style:#} {style}12345{style:#} {style}12345{style:#}");
240+
let mut actual = StyledStr::new();
241+
actual.push_string(input);
242+
actual.wrap(20);
243+
assert_data_eq!(actual.ansi().to_string(), str!["12345 12345 12345 12345"]);
244+
}
245+
}

0 commit comments

Comments
 (0)