1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
mod expr;
mod latex;
mod parser;
mod statement;
use statement::State;
pub mod error;
use error::CalcError;
pub mod function;
pub fn generate_latex(input: &str) -> Result<String, CalcError> {
let mut state = State::new(input)?;
state.exec()?;
Ok(state.output)
}
#[cfg(test)]
#[cfg(not(target_os = "windows"))]
mod tests {
use crate::CalcError;
fn run_on_file(filename: &str) -> Result<String, CalcError> {
let contents = std::fs::read_to_string(filename).unwrap();
super::generate_latex(&contents)
}
macro_rules! test_file {
( $name: ident ) => {
#[test]
fn $name() {
let input_name = format!("test_files/{}.math", stringify!($name));
let output_name = format!("test_outputs/{}.tex", stringify!($name));
let output = run_on_file(input_name.as_str()).unwrap().replace(" ", "");
println!("{}", output);
assert_eq!(
output.trim(),
std::fs::read_to_string(output_name.as_str())
.unwrap()
.trim()
.replace(" ", ""),
);
}
};
}
test_file!(basic);
test_file!(function);
test_file!(chemistry);
test_file!(tutorial);
test_file!(power_conversion);
test_file!(adv_unit_expr);
test_file!(amu_precision);
}