Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
),
("issue #94", r"\mathrm{AA}", [r"\mathrm", ["A", "A"]]),
(
"issue #96",
r"(1+(x-y)^{2})",
["(", "1", "+", "^", ["(", "x", "-", "y", ")"], ["2"], ")"],
),
("issue #98", r"p_{\max}", ["_", "p", [r"\max"]]),
]
PARAMS_WITH_EXCEPTION = [
(r"missing \right", r"\left(x", ExtraLeftOrMissingRight),
("fraction without numerator", r"{ \over 2}", NumeratorNotFoundError),
("fraction without denominator", r"{1 \over }", DenominatorNotFoundError),
("missing subscript", r"1_", MissingSuperScriptOrSubscript),
("missing superscript", r"1^", MissingSuperScriptOrSubscript),
]
@pytest.mark.parametrize(
"name, latex, expected", ids=[x[0] for x in PARAMS], argvalues=PARAMS,
)
def test_aggregator(name: str, latex: str, expected: list):
assert aggregate(latex) == expected
@pytest.mark.parametrize(
"name, latex, exception",
ids=[x[0] for x in PARAMS_WITH_EXCEPTION],
argvalues=PARAMS_WITH_EXCEPTION,
)
def test_missing_right(name: str, latex: str, exception: Exception):
next_token = next_item_or_group(tokens)
if len(aggregated) >= 2:
if aggregated[-2] == SUBSCRIPT and token == SUPERSCRIPT:
aggregated[-2] = SUB_SUP
aggregated += [previous, next_token]
elif aggregated[-2] == SUPERSCRIPT and token == SUBSCRIPT:
aggregated[-2] = SUB_SUP
aggregated += [next_token, previous]
else:
aggregated += [token, previous, next_token]
else:
aggregated += [token, previous, next_token]
except EmptyGroupError:
aggregated += [token, previous, []]
except StopIteration:
raise MissingSuperScriptOrSubscript
except IndexError:
next_token = next_item_or_group(tokens)
aggregated += [token, "", next_token]
return aggregated