From 8e5045ac836e31f4c0b7e185052a1145e2d8b809 Mon Sep 17 00:00:00 2001 From: OrangeX4 <34951714+OrangeX4@users.noreply.github.com> Date: Wed, 27 Mar 2024 23:07:54 +0800 Subject: [PATCH] fix: fix broken lr (#144) * fix: fix broken lr * fix: make ci happy --- crates/mitex-parser/tests/properties.rs | 7 ++----- crates/mitex/src/lib.rs | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/crates/mitex-parser/tests/properties.rs b/crates/mitex-parser/tests/properties.rs index 8df1b1d..53238ff 100644 --- a/crates/mitex-parser/tests/properties.rs +++ b/crates/mitex-parser/tests/properties.rs @@ -84,13 +84,10 @@ mod properties { #[test] fn test_lr_symbol() { fn lr_info(input: &str) -> Option { - let Some(e) = parse(input) + let e = parse(input) .descendants() .find(|node| matches!(node.kind(), SyntaxKind::ItemLR)) - .and_then(LRItem::cast) - else { - return None; - }; + .and_then(LRItem::cast)?; fn pretty_sym(s: Option) -> String { s.map(SnapToken) diff --git a/crates/mitex/src/lib.rs b/crates/mitex/src/lib.rs index 64cd7f9..a6391af 100644 --- a/crates/mitex/src/lib.rs +++ b/crates/mitex/src/lib.rs @@ -241,6 +241,8 @@ impl Converter { _ => self.convert(f, rowan::NodeOrToken::Token(token), spec)?, }, } + // add space + f.write_char(' ')?; } if name == "right" { f.write_char(')')?; @@ -949,29 +951,35 @@ mod tests { fn test_convert_lr() { assert_debug_snapshot!(convert_math(r#"$\left.\right.$"#), @r###" Ok( - "lr()", + "lr( )", ) "###); assert_debug_snapshot!(convert_math(r#"$\left.a\right.$"#), @r###" Ok( - "lr(a )", + "lr( a )", ) "###); assert_debug_snapshot!(convert_math(r#"$\alpha\left.\right.$"#), @r###" Ok( - "alpha lr()", + "alpha lr( )", ) "### ); assert_debug_snapshot!(convert_math(r#"$\left . a \right \|$"#), @r###" Ok( - "lr( a ||)", + "lr( a || )", ) "### ); assert_debug_snapshot!(convert_math(r#"$\left\langle a\right\|$"#), @r###" Ok( - "lr(angle.l a ||)", + "lr(angle.l a || )", + ) + "### + ); + assert_debug_snapshot!(convert_math(r#"$\left\lbrack\lbrack x\rbrack\right\rbrack$"#), @r###" + Ok( + "lr(bracket.l bracket.l x bracket.r bracket.r )", ) "### );