Some minor improvements ♻

This commit is contained in:
Laurenz 2021-01-13 21:33:22 +01:00
parent c36a136e6f
commit 1b53e27f27
7 changed files with 35 additions and 24 deletions

View File

@ -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<T>
pub fn get<T>(&mut self, ctx: &mut EvalContext, name: &str) -> Option<T>
where
T: Cast<Spanned<Value>>,
{

View File

@ -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 {

View File

@ -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<SpecAxis> for Size {

View File

@ -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
})
}
}

View File

@ -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)]

View File

@ -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(())
}
}

View File

@ -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);
}