diff --git a/core/src/stl.rs b/core/src/stl.rs
index c67fdf9..b405842 100644
--- a/core/src/stl.rs
+++ b/core/src/stl.rs
@@ -23,7 +23,6 @@ pub mod control;
pub mod decl;
pub mod math;
pub mod strings;
-pub mod 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);
boolean::add_bool_lib(syms);
math::add_math_lib(syms);
- file::add_file_lib(syms);
}
diff --git a/core/tests/test_lib_file.rs b/core/tests/test_lib_file.rs
deleted file mode 100644
index 729d5ad..0000000
--- a/core/tests/test_lib_file.rs
+++ /dev/null
@@ -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(),
- );
- }
-
-}
diff --git a/core/src/stl/file.rs b/shell/src/file.rs
similarity index 73%
rename from core/src/stl/file.rs
rename to shell/src/file.rs
index badb7f5..80208db 100644
--- a/core/src/stl/file.rs
+++ b/shell/src/file.rs
@@ -15,9 +15,11 @@
* along with this program. If not, see .
*/
-use crate::segment::{Ctr, Seg, Type};
-use crate::sym::{SymTable, Symbol, ValueType, Args};
-use crate::error::{Traceback, start_trace};
+use flesh::ast::{
+ start_trace, Ctr, Seg, Type, SymTable,
+ Symbol, ValueType, Args, Traceback,
+};
+
use std::io::Write;
use std::fs::{File, read_to_string, OpenOptions};
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(),
+ );
+ }
+}
diff --git a/shell/src/stl.rs b/shell/src/stl.rs
index 3f1669a..8638887 100644
--- a/shell/src/stl.rs
+++ b/shell/src/stl.rs
@@ -31,8 +31,10 @@ use crate::posix;
#[path = "window.rs"]
mod window;
-#[path = "store.rs"]
+#[path = "store.rs"]
mod store;
+#[path = "file.rs"]
+mod file;
pub const CONSOLE_XDIM_VNAME: &str = "_FLESH_WIDTH";
pub const CONSOLE_YDIM_VNAME: &str = "_FLESH_HEIGHT";
@@ -63,6 +65,7 @@ fn prompt_delimiter_default_callback(_: &Seg, _: &mut SymTable) -> Result