variable export and entire config system

This commit is contained in:
Aidan Hahn 2021-11-07 22:04:57 -08:00
parent 0931fbdcf0
commit 307101327c
No known key found for this signature in database
GPG key ID: 327711E983899316
10 changed files with 184 additions and 21 deletions

View file

@ -10,7 +10,7 @@ mod append_lib_tests {
let result = "(1 2 3)";
let vt = Rc::new(RefCell::new(VTable::new()));
let ft: Rc<RefCell<FTable>>;
match get_stdlib() {
match get_stdlib(vt.clone()) {
Ok(f) => ft = f,
Err(s) => {
ft = Rc::new(RefCell::new(FTable::new()));
@ -54,7 +54,7 @@ mod append_lib_tests {
let result = "(1 2 3)";
let vt = Rc::new(RefCell::new(VTable::new()));
let ft: Rc<RefCell<FTable>>;
match get_stdlib() {
match get_stdlib(vt.clone()) {
Ok(f) => ft = f,
Err(s) => {
ft = Rc::new(RefCell::new(FTable::new()));
@ -98,7 +98,7 @@ mod append_lib_tests {
let result = "()";
let vt = Rc::new(RefCell::new(VTable::new()));
let ft: Rc<RefCell<FTable>>;
match get_stdlib() {
match get_stdlib(vt.clone()) {
Ok(f) => ft = f,
Err(s) => {
ft = Rc::new(RefCell::new(FTable::new()));
@ -142,7 +142,7 @@ mod append_lib_tests {
let result = "('test' 1 2 3)";
let vt = Rc::new(RefCell::new(VTable::new()));
let ft: Rc<RefCell<FTable>>;
match get_stdlib() {
match get_stdlib(vt.clone()) {
Ok(f) => ft = f,
Err(s) => {
ft = Rc::new(RefCell::new(FTable::new()));

View file

@ -10,7 +10,7 @@ mod str_lib_tests {
let result = "test";
let vt = Rc::new(RefCell::new(VTable::new()));
let ft: Rc<RefCell<FTable>>;
match get_stdlib() {
match get_stdlib(vt.clone()) {
Ok(f) => ft = f,
Err(s) => {
ft = Rc::new(RefCell::new(FTable::new()));
@ -54,7 +54,7 @@ mod str_lib_tests {
let result = "test123";
let vt = Rc::new(RefCell::new(VTable::new()));
let ft: Rc<RefCell<FTable>>;
match get_stdlib() {
match get_stdlib(vt.clone()) {
Ok(f) => ft = f,
Err(s) => {
ft = Rc::new(RefCell::new(FTable::new()));
@ -98,7 +98,7 @@ mod str_lib_tests {
let result = "";
let vt = Rc::new(RefCell::new(VTable::new()));
let ft: Rc<RefCell<FTable>>;
match get_stdlib() {
match get_stdlib(vt.clone()) {
Ok(f) => ft = f,
Err(s) => {
ft = Rc::new(RefCell::new(FTable::new()));

69
tests/test_lib_vars.rs Normal file
View file

@ -0,0 +1,69 @@
mod var_lib_tests {
use relish::stdlib::{get_stdlib};
use relish::ast::{lex, eval, VTable, FTable, Ctr};
use std::rc::Rc;
use std::cell::RefCell;
#[test]
fn test_variable_export_and_lookup() {
let doc1 = "(export test 1)";
let doc2 = "(echo test)";
let result = "1";
let vt = Rc::new(RefCell::new(VTable::new()));
let ft: Rc<RefCell<FTable>>;
match get_stdlib(vt.clone()) {
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);
},
Ok(tree) => {
match eval(tree, vt.clone(), ft.clone(), false) {
Err(s) => {
println!("Couldnt eval {}: {}", doc2, s);
assert!(false);
},
Ok(ctr) => {
match ctr {
Ctr::None => assert!(true),
_ => assert!(false)
}
}
}
}
}
match lex(doc2.to_string()) {
Err(s) => {
println!("Couldnt lex {}: {}", doc2, s);
assert!(false);
},
Ok(tree) => {
match eval(tree, vt.clone(), ft.clone(), false) {
Err(s) => {
println!("Couldnt eval {}: {}", doc2, s);
assert!(false);
},
Ok(ctr) => {
match ctr {
Ctr::String(s) => assert_eq!(s, result),
_ => assert!(false)
}
}
}
}
}
}
}