use std::collections::HashMap;
use starlark_syntax::syntax::AstModule;
use starlark_syntax::syntax::Dialect;
use crate::environment::Globals;
use crate::environment::Module;
use crate::eval::Evaluator;
#[test]
fn test_replace_binary() {
let mut ast = AstModule::parse(
"file.sky",
r#"
def equals(a, b):
return "(" + str(a) + " == " + str(b) + ")"
def my_subtract(a, b):
return "(" + str(a) + " - " + str(b) + ")"
(7 + 8) - 9 == True
"#
.to_owned(),
&Dialect::Standard,
)
.unwrap();
ast.replace_binary_operators(&HashMap::from([
("==".to_owned(), "equals".to_owned()),
("-".to_owned(), "my_subtract".to_owned()),
]));
let module = Module::new();
let mut eval = Evaluator::new(&module);
let v = eval.eval_module(ast, &Globals::standard()).unwrap();
assert_eq!(v.unpack_str().unwrap(), "((15 - 9) == True)");
}