2023-03-24 18:14:33 -07:00
|
|
|
mod posix_tests {
|
2024-02-06 22:39:08 +00:00
|
|
|
use flesh::aux::args_from_ast;
|
|
|
|
|
use flesh::stdlib::{dynamic_stdlib, static_stdlib};
|
|
|
|
|
use flesh::ast::{lex, eval, SymTable};
|
2023-03-24 18:14:33 -07:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_cmd_singlet() {
|
|
|
|
|
let document = "(binary)";
|
|
|
|
|
let result = vec!["binary"];
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
|
|
|
|
dynamic_stdlib(&mut syms, None);
|
2023-03-24 18:14:33 -07:00
|
|
|
|
|
|
|
|
if let Ok(ref s) = lex(&document.to_string()) {
|
|
|
|
|
assert_eq!(
|
|
|
|
|
args_from_ast(s, &mut syms),
|
|
|
|
|
result
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_cmd_list() {
|
|
|
|
|
let document = "(binary --flag=1 122 'yeet' true)";
|
|
|
|
|
let result = vec!["binary", "--flag=1", "122", "yeet", "true"];
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
|
|
|
|
dynamic_stdlib(&mut syms, None);
|
2023-03-24 18:14:33 -07:00
|
|
|
|
|
|
|
|
if let Ok(ref s) = lex(&document.to_string()) {
|
|
|
|
|
assert_eq!(
|
|
|
|
|
args_from_ast(s, &mut syms),
|
|
|
|
|
result
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_cmd_syms_undef() {
|
|
|
|
|
let document = "(binary --flag=1 122 'yeet' true syms)";
|
|
|
|
|
let result = vec!["binary", "--flag=1", "122", "yeet", "true", "syms"];
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
|
|
|
|
dynamic_stdlib(&mut syms, None);
|
2023-03-24 18:14:33 -07:00
|
|
|
|
|
|
|
|
if let Ok(ref s) = lex(&document.to_string()) {
|
|
|
|
|
assert_eq!(
|
|
|
|
|
args_from_ast(s, &mut syms),
|
|
|
|
|
result
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_cmd_syms_unwrap_simple() {
|
|
|
|
|
let decl = "(def syms '' 1)";
|
|
|
|
|
let document = "(binary --flag=1 122 'yeet' true syms)";
|
|
|
|
|
let result = vec!["binary", "--flag=1", "122", "yeet", "true", "1"];
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
|
|
|
|
dynamic_stdlib(&mut syms, None);
|
2023-03-24 18:14:33 -07:00
|
|
|
|
|
|
|
|
eval(&lex(&decl.to_string()).unwrap(), &mut syms).unwrap();
|
|
|
|
|
|
|
|
|
|
if let Ok(ref s) = lex(&document.to_string()) {
|
|
|
|
|
assert_eq!(
|
|
|
|
|
args_from_ast(s, &mut syms),
|
|
|
|
|
result
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_cmd_syms_unwrap_eval() {
|
|
|
|
|
let document = "(binary --flag=1 122 'yeet' true (add 1 2))";
|
|
|
|
|
let result = vec!["binary", "--flag=1", "122", "yeet", "true", "3"];
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
|
|
|
|
dynamic_stdlib(&mut syms, None);
|
2023-03-24 18:14:33 -07:00
|
|
|
|
|
|
|
|
if let Ok(ref s) = lex(&document.to_string()) {
|
|
|
|
|
assert_eq!(
|
|
|
|
|
args_from_ast(s, &mut syms),
|
|
|
|
|
result
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|