mirror of
https://github.com/youwen5/iamb.git
synced 2025-06-20 05:39:52 -07:00
Fix underflow panics when using TextPrinter::push_span_nobreak
(#322)
This commit is contained in:
parent
c94d7d0ad7
commit
54cb7991be
1 changed files with 16 additions and 1 deletions
|
@ -94,7 +94,7 @@ impl<'a> TextPrinter<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remaining(&self) -> usize {
|
fn remaining(&self) -> usize {
|
||||||
self.width - self.curr_width
|
self.width.saturating_sub(self.curr_width)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If there is any text on the current line, start a new one.
|
/// If there is any text on the current line, start a new one.
|
||||||
|
@ -276,3 +276,18 @@ impl<'a> TextPrinter<'a> {
|
||||||
self.text
|
self.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_push_nobreak() {
|
||||||
|
let mut printer = TextPrinter::new(5, Style::default(), false, false);
|
||||||
|
printer.push_span_nobreak("hello world".into());
|
||||||
|
let text = printer.finish();
|
||||||
|
assert_eq!(text.lines.len(), 1);
|
||||||
|
assert_eq!(text.lines[0].spans.len(), 1);
|
||||||
|
assert_eq!(text.lines[0].spans[0].content, "hello world");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue