rustfmt
Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
parent
ecbc47d4fe
commit
bc09cb07b1
17 changed files with 236 additions and 217 deletions
|
|
@ -1,6 +1,6 @@
|
|||
mod eval_tests {
|
||||
use relish::ast::{eval, lex, SymTable};
|
||||
use relish::ast::{Args, Symbol, Ctr, Seg, ValueType, UserFn};
|
||||
use relish::ast::{Args, Ctr, Seg, Symbol, UserFn, ValueType};
|
||||
|
||||
#[test]
|
||||
fn eval_simple() {
|
||||
|
|
@ -58,11 +58,12 @@ mod eval_tests {
|
|||
name: String::from("echo"),
|
||||
args: Args::Lazy(1),
|
||||
conditional_branches: false,
|
||||
value: ValueType::FuncForm( UserFn {
|
||||
value: ValueType::FuncForm(UserFn {
|
||||
arg_syms: vec!["input".to_string()],
|
||||
ast: Box::new(Seg::from(
|
||||
Box::from(Ctr::Symbol("input".to_string())),
|
||||
Box::from(Ctr::None))),
|
||||
Box::from(Ctr::Symbol("input".to_string())),
|
||||
Box::from(Ctr::None),
|
||||
)),
|
||||
}),
|
||||
};
|
||||
|
||||
|
|
@ -93,15 +94,16 @@ mod eval_tests {
|
|||
let output = "('one' 'unwrap_me')";
|
||||
let mut syms = SymTable::new();
|
||||
|
||||
let test_external_func: Symbol = Symbol{
|
||||
let test_external_func: Symbol = Symbol {
|
||||
name: String::from("echo"),
|
||||
args: Args::Lazy(1),
|
||||
conditional_branches: false,
|
||||
value: ValueType::FuncForm( UserFn {
|
||||
value: ValueType::FuncForm(UserFn {
|
||||
arg_syms: vec!["input".to_string()],
|
||||
ast: Box::new(Seg::from(
|
||||
Box::from(Ctr::Symbol("input".to_string())),
|
||||
Box::from(Ctr::None))),
|
||||
Box::from(Ctr::Symbol("input".to_string())),
|
||||
Box::from(Ctr::None),
|
||||
)),
|
||||
}),
|
||||
};
|
||||
|
||||
|
|
@ -137,7 +139,7 @@ mod eval_tests {
|
|||
|
||||
Ok(initial_ast) => match eval(&initial_ast, &mut syms) {
|
||||
Err(e) => {
|
||||
assert_eq!(e,"error in call to undefined: undefined symbol: undefined")
|
||||
assert_eq!(e, "error in call to undefined: undefined symbol: undefined")
|
||||
}
|
||||
|
||||
Ok(reduced) => {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
mod func_tests {
|
||||
use std::rc::Rc;
|
||||
use relish::ast::lex;
|
||||
use relish::ast::{Args, Ctr, Seg, Symbol, ValueType};
|
||||
use relish::ast::{SymTable, Type, UserFn};
|
||||
use relish::ast::{Args, Symbol, Ctr, Seg, ValueType};
|
||||
use std::rc::Rc;
|
||||
|
||||
#[test]
|
||||
fn decl_and_call_internal_func() {
|
||||
|
|
@ -22,10 +22,7 @@ mod func_tests {
|
|||
},
|
||||
)),
|
||||
};
|
||||
let args = Seg::from(
|
||||
Box::new(Ctr::Bool(true)),
|
||||
Box::new(Ctr::None)
|
||||
);
|
||||
let args = Seg::from(Box::new(Ctr::Bool(true)), Box::new(Ctr::None));
|
||||
|
||||
syms.insert(String::from("test_func_in"), test_internal_func);
|
||||
|
||||
|
|
@ -53,7 +50,7 @@ mod func_tests {
|
|||
name: String::from("echo"),
|
||||
conditional_branches: false,
|
||||
args: Args::Lazy(1),
|
||||
value: ValueType::FuncForm(UserFn{
|
||||
value: ValueType::FuncForm(UserFn {
|
||||
arg_syms: vec!["input".to_string()],
|
||||
ast: finner,
|
||||
}),
|
||||
|
|
@ -61,7 +58,7 @@ mod func_tests {
|
|||
|
||||
let args = Seg::from(
|
||||
Box::new(Ctr::String("test".to_string())),
|
||||
Box::new(Ctr::None)
|
||||
Box::new(Ctr::None),
|
||||
);
|
||||
|
||||
syms.insert(String::from("test_func_in"), test_external_func);
|
||||
|
|
@ -89,11 +86,11 @@ mod func_tests {
|
|||
match lex(&"(input input)".to_string()) {
|
||||
Err(e) => panic!("{}", e),
|
||||
Ok(finner) => {
|
||||
let test_external_func: Symbol = Symbol{
|
||||
let test_external_func: Symbol = Symbol {
|
||||
name: String::from("echo_2"),
|
||||
conditional_branches: false,
|
||||
args: Args::Lazy(1),
|
||||
value: ValueType::FuncForm(UserFn{
|
||||
value: ValueType::FuncForm(UserFn {
|
||||
arg_syms: vec!["input".to_string()],
|
||||
ast: finner,
|
||||
}),
|
||||
|
|
@ -101,7 +98,7 @@ mod func_tests {
|
|||
|
||||
let args = Seg::from(
|
||||
Box::new(Ctr::String("test".to_string())),
|
||||
Box::new(Ctr::None)
|
||||
Box::new(Ctr::None),
|
||||
);
|
||||
|
||||
syms.insert(String::from("echo_2"), test_external_func);
|
||||
|
|
@ -147,16 +144,13 @@ mod func_tests {
|
|||
name: String::from("test_outer"),
|
||||
conditional_branches: false,
|
||||
args: Args::Lazy(1),
|
||||
value: ValueType::FuncForm(UserFn{
|
||||
value: ValueType::FuncForm(UserFn {
|
||||
arg_syms: vec!["input".to_string()],
|
||||
ast: finner,
|
||||
}),
|
||||
};
|
||||
|
||||
let args = Seg::from(
|
||||
Box::new(Ctr::Bool(true)),
|
||||
Box::new(Ctr::None)
|
||||
);
|
||||
let args = Seg::from(Box::new(Ctr::Bool(true)), Box::new(Ctr::None));
|
||||
|
||||
syms.insert(String::from("test_inner"), inner_func);
|
||||
syms.insert(String::from("test_outer"), outer_func);
|
||||
|
|
@ -196,10 +190,7 @@ mod func_tests {
|
|||
},
|
||||
)),
|
||||
};
|
||||
let args = Seg::from(
|
||||
Box::new(Ctr::Integer(1)),
|
||||
Box::new(Ctr::None)
|
||||
);
|
||||
let args = Seg::from(Box::new(Ctr::Integer(1)), Box::new(Ctr::None));
|
||||
|
||||
syms.insert(String::from("test_func_in"), test_internal_func);
|
||||
|
||||
|
|
@ -221,7 +212,7 @@ mod func_tests {
|
|||
name: String::from("echo"),
|
||||
conditional_branches: false,
|
||||
args: Args::Lazy(1),
|
||||
value: ValueType::FuncForm(UserFn{
|
||||
value: ValueType::FuncForm(UserFn {
|
||||
arg_syms: vec!["input".to_string()],
|
||||
ast: finner,
|
||||
}),
|
||||
|
|
@ -229,7 +220,7 @@ mod func_tests {
|
|||
|
||||
let args = Seg::from(
|
||||
Box::new(Ctr::String("test".to_string())),
|
||||
Box::new(Ctr::Seg(Seg::from_mono(Box::new(Ctr::Integer(1)))))
|
||||
Box::new(Ctr::Seg(Seg::from_mono(Box::new(Ctr::Integer(1))))),
|
||||
);
|
||||
|
||||
syms.insert(String::from("test_func_in"), test_external_func);
|
||||
|
|
@ -254,7 +245,7 @@ mod func_tests {
|
|||
name: String::from("echo"),
|
||||
conditional_branches: false,
|
||||
args: Args::Lazy(1),
|
||||
value: ValueType::FuncForm(UserFn{
|
||||
value: ValueType::FuncForm(UserFn {
|
||||
arg_syms: vec!["input".to_string()],
|
||||
ast: finner,
|
||||
}),
|
||||
|
|
@ -293,13 +284,16 @@ mod func_tests {
|
|||
};
|
||||
let args = Seg::from(
|
||||
Box::new(Ctr::Symbol("undefined-symbol".to_string())),
|
||||
Box::new(Ctr::None)
|
||||
Box::new(Ctr::None),
|
||||
);
|
||||
|
||||
syms.insert(String::from("test_func_in"), test_internal_func);
|
||||
|
||||
if let Err(s) = syms.call_symbol(&"test_func_in".to_string(), &args, true) {
|
||||
assert_eq!(s, "error in call to undefined-symbol: undefined symbol: undefined-symbol");
|
||||
assert_eq!(
|
||||
s,
|
||||
"error in call to undefined-symbol: undefined symbol: undefined-symbol"
|
||||
);
|
||||
} else {
|
||||
print!("call to function succeeded (shouldnt have)");
|
||||
assert!(false);
|
||||
|
|
|
|||
|
|
@ -133,7 +133,8 @@ mod lex_tests {
|
|||
|
||||
#[test]
|
||||
fn test_postline_comment() {
|
||||
let document = String::from("#!/bin/relish\n((one two)# another doc comment\n(three four))");
|
||||
let document =
|
||||
String::from("#!/bin/relish\n((one two)# another doc comment\n(three four))");
|
||||
let output: &str = "((one two) (three four))";
|
||||
match lex(&document) {
|
||||
Ok(tree) => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
mod append_lib_tests {
|
||||
use relish::ast::{Ctr, eval, lex, SymTable};
|
||||
use relish::stdlib::{static_stdlib, dynamic_stdlib};
|
||||
use relish::ast::{eval, lex, Ctr, SymTable};
|
||||
use relish::stdlib::{dynamic_stdlib, static_stdlib};
|
||||
|
||||
#[test]
|
||||
fn test_append_to_empty_list() {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
mod control_lib_tests {
|
||||
use relish::ast::{Ctr, eval, lex, SymTable};
|
||||
use relish::stdlib::{static_stdlib, dynamic_stdlib};
|
||||
use relish::ast::{eval, lex, Ctr, SymTable};
|
||||
use relish::stdlib::{dynamic_stdlib, static_stdlib};
|
||||
|
||||
#[test]
|
||||
fn test_if_first_case_singlet() {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
mod var_lib_tests {
|
||||
use relish::ast::{eval, lex, SymTable, Ctr};
|
||||
use relish::stdlib::{static_stdlib, dynamic_stdlib};
|
||||
use relish::ast::{eval, lex, Ctr, SymTable};
|
||||
use relish::stdlib::{dynamic_stdlib, static_stdlib};
|
||||
|
||||
#[test]
|
||||
fn test_variable_def_and_lookup() {
|
||||
|
|
@ -134,7 +134,10 @@ mod var_lib_tests {
|
|||
println!("tree: {tree}");
|
||||
let eval_result = eval(&tree, &mut syms);
|
||||
if let Err(s) = eval_result {
|
||||
assert_eq!(s.to_string(), "error in call to test: undefined symbol: test".to_string());
|
||||
assert_eq!(
|
||||
s.to_string(),
|
||||
"error in call to test: undefined symbol: test".to_string()
|
||||
);
|
||||
} else {
|
||||
let res = eval_result.unwrap();
|
||||
eprintln!("shouldn't have suceeded: {res}");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue