From ca692987e76fdf6ce666d1fc1bee42f68247fbd6 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Sun, 22 Oct 2023 11:02:17 -0500 Subject: [PATCH 1/8] initial commit for math block align --- lib/src/lib.rs | 10 ++- lib/src/math.rs | 155 ++++++++++++++++++++++++++++++++++++++++++ lib/src/tests/math.rs | 41 +++++++++++ lib/src/tests/mod.rs | 1 + 4 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 lib/src/math.rs create mode 100644 lib/src/tests/math.rs diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 9bee1bd..611e2d5 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -12,8 +12,11 @@ use typst_syntax::{parse, LinkedNode}; use Option::None; mod config; + pub use config::Config; + mod context; + use context::Ctx; mod utils; @@ -22,6 +25,7 @@ mod binary; mod code_blocks; mod markup; mod params; +mod math; #[must_use] pub fn format(s: &str, config: Config) -> String { @@ -43,7 +47,7 @@ pub fn format(s: &str, config: Config) -> String { /// how they will be formatted. /// /// One assumed rule is that no kind should be formatting with surrounded space -#[instrument(skip_all,name = "V", fields(kind = format!("{:?}",node.kind())))] +#[instrument(skip_all, name = "V", fields(kind = format!("{:?}",node.kind())))] fn visit(node: &LinkedNode, ctx: &mut Ctx) -> String { let mut res: Vec = vec![]; for child in node.children() { @@ -68,6 +72,10 @@ fn visit(node: &LinkedNode, ctx: &mut Ctx) -> String { ctx.lost_context(); node.text().to_string() } + Equation => { + math::format_equation(node, &res, ctx) + } + Math => math::format_math(node, &res, ctx), _ => format_default(node, &res, ctx), }; if node.children().count() == 0 { diff --git a/lib/src/math.rs b/lib/src/math.rs new file mode 100644 index 0000000..904418f --- /dev/null +++ b/lib/src/math.rs @@ -0,0 +1,155 @@ +use std::cmp::max; +use tracing::info; +use super::*; +use typst_syntax::ast::*; +use crate::context::Ctx; +use crate::format_comment_handling_disable; + +#[instrument(skip_all)] +pub(crate) fn format_equation( + parent: &LinkedNode, + children: &[String], + ctx: &mut Ctx, +) -> String { + let mut res = String::new(); + let first_space = parent + .children().nth(1); + let space_type = if first_space.as_ref().is_some_and(|s| s.text().contains('\n')) { + "\n" + } else { + " " + }; + + let mut first_dollar = true; + + + info!("equation children: {:?}", children); + + let newline = space_type == "\n"; + + for (s, node) in children.iter().zip(parent.children()) { + match node.kind() { + _ if ctx.off => res.push_str(node.text()), + LineComment | BlockComment => { + let buf = format_comment_handling_disable(&node, &[], ctx); + ctx.push_raw_in(&buf, &mut res); + } + Dollar if first_dollar => { + first_dollar = false; + ctx.push_raw_in(s, &mut res); + } + Math => { + if newline { + ctx.push_raw_in(ctx.get_indent().as_str(), &mut res); + ctx.push_raw_indent(s, &mut res); + } else { + ctx.push_raw_in(s, &mut res); + } + } + Space => { + ctx.push_raw_in(space_type, &mut res); + } + _ => { + ctx.push_raw_indent(s, &mut res) + } + } + } + res +} + + +#[instrument(skip_all)] +pub(crate) fn format_math( + parent: &LinkedNode, + children: &[String], + ctx: &mut Ctx, +) -> String { + let mut res = String::new(); + + let mut align_points: Vec = retrieve_align_point(parent, children); + let mut index = 0; + let mut position = 0usize; + + info!("math children: {:?}", children); + + let mut first_align = true; + let mut should_indent = false; + + for (s, node) in children.iter().zip(parent.children()) { + match node.kind() { + _ if ctx.off => res.push_str(node.text()), + MathAlignPoint => { + if align_points[index] < position { + panic!("align point {} is smaller than position {}", align_points[index], position); + } + + if position == 0 && first_align { + should_indent = true; + } + + if position == 0 && should_indent { + ctx.push_raw_in(ctx.get_indent().as_str(), &mut res); + } + + ctx.push_raw_in(" ".repeat(align_points[index] - position).as_str(), &mut res); + ctx.push_raw_in(s, &mut res); + position = align_points[index] + s.len(); + index += 1; + + first_align = false; + } + Space if s.contains('\n') => { + position = 0; + index = 0; + ctx.push_raw_in(s, &mut res); + } + Space => { + position += 1; + ctx.push_raw_in(" ", &mut res); + } + _ => { + position += s.len(); + ctx.push_raw_in(s, &mut res) + } + } + } + + res +} + + +fn retrieve_align_point(parent: &LinkedNode, children: &[String]) -> Vec { + let mut align_points: Vec = vec![]; + let mut index = 0; + let mut position = 0usize; + + let mut space = false; + + for (s, node) in children.iter().zip(parent.children()) { + match node.kind() { + MathAlignPoint => { + if align_points.len() <= index { + align_points.push(position); + + position += s.len(); + } else { + align_points[index] = max(align_points[index], position); + } + index += 1 + } + Space if s.contains('\n') => { + position = 0; + index = 0; + } + Space => { + space = true; + position += 1; + } + _ => { + space = false; + position += s.len(); + } + } + } + align_points +} \ No newline at end of file diff --git a/lib/src/tests/math.rs b/lib/src/tests/math.rs new file mode 100644 index 0000000..12483aa --- /dev/null +++ b/lib/src/tests/math.rs @@ -0,0 +1,41 @@ +use super::*; + +make_test!(mathblock1, +r#"$ + #xx(a,b) &= 1 \ + &= 2 \ + +$"#); + + +make_test!(mathblock2, +r#"$x$"#); + + +make_test!(mathblock3, +r#"$ + #xx(a,b) &= 1 \ + &= 2 \ + &=3 \ + &=4 \ + +$"#); + +make_test!(mathblock4, +r#"$ + #xx(a,b) &= 1 &=3 \ + &= 2 &=2 \ + &=3 \ + &=4 \ + &=5 \ + $"#); + +make_test!(mathblock5, +r#"$ +#xx(a,b) + &= 1 &=3 \ + &= 2 &=2 \ + &=3 \ + &=4 \ + &=5 \ + $"#); diff --git a/lib/src/tests/mod.rs b/lib/src/tests/mod.rs index b8cf492..32f7218 100644 --- a/lib/src/tests/mod.rs +++ b/lib/src/tests/mod.rs @@ -170,3 +170,4 @@ mod lists; mod markup; mod params; mod snippets; +mod math; From a801b38745f5899bcf2f0de70309bae0665627e1 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Sun, 22 Oct 2023 11:08:08 -0500 Subject: [PATCH 2/8] add one more test case --- lib/src/tests/math.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/src/tests/math.rs b/lib/src/tests/math.rs index 12483aa..b568711 100644 --- a/lib/src/tests/math.rs +++ b/lib/src/tests/math.rs @@ -39,3 +39,12 @@ r#"$ &=4 \ &=5 \ $"#); + +make_test!(mathblock6, +r#"$ + #xx(a,b) &= 1 &=3 \ + &= 2 &=2 \ + &=3 \ + &=4 \ + &=5 \ + $"#); \ No newline at end of file From 87f78a41c2edbbfebc2b8439b0635cf2f37c97f6 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Mon, 23 Oct 2023 10:41:01 -0500 Subject: [PATCH 3/8] add test result and a new test --- lib/src/tests/math.rs | 10 +++++++++- ...ypstfmt_lib__tests__math__mathblock1__snapshot.snap | 6 ++++++ ...ypstfmt_lib__tests__math__mathblock2__snapshot.snap | 6 ++++++ ...ypstfmt_lib__tests__math__mathblock3__snapshot.snap | 6 ++++++ ...ypstfmt_lib__tests__math__mathblock4__snapshot.snap | 6 ++++++ ...ypstfmt_lib__tests__math__mathblock5__snapshot.snap | 6 ++++++ ...ypstfmt_lib__tests__math__mathblock6__snapshot.snap | 6 ++++++ ...fmt_lib__tests__math__mathblock7__snapshot.snap.new | 7 +++++++ ...typstfmt_lib__tests__math__mathblock__snapshot.snap | 6 ++++++ 9 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock1__snapshot.snap create mode 100644 lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock2__snapshot.snap create mode 100644 lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock3__snapshot.snap create mode 100644 lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock4__snapshot.snap create mode 100644 lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock5__snapshot.snap create mode 100644 lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock6__snapshot.snap create mode 100644 lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock7__snapshot.snap.new create mode 100644 lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock__snapshot.snap diff --git a/lib/src/tests/math.rs b/lib/src/tests/math.rs index b568711..9171293 100644 --- a/lib/src/tests/math.rs +++ b/lib/src/tests/math.rs @@ -47,4 +47,12 @@ r#"$ &=3 \ &=4 \ &=5 \ - $"#); \ No newline at end of file + $"#); + +make_test!(mathblock7, +r#"$ +mat( + 1,2,3,4; +5,2,2,3 +) +$"#); \ No newline at end of file diff --git a/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock1__snapshot.snap b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock1__snapshot.snap new file mode 100644 index 0000000..e91ab1e --- /dev/null +++ b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock1__snapshot.snap @@ -0,0 +1,6 @@ +--- +source: lib/src/tests/math.rs +description: "INPUT\n===\n\"$\\n #xx(a,b) &= 1 \\\\\\n &= 2 \\\\\\n\\n$\"\n===\n$\n #xx(a,b) &= 1 \\\n &= 2 \\\n\n$\n===\nFORMATTED\n===\n$\n #xx(a, b) &= 1 \\\n &= 2 \\\n$" +expression: formatted +--- +"$\n #xx(a, b) &= 1 \\\n &= 2 \\\n$" diff --git a/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock2__snapshot.snap b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock2__snapshot.snap new file mode 100644 index 0000000..d276aa0 --- /dev/null +++ b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock2__snapshot.snap @@ -0,0 +1,6 @@ +--- +source: lib/src/tests/math.rs +description: "INPUT\n===\n\"$x$\"\n===\n$x$\n===\nFORMATTED\n===\n$x$" +expression: formatted +--- +"$x$" diff --git a/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock3__snapshot.snap b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock3__snapshot.snap new file mode 100644 index 0000000..c5dc536 --- /dev/null +++ b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock3__snapshot.snap @@ -0,0 +1,6 @@ +--- +source: lib/src/tests/math.rs +description: "INPUT\n===\n\"$\\n #xx(a,b) &= 1 \\\\\\n &= 2 \\\\\\n &=3 \\\\\\n &=4 \\\\\\n\\n$\"\n===\n$\n #xx(a,b) &= 1 \\\n &= 2 \\\n &=3 \\\n &=4 \\\n\n$\n===\nFORMATTED\n===\n$\n #xx(a, b) &= 1 \\\n &= 2 \\\n &=3 \\\n &=4 \\\n$" +expression: formatted +--- +"$\n #xx(a, b) &= 1 \\\n &= 2 \\\n &=3 \\\n &=4 \\\n$" diff --git a/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock4__snapshot.snap b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock4__snapshot.snap new file mode 100644 index 0000000..263149c --- /dev/null +++ b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock4__snapshot.snap @@ -0,0 +1,6 @@ +--- +source: lib/src/tests/math.rs +description: "INPUT\n===\n\"$\\n #xx(a,b) &= 1 &=3 \\\\\\n &= 2 &=2 \\\\\\n &=3 \\\\\\n &=4 \\\\\\n &=5 \\\\\\n $\"\n===\n$\n #xx(a,b) &= 1 &=3 \\\n &= 2 &=2 \\\n &=3 \\\n &=4 \\\n &=5 \\\n $\n===\nFORMATTED\n===\n$\n #xx(a, b) &= 1 &=3 \\\n &= 2 &=2 \\\n &=3 \\\n &=4 \\\n &=5 \\\n$" +expression: formatted +--- +"$\n #xx(a, b) &= 1 &=3 \\\n &= 2 &=2 \\\n &=3 \\\n &=4 \\\n &=5 \\\n$" diff --git a/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock5__snapshot.snap b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock5__snapshot.snap new file mode 100644 index 0000000..df226b7 --- /dev/null +++ b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock5__snapshot.snap @@ -0,0 +1,6 @@ +--- +source: lib/src/tests/math.rs +description: "INPUT\n===\n\"$\\n#xx(a,b)\\n &= 1 &=3 \\\\\\n &= 2 &=2 \\\\\\n &=3 \\\\\\n &=4 \\\\\\n &=5 \\\\\\n $\"\n===\n$\n#xx(a,b)\n &= 1 &=3 \\\n &= 2 &=2 \\\n &=3 \\\n &=4 \\\n &=5 \\\n $\n===\nFORMATTED\n===\n$\n #xx(a, b)\n &= 1 &=3 \\\n &= 2 &=2 \\\n &=3 \\\n &=4 \\\n &=5 \\\n$" +expression: formatted +--- +"$\n #xx(a, b)\n &= 1 &=3 \\\n &= 2 &=2 \\\n &=3 \\\n &=4 \\\n &=5 \\\n$" diff --git a/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock6__snapshot.snap b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock6__snapshot.snap new file mode 100644 index 0000000..0bb1042 --- /dev/null +++ b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock6__snapshot.snap @@ -0,0 +1,6 @@ +--- +source: lib/src/tests/math.rs +description: "INPUT\n===\n\"$\\n #xx(a,b) &= 1 &=3 \\\\\\n &= 2 &=2 \\\\\\n &=3 \\\\\\n &=4 \\\\\\n &=5 \\\\\\n $\"\n===\n$\n #xx(a,b) &= 1 &=3 \\\n &= 2 &=2 \\\n &=3 \\\n &=4 \\\n &=5 \\\n $\n===\nFORMATTED\n===\n$\n #xx(a, b) &= 1 &=3 \\\n &= 2 &=2 \\\n &=3 \\\n &=4 \\\n &=5 \\\n$" +expression: formatted +--- +"$\n #xx(a, b) &= 1 &=3 \\\n &= 2 &=2 \\\n &=3 \\\n &=4 \\\n &=5 \\\n$" diff --git a/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock7__snapshot.snap.new b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock7__snapshot.snap.new new file mode 100644 index 0000000..7f5fc83 --- /dev/null +++ b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock7__snapshot.snap.new @@ -0,0 +1,7 @@ +--- +source: lib/src/tests/math.rs +assertion_line: 52 +description: "INPUT\n===\n\"$\\nmat(\\n 1,2,3,4;\\n5,2,2,3\\n)\\n$\"\n===\n$\nmat(\n 1,2,3,4;\n5,2,2,3\n)\n$\n===\nFORMATTED\n===\n$\n mat(1, 2, 3, 4;5, 2, 2, 3)\n$" +expression: formatted +--- +"$\n mat(1, 2, 3, 4;5, 2, 2, 3)\n$" diff --git a/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock__snapshot.snap b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock__snapshot.snap new file mode 100644 index 0000000..e91ab1e --- /dev/null +++ b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock__snapshot.snap @@ -0,0 +1,6 @@ +--- +source: lib/src/tests/math.rs +description: "INPUT\n===\n\"$\\n #xx(a,b) &= 1 \\\\\\n &= 2 \\\\\\n\\n$\"\n===\n$\n #xx(a,b) &= 1 \\\n &= 2 \\\n\n$\n===\nFORMATTED\n===\n$\n #xx(a, b) &= 1 \\\n &= 2 \\\n$" +expression: formatted +--- +"$\n #xx(a, b) &= 1 \\\n &= 2 \\\n$" From de7320b40cbb3770db75024d1b905cb31f1a2959 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Mon, 23 Oct 2023 10:41:35 -0500 Subject: [PATCH 4/8] remove debugging code --- lib/src/math.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/src/math.rs b/lib/src/math.rs index 904418f..30595f8 100644 --- a/lib/src/math.rs +++ b/lib/src/math.rs @@ -22,9 +22,6 @@ pub(crate) fn format_equation( let mut first_dollar = true; - - info!("equation children: {:?}", children); - let newline = space_type == "\n"; for (s, node) in children.iter().zip(parent.children()) { @@ -70,8 +67,6 @@ pub(crate) fn format_math( let mut index = 0; let mut position = 0usize; - info!("math children: {:?}", children); - let mut first_align = true; let mut should_indent = false; From 0604379ae2cafd1553cc9934032d2abc4a30c096 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Mon, 23 Oct 2023 10:45:11 -0500 Subject: [PATCH 5/8] format and use debug assert --- lib/src/math.rs | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/lib/src/math.rs b/lib/src/math.rs index 30595f8..74cf763 100644 --- a/lib/src/math.rs +++ b/lib/src/math.rs @@ -1,20 +1,18 @@ -use std::cmp::max; -use tracing::info; use super::*; -use typst_syntax::ast::*; use crate::context::Ctx; use crate::format_comment_handling_disable; +use std::cmp::max; +use tracing::info; +use typst_syntax::ast::*; #[instrument(skip_all)] -pub(crate) fn format_equation( - parent: &LinkedNode, - children: &[String], - ctx: &mut Ctx, -) -> String { +pub(crate) fn format_equation(parent: &LinkedNode, children: &[String], ctx: &mut Ctx) -> String { let mut res = String::new(); - let first_space = parent - .children().nth(1); - let space_type = if first_space.as_ref().is_some_and(|s| s.text().contains('\n')) { + let first_space = parent.children().nth(1); + let space_type = if first_space + .as_ref() + .is_some_and(|s| s.text().contains('\n')) + { "\n" } else { " " @@ -46,21 +44,14 @@ pub(crate) fn format_equation( Space => { ctx.push_raw_in(space_type, &mut res); } - _ => { - ctx.push_raw_indent(s, &mut res) - } + _ => ctx.push_raw_indent(s, &mut res), } } res } - #[instrument(skip_all)] -pub(crate) fn format_math( - parent: &LinkedNode, - children: &[String], - ctx: &mut Ctx, -) -> String { +pub(crate) fn format_math(parent: &LinkedNode, children: &[String], ctx: &mut Ctx) -> String { let mut res = String::new(); let mut align_points: Vec = retrieve_align_point(parent, children); @@ -74,9 +65,12 @@ pub(crate) fn format_math( match node.kind() { _ if ctx.off => res.push_str(node.text()), MathAlignPoint => { - if align_points[index] < position { - panic!("align point {} is smaller than position {}", align_points[index], position); - } + debug_assert!( + align_points[index] >= position, + "align point {} is smaller than position {}", + align_points[index], + position + ); if position == 0 && first_align { should_indent = true; @@ -86,7 +80,10 @@ pub(crate) fn format_math( ctx.push_raw_in(ctx.get_indent().as_str(), &mut res); } - ctx.push_raw_in(" ".repeat(align_points[index] - position).as_str(), &mut res); + ctx.push_raw_in( + " ".repeat(align_points[index] - position).as_str(), + &mut res, + ); ctx.push_raw_in(s, &mut res); position = align_points[index] + s.len(); index += 1; @@ -112,7 +109,6 @@ pub(crate) fn format_math( res } - fn retrieve_align_point(parent: &LinkedNode, children: &[String]) -> Vec { let mut align_points: Vec = vec![]; let mut index = 0; @@ -147,4 +143,4 @@ fn retrieve_align_point(parent: &LinkedNode, children: &[String]) -> Vec } } align_points -} \ No newline at end of file +} From 87ebbdc9be5788d61b482393b358d415c6bce9b9 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Mon, 23 Oct 2023 10:45:39 -0500 Subject: [PATCH 6/8] accept new test result --- ....new => typstfmt_lib__tests__math__mathblock7__snapshot.snap} | 1 - 1 file changed, 1 deletion(-) rename lib/src/tests/snapshots/{typstfmt_lib__tests__math__mathblock7__snapshot.snap.new => typstfmt_lib__tests__math__mathblock7__snapshot.snap} (93%) diff --git a/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock7__snapshot.snap.new b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock7__snapshot.snap similarity index 93% rename from lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock7__snapshot.snap.new rename to lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock7__snapshot.snap index 7f5fc83..573b0d3 100644 --- a/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock7__snapshot.snap.new +++ b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock7__snapshot.snap @@ -1,6 +1,5 @@ --- source: lib/src/tests/math.rs -assertion_line: 52 description: "INPUT\n===\n\"$\\nmat(\\n 1,2,3,4;\\n5,2,2,3\\n)\\n$\"\n===\n$\nmat(\n 1,2,3,4;\n5,2,2,3\n)\n$\n===\nFORMATTED\n===\n$\n mat(1, 2, 3, 4;5, 2, 2, 3)\n$" expression: formatted --- From 5486efbe3da5defb4aac1952f9eb214d33b4803a Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Wed, 25 Oct 2023 17:39:43 -0500 Subject: [PATCH 7/8] add one more test case --- lib/src/tests/math.rs | 5 ++++- ...ypstfmt_lib__tests__math__mathblock8__snapshot.snap.new | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock8__snapshot.snap.new diff --git a/lib/src/tests/math.rs b/lib/src/tests/math.rs index 9171293..619531d 100644 --- a/lib/src/tests/math.rs +++ b/lib/src/tests/math.rs @@ -55,4 +55,7 @@ mat( 1,2,3,4; 5,2,2,3 ) -$"#); \ No newline at end of file +$"#); + +make_test!(mathblock8, +r#"$#xx(a,b) &= 1 \ #xx(a,b) &= 1 \ &= 2 \ $"#); \ No newline at end of file diff --git a/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock8__snapshot.snap.new b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock8__snapshot.snap.new new file mode 100644 index 0000000..336065b --- /dev/null +++ b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock8__snapshot.snap.new @@ -0,0 +1,7 @@ +--- +source: lib/src/tests/math.rs +assertion_line: 60 +description: "INPUT\n===\n\"$#xx(a,b) &= 1 \\\\ #xx(a,b) &= 1 \\\\ &= 2 \\\\ $\"\n===\n$#xx(a,b) &= 1 \\ #xx(a,b) &= 1 \\ &= 2 \\ $\n===\nFORMATTED\n===\n$#xx(a, b) &= 1 \\ #xx(a, b) &= 1 \\ &= 2 \\ $" +expression: formatted +--- +"$#xx(a, b) &= 1 \\ #xx(a, b) &= 1 \\ &= 2 \\ $" From 94e72478c95395f9138002fe9327f78f47354c23 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Sat, 28 Oct 2023 16:16:38 -0500 Subject: [PATCH 8/8] fix test snapshot --- ....new => typstfmt_lib__tests__math__mathblock8__snapshot.snap} | 1 - 1 file changed, 1 deletion(-) rename lib/src/tests/snapshots/{typstfmt_lib__tests__math__mathblock8__snapshot.snap.new => typstfmt_lib__tests__math__mathblock8__snapshot.snap} (94%) diff --git a/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock8__snapshot.snap.new b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock8__snapshot.snap similarity index 94% rename from lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock8__snapshot.snap.new rename to lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock8__snapshot.snap index 336065b..0d42b01 100644 --- a/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock8__snapshot.snap.new +++ b/lib/src/tests/snapshots/typstfmt_lib__tests__math__mathblock8__snapshot.snap @@ -1,6 +1,5 @@ --- source: lib/src/tests/math.rs -assertion_line: 60 description: "INPUT\n===\n\"$#xx(a,b) &= 1 \\\\ #xx(a,b) &= 1 \\\\ &= 2 \\\\ $\"\n===\n$#xx(a,b) &= 1 \\ #xx(a,b) &= 1 \\ &= 2 \\ $\n===\nFORMATTED\n===\n$#xx(a, b) &= 1 \\ #xx(a, b) &= 1 \\ &= 2 \\ $" expression: formatted ---