1#![recursion_limit = "1024"]
18
19#[macro_use]
20extern crate error_chain;
21
22pub mod errors {
26    error_chain! {
28        }
33}
34
35#[macro_use]
36extern crate lazy_static;
37
38#[macro_use]
39extern crate bitflags;
40
41#[macro_use]
42extern crate log;
43
44#[macro_use]
45extern crate cfg_if;
46
47
48pub mod interface;
49#[cfg(feature = "include-zip")]
50pub use shim_filesystem::ZIPPED_RULE_FILES;
51
52mod canonicalize;
53mod infer_intent;
54pub mod speech;
55mod braille;
56mod navigate;
57mod prefs;
58mod tts;
59mod xpath_functions;
60mod definitions;
61pub mod pretty_print;
62mod chemistry;
63
64pub mod shim_filesystem; pub use interface::*;
66
67#[cfg(test)]
68pub fn init_logger() {
69    env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("debug"))
70        .is_test(true)
71        .format_timestamp(None)
72        .format_module_path(false)
73        .format_indent(None)
74        .format_level(false)
75        .init();
76}
77
78#[cfg(test)]
79pub fn abs_rules_dir_path() -> String {
81    cfg_if::cfg_if! {
82    if #[cfg(feature = "include-zip")] {
83          return "Rules".to_string();
84    } else {
85        return std::env::current_exe().unwrap().parent().unwrap()
86                    .join("../../../Rules")
87                    .to_str().unwrap().to_string();
88        }
89    }
90}
91
92#[cfg(test)]
93pub fn are_strs_canonically_equal_with_locale(test: &str, target: &str, block_separators: &str, decimal_separators: &str) -> bool {
94    use crate::{interface::*, pretty_print::mml_to_string};
95    use sxd_document::parser;
96    use crate::canonicalize::canonicalize;
97    crate::interface::set_rules_dir(abs_rules_dir_path()).unwrap();
99    crate::speech::SPEECH_RULES.with(|rules|  rules.borrow_mut().read_files().unwrap());
100    set_preference("Language".to_string(), "en".to_string()).unwrap();
101    set_preference("BlockSeparators".to_string(), block_separators.to_string()).unwrap();
102    set_preference("DecimalSeparators".to_string(), decimal_separators.to_string()).unwrap();
103    
104    let package1 = &parser::parse(test).expect("Failed to parse test input");
105    let mathml = get_element(package1);
106    trim_element(mathml, false);
107    let mathml_test = canonicalize(mathml).unwrap();
109   
110    let package2 = &parser::parse(target).expect("Failed to parse target input");
111    let mathml_target = get_element(package2);
112    trim_element(mathml_target, false);
113    match is_same_element(mathml_test, mathml_target) {
116        Ok(_) => return true,
117        Err(e) => panic!("{}\nResult:\n{}\nTarget:\n{}", e, mml_to_string(mathml_test), mml_to_string(mathml_target)),
118    }
119}
120
121#[cfg(test)]
122pub fn are_strs_canonically_equal(test: &str, target: &str) -> bool {
124    return are_strs_canonically_equal_with_locale(test, target, ", \u{00A0}\u{202F}", ".");
125}
126