Move File module and tests to the shell project
Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit is contained in:
parent
6d2925984f
commit
74f73fb493
4 changed files with 87 additions and 82 deletions
|
|
@ -23,7 +23,6 @@ pub mod control;
|
||||||
pub mod decl;
|
pub mod decl;
|
||||||
pub mod math;
|
pub mod math;
|
||||||
pub mod strings;
|
pub mod strings;
|
||||||
pub mod file;
|
|
||||||
|
|
||||||
pub const CFG_FILE_VNAME: &str = "FLESH_CFG_FILE";
|
pub const CFG_FILE_VNAME: &str = "FLESH_CFG_FILE";
|
||||||
|
|
||||||
|
|
@ -37,5 +36,4 @@ pub fn static_stdlib(syms: &mut SymTable) {
|
||||||
control::add_control_lib(syms);
|
control::add_control_lib(syms);
|
||||||
boolean::add_bool_lib(syms);
|
boolean::add_bool_lib(syms);
|
||||||
math::add_math_lib(syms);
|
math::add_math_lib(syms);
|
||||||
file::add_file_lib(syms);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,76 +0,0 @@
|
||||||
mod file_lib_tests {
|
|
||||||
use flesh::ast::{eval, lex, SymTable};
|
|
||||||
use flesh::stdlib::static_stdlib;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_fexists() {
|
|
||||||
let document = "(exists? \"/tmp\")";
|
|
||||||
let result = "true";
|
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
|
||||||
static_stdlib(&mut syms);
|
|
||||||
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);
|
|
||||||
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/flesh-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);
|
|
||||||
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/flesh-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);
|
|
||||||
assert_eq!(
|
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
||||||
.unwrap()
|
|
||||||
.to_string(),
|
|
||||||
result.to_string(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -15,9 +15,11 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::segment::{Ctr, Seg, Type};
|
use flesh::ast::{
|
||||||
use crate::sym::{SymTable, Symbol, ValueType, Args};
|
start_trace, Ctr, Seg, Type, SymTable,
|
||||||
use crate::error::{Traceback, start_trace};
|
Symbol, ValueType, Args, Traceback,
|
||||||
|
};
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::fs::{File, read_to_string, OpenOptions};
|
use std::fs::{File, read_to_string, OpenOptions};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
@ -170,3 +172,81 @@ pub fn add_file_lib(syms: &mut SymTable) {
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use flesh::ast::{eval, lex, SymTable};
|
||||||
|
use flesh::stdlib::static_stdlib;
|
||||||
|
use crate::stl::static_stdlib_overwrites;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_fexists() {
|
||||||
|
let document = "(exists? \"/tmp\")";
|
||||||
|
let result = "true";
|
||||||
|
let mut syms = SymTable::new();
|
||||||
|
static_stdlib(&mut syms);
|
||||||
|
static_stdlib_overwrites(&mut syms);
|
||||||
|
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);
|
||||||
|
static_stdlib_overwrites(&mut syms);
|
||||||
|
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/flesh-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);
|
||||||
|
static_stdlib_overwrites(&mut syms);
|
||||||
|
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/flesh-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);
|
||||||
|
static_stdlib_overwrites(&mut syms);
|
||||||
|
assert_eq!(
|
||||||
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
|
.unwrap()
|
||||||
|
.to_string(),
|
||||||
|
result.to_string(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -31,8 +31,10 @@ use crate::posix;
|
||||||
|
|
||||||
#[path = "window.rs"]
|
#[path = "window.rs"]
|
||||||
mod window;
|
mod window;
|
||||||
#[path = "store.rs"]
|
#[path = "store.rs"]
|
||||||
mod store;
|
mod store;
|
||||||
|
#[path = "file.rs"]
|
||||||
|
mod file;
|
||||||
|
|
||||||
pub const CONSOLE_XDIM_VNAME: &str = "_FLESH_WIDTH";
|
pub const CONSOLE_XDIM_VNAME: &str = "_FLESH_WIDTH";
|
||||||
pub const CONSOLE_YDIM_VNAME: &str = "_FLESH_HEIGHT";
|
pub const CONSOLE_YDIM_VNAME: &str = "_FLESH_HEIGHT";
|
||||||
|
|
@ -63,6 +65,7 @@ fn prompt_delimiter_default_callback(_: &Seg, _: &mut SymTable) -> Result<Ctr, T
|
||||||
pub fn static_stdlib_overwrites(syms: &mut SymTable) {
|
pub fn static_stdlib_overwrites(syms: &mut SymTable) {
|
||||||
static_stdlib(syms);
|
static_stdlib(syms);
|
||||||
window::add_window_lib_funcs(syms);
|
window::add_window_lib_funcs(syms);
|
||||||
|
file::add_file_lib(syms);
|
||||||
|
|
||||||
syms.insert(
|
syms.insert(
|
||||||
"call".to_string(),
|
"call".to_string(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue