use latex_contract_frontend::LatexContractFrontend;
use std::path::PathBuf;
use xpile_contract_frontend::ContractFrontend;
fn fixture_path(name: &str) -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures")
.join(name)
}
#[test]
fn c_notation_runtime_three_forms_produce_equal_formula() {
let src =
std::fs::read_to_string(fixture_path("notation_demo.tex")).expect("read notation_demo.tex");
let frontend = LatexContractFrontend;
let block = frontend
.parse_to_equations(&src)
.expect("parse_to_equations should succeed on notation_demo.tex");
assert_eq!(
block.equations.len(),
3,
"expected 3 equations (one per form: \\[ \\], equation, align); got {}",
block.equations.len()
);
let formulas: Vec<&str> = block
.equations
.values()
.map(|e| e.formula.as_str())
.collect();
let first = formulas[0];
for (i, f) in formulas.iter().enumerate() {
assert_eq!(
*f, first,
"form {i} formula differs from form 0: form 0 = {first:?}, form {i} = {f:?}"
);
}
assert_eq!(
first, "a^2 + b^2 = c^2",
"expected the Pythagorean identity, got {first:?}"
);
}
#[test]
fn c_notation_runtime_parse_is_deterministic_on_notation_demo_fixture() {
let src =
std::fs::read_to_string(fixture_path("notation_demo.tex")).expect("read notation_demo.tex");
let frontend = LatexContractFrontend;
let first = frontend.parse_to_equations(&src).expect("first parse");
let second = frontend.parse_to_equations(&src).expect("second parse");
assert_eq!(
first, second,
"C-NOTATION-LATEX-MATH-TO-EQUATION-V1 parse_to_equations \
non-deterministic on notation_demo.tex"
);
}