mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-22 04:33:13 +00:00
fix(text): remove trailing newline from single-line Display trait impl (#1320)
This commit is contained in:
parent
8b624f5952
commit
fdd5d8c092
1 changed files with 7 additions and 6 deletions
|
@ -633,7 +633,7 @@ impl<T: fmt::Display> ToText for T {
|
|||
impl fmt::Display for Text<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
for (position, line) in self.iter().with_position() {
|
||||
if position == Position::Last {
|
||||
if position == Position::Last || position == Position::Only {
|
||||
write!(f, "{line}")?;
|
||||
} else {
|
||||
writeln!(f, "{line}")?;
|
||||
|
@ -945,11 +945,12 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn display_raw_text() {
|
||||
let text = Text::raw("The first line\nThe second line");
|
||||
|
||||
assert_eq!(format!("{text}"), "The first line\nThe second line");
|
||||
#[rstest]
|
||||
#[case::one_line("The first line")]
|
||||
#[case::multiple_lines("The first line\nThe second line")]
|
||||
fn display_raw_text(#[case] value: &str) {
|
||||
let text = Text::raw(value);
|
||||
assert_eq!(format!("{text}"), value);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue