Big project dir refactor
* split into multi member workspace in preparation for a no_std core * env and posix stuff neatly crammed into a seperate shell project * some pokes at interactive-devel.f * updated ci * removed 'l' shortcut for 'load' and update docs * remove out of date readme content * updated tests * more sensible cond implementation and extra tests * substr stdlib function with tests Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit is contained in:
parent
aa56570d7d
commit
6d2925984f
44 changed files with 967 additions and 779 deletions
|
|
@ -1,229 +0,0 @@
|
|||
mod str_lib_tests {
|
||||
use flesh::ast::{eval, lex, SymTable};
|
||||
use flesh::stdlib::{dynamic_stdlib, static_stdlib};
|
||||
|
||||
#[test]
|
||||
fn test_simple_concat() {
|
||||
let document = "(concat 'test')";
|
||||
let result = "'test'";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
dynamic_stdlib(&mut syms, None);
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_poly_concat() {
|
||||
let document = "(concat 'test' 1 2 3)";
|
||||
let result = "'test123'";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
dynamic_stdlib(&mut syms, None);
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty_concat() {
|
||||
let document = "(concat)";
|
||||
let result = "''";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
dynamic_stdlib(&mut syms, None);
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_strlen_str() {
|
||||
let document = "(strlen 'test')";
|
||||
let result = 4;
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
dynamic_stdlib(&mut syms, None);
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_strlen_int() {
|
||||
let document = "(strlen 1000)";
|
||||
let result = 4;
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
dynamic_stdlib(&mut syms, None);
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_strlen_float() {
|
||||
let document = "(strlen 10.2)";
|
||||
let result = 4;
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
dynamic_stdlib(&mut syms, None);
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_strlen_seg() {
|
||||
let document = "(strlen (1 2 3))";
|
||||
let result = 7;
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
dynamic_stdlib(&mut syms, None);
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_strlen_bool() {
|
||||
let document = "(strlen true)";
|
||||
let result = 4;
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
dynamic_stdlib(&mut syms, None);
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_strcast_i() {
|
||||
let document = "(string 4)";
|
||||
let result = "'4'";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
dynamic_stdlib(&mut syms, None);
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_strcast_seg() {
|
||||
let document = "(string (1 2 3))";
|
||||
let result = "'(1 2 3)'";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
dynamic_stdlib(&mut syms, None);
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_contains() {
|
||||
let document = "(substr? 'bigger' 'ger')";
|
||||
let result = "true";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
dynamic_stdlib(&mut syms, None);
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_doesnt_contain() {
|
||||
let document = "(substr? 'smaller' 'ger')";
|
||||
let result = "false";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
dynamic_stdlib(&mut syms, None);
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_split() {
|
||||
let document = "(split 'one.two.three' '.')";
|
||||
let result = "('one' 'two' 'three')";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
dynamic_stdlib(&mut syms, None);
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_split_big_delim() {
|
||||
let document = "(split 'one:d:two:d:three' ':d:')";
|
||||
let result = "('one' 'two' 'three')";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
dynamic_stdlib(&mut syms, None);
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_splitnt() {
|
||||
let document = "(split 'one.two.three' '-')";
|
||||
let result = "('one.two.three')";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
dynamic_stdlib(&mut syms, None);
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue