flesh/tests/test_lib_vars.rs

65 lines
1.9 KiB
Rust
Raw Normal View History

mod var_lib_tests {
2022-01-16 22:02:40 -08:00
use relish::ast::{eval, lex, Ctr, FTable, VTable};
use relish::stdlib::get_stdlib;
2021-11-06 15:43:42 -07:00
use std::cell::RefCell;
2022-01-16 22:02:40 -08:00
use std::rc::Rc;
2021-11-06 15:43:42 -07:00
#[test]
fn test_variable_export_and_lookup() {
let doc1 = "(export test 1)";
2021-11-08 00:45:09 -08:00
let doc2 = "(concat test)";
2021-11-06 15:43:42 -07:00
let result = "1";
let vt = Rc::new(RefCell::new(VTable::new()));
let ft: Rc<RefCell<FTable>>;
match get_stdlib(vt.clone()) {
2021-11-06 15:43:42 -07:00
Ok(f) => ft = f,
Err(s) => {
ft = Rc::new(RefCell::new(FTable::new()));
println!("Couldnt get stdlib: {}!", s);
assert!(false);
}
}
match lex(doc1.to_string()) {
Err(s) => {
println!("Couldnt lex {}: {}", doc1, s);
assert!(false);
2022-01-16 22:02:40 -08:00
}
2021-11-06 15:43:42 -07:00
2022-01-16 22:02:40 -08:00
Ok(tree) => match eval(tree, vt.clone(), ft.clone(), false) {
Err(s) => {
println!("Couldnt eval {}: {}", doc2, s);
assert!(false);
}
2021-11-06 15:43:42 -07:00
2022-01-16 22:02:40 -08:00
Ok(ctr) => {
println!("{:#?}", vt);
match ctr {
Ctr::None => assert!(true),
_ => assert!(false),
2021-11-06 15:43:42 -07:00
}
}
2022-01-16 22:02:40 -08:00
},
2021-11-06 15:43:42 -07:00
}
match lex(doc2.to_string()) {
Err(s) => {
println!("Couldnt lex {}: {}", doc2, s);
assert!(false);
2022-01-16 22:02:40 -08:00
}
2021-11-06 15:43:42 -07:00
2022-01-16 22:02:40 -08:00
Ok(tree) => match eval(tree, vt.clone(), ft.clone(), false) {
Err(s) => {
println!("Couldnt eval {}: {}", doc2, s);
assert!(false);
2021-11-06 15:43:42 -07:00
}
2022-01-16 22:02:40 -08:00
Ok(ctr) => match ctr {
Ctr::String(s) => assert_eq!(s, result),
_ => assert!(false),
},
},
2021-11-06 15:43:42 -07:00
}
}
}