File operations
* read * write * append * exists? * tests for each
This commit is contained in:
parent
25db2aac47
commit
64be70b3af
5 changed files with 261 additions and 6 deletions
80
tests/test_lib_file.rs
Normal file
80
tests/test_lib_file.rs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
mod file_lib_tests {
|
||||
use relish::ast::{eval, lex, SymTable};
|
||||
use relish::stdlib::{dynamic_stdlib, static_stdlib};
|
||||
|
||||
#[test]
|
||||
fn test_fexists() {
|
||||
let document = "(exists? '/tmp')";
|
||||
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_fexists_doesnt() {
|
||||
let document = "(exists? 'cargo.timtam')";
|
||||
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_write_file() {
|
||||
let document = "
|
||||
(let ((s 'test')
|
||||
(t '/tmp/relish-lib-test-file-1'))
|
||||
(write-file t s)
|
||||
(echo (read-file t))
|
||||
(eq? (read-file t) s))";
|
||||
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_append_file() {
|
||||
let document = "
|
||||
(let ((s 'test')
|
||||
(t '/tmp/relish-lib-test-file-2'))
|
||||
(write-file t s)
|
||||
(append-file t s)
|
||||
(eq? (read-file t)
|
||||
(concat s s)))";
|
||||
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(),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue