mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-19 08:55:26 +00:00
This commit is contained in:
1 parent
a216825578
commit
de694152a9
2 files changed
+27
-2
No files matched your search
@@ -610,11 +610,12 @@ fn lin_node(n: &MNode, s: &mut String, depth: usize) {
|
||||
}
|
||||
MNode::Nary { chr, sub_hide, sup_hide, sub, sup, e, .. } => {
|
||||
s.push(*chr);
|
||||
if !sub_hide && !sub.is_empty() {
|
||||
// A shown limit is written even when empty (`_()`): left out, it reads back hidden (#6076).
|
||||
if !sub_hide {
|
||||
s.push('_');
|
||||
lin_script(sub, s, depth);
|
||||
}
|
||||
if !sup_hide && !sup.is_empty() {
|
||||
if !sup_hide {
|
||||
s.push('^');
|
||||
lin_script(sup, s, depth);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
//! An n-ary operator's empty but shown limit survives linear text (#6076): half-typed `∑_` has an
|
||||
//! empty lower limit that is shown, and `to_linear` writes it as `_()`. Left out, it reads back as a
|
||||
//! hidden limit.
|
||||
|
||||
use wordcraft_doc::math::{MNode, MRun, parse_linear, to_linear};
|
||||
|
||||
#[test]
|
||||
fn an_empty_shown_limit_prints_back_the_same() {
|
||||
for s in ["∑_", "∑^", "∫_0^▒x", "∑_()^n▒i"] {
|
||||
let n = parse_linear(s);
|
||||
assert_eq!(parse_linear(&to_linear(&n)), n, "{s} → {}", to_linear(&n));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hidden_and_filled_limits_print_as_before() {
|
||||
let nary = |sub_hide, sup_hide, sub: &str, sup: &str| {
|
||||
let arg = |t: &str| if t.is_empty() { Vec::new() } else { vec![MNode::Run(MRun::new(t))] };
|
||||
vec![MNode::Nary { chr: '∑', lim_loc: None, grow: false, sub_hide, sup_hide, sub: arg(sub), sup: arg(sup), e: arg("x") }]
|
||||
};
|
||||
assert_eq!(to_linear(&nary(true, true, "", "")), "∑▒x");
|
||||
assert_eq!(to_linear(&nary(false, false, "i", "n")), "∑_i^n▒x");
|
||||
assert_eq!(to_linear(&nary(false, true, "", "")), "∑_()▒x");
|
||||
}
|
||||
Reference in new issue
Block a user