mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Some minor improvements ♻
This commit is contained in:
parent
c36a136e6f
commit
1b53e27f27
@ -102,7 +102,7 @@ impl Args {
|
|||||||
|
|
||||||
/// Convert and remove the value for the given named argument, producing an
|
/// Convert and remove the value for the given named argument, producing an
|
||||||
/// error if the conversion fails.
|
/// 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
|
where
|
||||||
T: Cast<Spanned<Value>>,
|
T: Cast<Spanned<Value>>,
|
||||||
{
|
{
|
||||||
|
@ -80,6 +80,11 @@ impl Length {
|
|||||||
pub fn max(self, other: Self) -> Self {
|
pub fn max(self, other: Self) -> Self {
|
||||||
Self { raw: self.raw.max(other.raw) }
|
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 {
|
impl Display for Length {
|
||||||
|
@ -30,6 +30,11 @@ impl Size {
|
|||||||
pub fn fits(self, other: Self) -> bool {
|
pub fn fits(self, other: Self) -> bool {
|
||||||
self.width >= other.width && self.height >= other.height
|
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 {
|
impl Get<SpecAxis> for Size {
|
||||||
|
@ -128,7 +128,10 @@ impl Areas {
|
|||||||
///
|
///
|
||||||
/// If this is false calling `next()` will have no effect.
|
/// If this is false calling `next()` will have no effect.
|
||||||
pub fn in_full_last(&self) -> bool {
|
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
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,13 +70,13 @@ impl<'s> LineMap<'s> {
|
|||||||
|
|
||||||
/// Whether this character denotes a newline.
|
/// Whether this character denotes a newline.
|
||||||
pub fn is_newline(character: char) -> bool {
|
pub fn is_newline(character: char) -> bool {
|
||||||
match character {
|
matches!(
|
||||||
|
character,
|
||||||
// Line Feed, Vertical Tab, Form Feed, Carriage Return.
|
// Line Feed, Vertical Tab, Form Feed, Carriage Return.
|
||||||
'\n' | '\x0B' | '\x0C' | '\r' |
|
'\n' | '\x0B' | '\x0C' | '\r' |
|
||||||
// Next Line, Line Separator, Paragraph Separator.
|
// Next Line, Line Separator, Paragraph Separator.
|
||||||
'\u{0085}' | '\u{2028}' | '\u{2029}' => true,
|
'\u{0085}' | '\u{2028}' | '\u{2029}'
|
||||||
_ => false,
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -63,6 +63,7 @@ impl Printer {
|
|||||||
|
|
||||||
impl Write for Printer {
|
impl Write for Printer {
|
||||||
fn write_str(&mut self, s: &str) -> Result {
|
fn write_str(&mut self, s: &str) -> Result {
|
||||||
Ok(self.push_str(s))
|
self.push_str(s);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,11 +50,9 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let len = filtered.len();
|
let len = filtered.len();
|
||||||
if len == 0 {
|
if len == 1 {
|
||||||
return;
|
|
||||||
} else if len == 1 {
|
|
||||||
println!("Running test ...");
|
println!("Running test ...");
|
||||||
} else {
|
} else if len > 1 {
|
||||||
println!("Running {} tests", len);
|
println!("Running {} tests", len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,8 +68,19 @@ fn main() {
|
|||||||
resources: ResourceLoader::new(),
|
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 {
|
for (name, src_path) in filtered {
|
||||||
let png_path = Path::new(PNG_DIR).join(&name).with_extension("png");
|
let png_path = Path::new(PNG_DIR).join(&name).with_extension("png");
|
||||||
let pdf_path = Path::new(PDF_DIR).join(&name).with_extension("pdf");
|
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 {
|
if !ok {
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user