mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Make use of new Rust 1.58 formatting feature
This commit is contained in:
parent
8013a0d0e6
commit
b3062ee880
@ -220,10 +220,10 @@ impl Layout for PackedNode {
|
|||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
if !entry.check(regions) {
|
if !entry.check(regions) {
|
||||||
eprintln!("node: {:#?}", self.node);
|
eprintln!("node: {:#?}", self.node);
|
||||||
eprintln!("regions: {:#?}", regions);
|
eprintln!("regions: {regions:#?}");
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"constraints: {:#?}",
|
"constraints: {:#?}",
|
||||||
frames.iter().map(|c| c.cts).collect::<Vec<_>>()
|
frames.iter().map(|c| c.cts).collect::<Vec<_>>(),
|
||||||
);
|
);
|
||||||
panic!("constraints did not match regions they were created for");
|
panic!("constraints did not match regions they were created for");
|
||||||
}
|
}
|
||||||
|
@ -683,9 +683,9 @@ mod tests {
|
|||||||
T: Debug + PartialEq,
|
T: Debug + PartialEq,
|
||||||
{
|
{
|
||||||
if found != expected {
|
if found != expected {
|
||||||
println!("source: {:?}", src);
|
println!("source: {src:?}");
|
||||||
println!("expected: {:#?}", expected);
|
println!("expected: {expected:#?}");
|
||||||
println!("found: {:#?}", found);
|
println!("found: {found:#?}");
|
||||||
panic!("test failed");
|
panic!("test failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -549,9 +549,9 @@ mod tests {
|
|||||||
let ast = source.ast().unwrap();
|
let ast = source.ast().unwrap();
|
||||||
let found = pretty(&ast);
|
let found = pretty(&ast);
|
||||||
if found != expected {
|
if found != expected {
|
||||||
println!("tree: {:#?}", ast);
|
println!("tree: {ast:#?}");
|
||||||
println!("expected: {}", expected);
|
println!("expected: {expected}");
|
||||||
println!("found: {}", found);
|
println!("found: {found}");
|
||||||
panic!("test failed");
|
panic!("test failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ fn main() {
|
|||||||
if len == 1 {
|
if len == 1 {
|
||||||
println!("Running test ...");
|
println!("Running test ...");
|
||||||
} else if len > 1 {
|
} else if len > 1 {
|
||||||
println!("Running {} tests", len);
|
println!("Running {len} tests");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set page width to 120pt with 10pt margins, so that the inner page is
|
// Set page width to 120pt with 10pt margins, so that the inner page is
|
||||||
@ -118,7 +118,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len > 1 {
|
if len > 1 {
|
||||||
println!("{} / {} tests passed.", ok, len);
|
println!("{ok} / {len} tests passed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ok < len {
|
if ok < len {
|
||||||
@ -275,7 +275,7 @@ fn test_part(
|
|||||||
Ok(module) => {
|
Ok(module) => {
|
||||||
let tree = module.into_root();
|
let tree = module.into_root();
|
||||||
if debug {
|
if debug {
|
||||||
println!("{:#?}", tree);
|
println!("{tree:#?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut frames = tree.layout(ctx);
|
let mut frames = tree.layout(ctx);
|
||||||
@ -303,7 +303,7 @@ fn test_part(
|
|||||||
errors.sort_by(|a, b| a.span.partial_cmp(&b.span).unwrap());
|
errors.sort_by(|a, b| a.span.partial_cmp(&b.span).unwrap());
|
||||||
|
|
||||||
if errors != ref_errors {
|
if errors != ref_errors {
|
||||||
println!(" Subtest {} does not match expected errors. ❌", i);
|
println!(" Subtest {i} does not match expected errors. ❌");
|
||||||
ok = false;
|
ok = false;
|
||||||
|
|
||||||
let source = ctx.sources.get(id);
|
let source = ctx.sources.get(id);
|
||||||
@ -345,6 +345,7 @@ fn test_incremental(
|
|||||||
ctx.layouts.turnaround();
|
ctx.layouts.turnaround();
|
||||||
|
|
||||||
let cached = silenced(|| tree.layout(ctx));
|
let cached = silenced(|| tree.layout(ctx));
|
||||||
|
let total = reference.levels() - 1;
|
||||||
let misses = ctx
|
let misses = ctx
|
||||||
.layouts
|
.layouts
|
||||||
.entries()
|
.entries()
|
||||||
@ -353,19 +354,14 @@ fn test_incremental(
|
|||||||
|
|
||||||
if misses > 0 {
|
if misses > 0 {
|
||||||
println!(
|
println!(
|
||||||
" Subtest {} relayout had {} cache misses on level {} of {} ❌",
|
" Subtest {i} relayout had {misses} cache misses on level {level} of {total} ❌",
|
||||||
i,
|
|
||||||
misses,
|
|
||||||
level,
|
|
||||||
reference.levels() - 1,
|
|
||||||
);
|
);
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if cached != frames {
|
if cached != frames {
|
||||||
println!(
|
println!(
|
||||||
" Subtest {} relayout differs from clean pass on level {} ❌",
|
" Subtest {i} relayout differs from clean pass on level {level} ❌",
|
||||||
i, level
|
|
||||||
);
|
);
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
@ -414,8 +410,7 @@ fn test_reparse(src: &str, i: usize, rng: &mut LinearShift) -> bool {
|
|||||||
let mut incr_source = SourceFile::detached(src);
|
let mut incr_source = SourceFile::detached(src);
|
||||||
if incr_source.root().len() != src.len() {
|
if incr_source.root().len() != src.len() {
|
||||||
println!(
|
println!(
|
||||||
" Subtest {} tree length {} does not match string length {} ❌",
|
" Subtest {i} tree length {} does not match string length {} ❌",
|
||||||
i,
|
|
||||||
incr_source.root().len(),
|
incr_source.root().len(),
|
||||||
src.len(),
|
src.len(),
|
||||||
);
|
);
|
||||||
@ -430,14 +425,12 @@ fn test_reparse(src: &str, i: usize, rng: &mut LinearShift) -> bool {
|
|||||||
let ref_root = ref_source.root();
|
let ref_root = ref_source.root();
|
||||||
if incr_root != ref_root {
|
if incr_root != ref_root {
|
||||||
println!(
|
println!(
|
||||||
" Subtest {} reparse differs from clean parse when inserting '{}' at {}-{} ❌",
|
" Subtest {i} reparse differs from clean parse when inserting '{with}' at {}-{} ❌\n",
|
||||||
i, with, replace.start, replace.end,
|
replace.start, replace.end,
|
||||||
);
|
);
|
||||||
println!(
|
println!(" Expected reference tree:\n{ref_root:#?}\n");
|
||||||
"\n Expected reference tree:\n{:#?}\n\n Found incremental tree:\n{:#?}",
|
println!(" Found incremental tree:\n{incr_root:#?}");
|
||||||
ref_root, incr_root
|
println!("Full source ({}):\n\"{edited_src:?}\"", edited_src.len());
|
||||||
);
|
|
||||||
println!("Full source ({}):\n\"{:?}\"", edited_src.len(), edited_src);
|
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
@ -527,8 +520,8 @@ fn print_error(source: &SourceFile, line: usize, error: &Error) {
|
|||||||
let end_line = 1 + line + source.byte_to_line(error.span.end).unwrap();
|
let end_line = 1 + line + source.byte_to_line(error.span.end).unwrap();
|
||||||
let end_col = 1 + source.byte_to_column(error.span.end).unwrap();
|
let end_col = 1 + source.byte_to_column(error.span.end).unwrap();
|
||||||
println!(
|
println!(
|
||||||
"Error: {}:{}-{}:{}: {}",
|
"Error: {start_line}:{start_col}-{end_line}:{end_col}: {}",
|
||||||
start_line, start_col, end_line, end_col, error.message
|
error.message,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -540,10 +533,7 @@ fn draw(ctx: &Context, frames: &[Rc<Frame>], dpp: f32) -> sk::Pixmap {
|
|||||||
let pxw = (dpp * width.to_f32()) as u32;
|
let pxw = (dpp * width.to_f32()) as u32;
|
||||||
let pxh = (dpp * height.to_f32()) as u32;
|
let pxh = (dpp * height.to_f32()) as u32;
|
||||||
if pxw > 4000 || pxh > 4000 {
|
if pxw > 4000 || pxh > 4000 {
|
||||||
panic!(
|
panic!("overlarge image: {pxw} by {pxh} ({width:?} x {height:?})",);
|
||||||
"overlarge image: {} by {} ({:?} x {:?})",
|
|
||||||
pxw, pxh, width, height,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut canvas = sk::Pixmap::new(pxw, pxh).unwrap();
|
let mut canvas = sk::Pixmap::new(pxw, pxh).unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user