1#![allow(clippy::needless_return)]
2
3pub mod errors {
23 pub use anyhow::{anyhow, bail, Error, Result, Context};
24}
25
26pub mod interface;
27#[cfg(feature = "include-zip")]
28pub use shim_filesystem::ZIPPED_RULE_FILES;
29
30mod canonicalize;
31mod infer_intent;
32pub mod speech;
33mod braille;
34mod navigate;
35mod prefs;
36mod tts;
37mod xpath_functions;
38mod definitions;
39pub mod pretty_print;
40mod chemistry;
41
42pub mod shim_filesystem; pub use interface::*;
44
45#[cfg(test)]
46pub fn init_logger() {
47 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("debug"))
48 .is_test(true)
49 .format_timestamp(None)
50 .format_module_path(false)
51 .format_indent(None)
52 .format_level(false)
53 .init();
54}
55
56pub fn abs_rules_dir_path() -> String {
58 cfg_if::cfg_if! {
59 if #[cfg(feature = "include-zip")] {
60 return "Rules".to_string();
61 } else {
62 return std::env::current_exe().unwrap().parent().unwrap()
63 .join("../../../Rules")
64 .to_str().unwrap().to_string();
65 }
66 }
67}
68
69pub fn are_strs_canonically_equal_with_locale(test: &str, target: &str, ignore_attrs: &[&str], block_separators: &str, decimal_separators: &str) -> bool {
70 use crate::{interface::*, pretty_print::mml_to_string};
71 use sxd_document::parser;
72 use crate::canonicalize::canonicalize;
73 crate::interface::set_rules_dir(abs_rules_dir_path()).unwrap();
75 crate::speech::SPEECH_RULES.with(|rules| rules.borrow_mut().read_files().unwrap());
76 set_preference("Language", "en").unwrap();
77 set_preference("BlockSeparators", block_separators).unwrap();
78 set_preference("DecimalSeparators", decimal_separators).unwrap();
79
80 let package1 = &parser::parse(test).expect("Failed to parse test input");
81 let mathml = get_element(package1);
82 trim_element(mathml, false);
83 let mathml_test = canonicalize(mathml).unwrap();
85
86 let package2 = &parser::parse(target).expect("Failed to parse target input");
87 let mathml_target = get_element(package2);
88 trim_element(mathml_target, false);
89 match is_same_element(mathml_test, mathml_target, ignore_attrs) {
92 Ok(_) => return true,
93 Err(e) => panic!("{}\nResult:\n{}\nTarget:\n{}", e, mml_to_string(mathml_test), mml_to_string(mathml_target)),
94 }
95}
96
97pub fn are_strs_canonically_equal(test: &str, target: &str, ignore_attrs: &[&str]) -> bool {
99 return are_strs_canonically_equal_with_locale(test, target, ignore_attrs, ", \u{00A0}\u{202F}", ".");
100}