From 1b53e27f270e3c040ee095573af9a5243980191a Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 13 Jan 2021 21:33:22 +0100 Subject: [PATCH] =?UTF-8?q?Some=20minor=20improvements=20=E2=99=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/eval/call.rs | 2 +- src/geom/length.rs | 5 +++++ src/geom/size.rs | 5 +++++ src/layout/mod.rs | 5 ++++- src/parse/lines.rs | 8 ++++---- src/pretty.rs | 3 ++- tests/typeset.rs | 31 ++++++++++++++----------------- 7 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/eval/call.rs b/src/eval/call.rs index a2387a175..f47ee8479 100644 --- a/src/eval/call.rs +++ b/src/eval/call.rs @@ -102,7 +102,7 @@ impl Args { /// Convert and remove the value for the given named argument, producing an /// error if the conversion fails. - pub fn get<'a, T>(&mut self, ctx: &mut EvalContext, name: &str) -> Option + pub fn get(&mut self, ctx: &mut EvalContext, name: &str) -> Option where T: Cast>, { diff --git a/src/geom/length.rs b/src/geom/length.rs index 3e6c86019..f4d8682ed 100644 --- a/src/geom/length.rs +++ b/src/geom/length.rs @@ -80,6 +80,11 @@ impl Length { pub fn max(self, other: Self) -> Self { Self { raw: self.raw.max(other.raw) } } + + /// Whether the length is `NaN`. + pub fn is_nan(self) -> bool { + self.raw.is_nan() + } } impl Display for Length { diff --git a/src/geom/size.rs b/src/geom/size.rs index bc233e5cc..1dfc8b97e 100644 --- a/src/geom/size.rs +++ b/src/geom/size.rs @@ -30,6 +30,11 @@ impl Size { pub fn fits(self, other: Self) -> bool { self.width >= other.width && self.height >= other.height } + + /// Whether any of the two components is `NaN`. + pub fn is_nan(self) -> bool { + self.width.is_nan() || self.height.is_nan() + } } impl Get for Size { diff --git a/src/layout/mod.rs b/src/layout/mod.rs index d09566e35..30026b9f7 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -128,7 +128,10 @@ impl Areas { /// /// If this is false calling `next()` will have no effect. pub fn in_full_last(&self) -> bool { - self.backlog.is_empty() && self.last.map_or(true, |size| self.current.rem == size) + self.backlog.is_empty() + && self.last.map_or(true, |size| { + self.current.rem.is_nan() || size.is_nan() || self.current.rem == size + }) } } diff --git a/src/parse/lines.rs b/src/parse/lines.rs index d1a6c781f..c47b7534a 100644 --- a/src/parse/lines.rs +++ b/src/parse/lines.rs @@ -70,13 +70,13 @@ impl<'s> LineMap<'s> { /// Whether this character denotes a newline. pub fn is_newline(character: char) -> bool { - match character { + matches!( + character, // Line Feed, Vertical Tab, Form Feed, Carriage Return. '\n' | '\x0B' | '\x0C' | '\r' | // Next Line, Line Separator, Paragraph Separator. - '\u{0085}' | '\u{2028}' | '\u{2029}' => true, - _ => false, - } + '\u{0085}' | '\u{2028}' | '\u{2029}' + ) } #[cfg(test)] diff --git a/src/pretty.rs b/src/pretty.rs index f6398495f..f1c3cfb7d 100644 --- a/src/pretty.rs +++ b/src/pretty.rs @@ -63,6 +63,7 @@ impl Printer { impl Write for Printer { fn write_str(&mut self, s: &str) -> Result { - Ok(self.push_str(s)) + self.push_str(s); + Ok(()) } } diff --git a/tests/typeset.rs b/tests/typeset.rs index 6f077ed15..499c5c04a 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -50,11 +50,9 @@ fn main() { } let len = filtered.len(); - if len == 0 { - return; - } else if len == 1 { + if len == 1 { println!("Running test ..."); - } else { + } else if len > 1 { println!("Running {} tests", len); } @@ -70,8 +68,19 @@ fn main() { resources: ResourceLoader::new(), })); - let mut ok = true; + let playground = Path::new("playground.typ"); + if playground.exists() { + test( + "playground", + playground, + Path::new("playground.png"), + Path::new("playground.pdf"), + None, + &env, + ); + } + let mut ok = true; for (name, src_path) in filtered { let png_path = Path::new(PNG_DIR).join(&name).with_extension("png"); let pdf_path = Path::new(PDF_DIR).join(&name).with_extension("pdf"); @@ -86,18 +95,6 @@ fn main() { ); } - let playground = Path::new("playground.typ"); - if playground.exists() { - test( - "playground", - playground, - Path::new("playground.png"), - Path::new("playground.pdf"), - None, - &env, - ); - } - if !ok { std::process::exit(1); }