From 34e77903a621d41641244ff9e65e29db92476791 Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Fri, 17 Mar 2023 13:24:31 -0700 Subject: [PATCH] Add userlib tests Document userlib in readme extend example configuration to include userlib --- Readme.org | 20 +++++++---- snippets/basic_minimal_configuration.rls | 9 +++-- snippets/userlib-tests.rls | 43 ++++++++++++++++++++++++ snippets/userlib.rls | 2 +- src/stl/control.rs | 1 - 5 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 snippets/userlib-tests.rls diff --git a/Readme.org b/Readme.org index e591d71..ef88cc1 100644 --- a/Readme.org +++ b/Readme.org @@ -174,11 +174,13 @@ To be specific, typing ~(a)~ usually results in a symbol lookup for ~a~, and the #+BEGIN_SRC lisp (quote a) ;; returns the symbol a (quote (add 1 2)) ;; returns the following tree: (add 1 2) + (q a) ;; returns the symbol a #+END_SRC +(note that ~quote~ may be shortened to ~q~) We can use this to build structures that evaluate into new data: #+BEGIN_SRC lisp - (let ((mylist (quote (add))) ;; store a list starting with the add function + (let ((mylist (q (add))) ;; store a list starting with the add function (myiter 0)) ;; store an iterator starting at 0 (while (lt? myiter 4) ;; loop until the iterator >= 4 (inc myiter) ;; increment the iterator @@ -316,6 +318,10 @@ Within it are several examples that the authors and maintainers wanted to keep a It is sort of like a lint roller. It also contains considerably subpar implementations of Relish's internals that are kept around for historical reasons. +*** Userlib +The *Userlib* was added as a script containing many valuable functions such as ~set~ and ~prepend~. +You can use it by loading it in your shell config (See file:snippets/basic_minimal_configuration.rls for more info). + ** Easy patterns This section contains examples of common composites of control flow that can be used to build more complex or effective applications More ideas may be explored in the file:snippets directory of this project. @@ -470,14 +476,15 @@ This contains any executable target of this project. Notably the main shell file Note: this section will not show the status of each item unless you are viewing it with a proper orgmode viewer. Note: this section only tracks the state of incomplete TODO items. Having everything on here would be cluttered. -*** TODO Shell prompt is fully configurable (L, R, and Delim) +*** TODO Shell prompt is fully configurable (History, L, R, and Delim) *** TODO Load (load a script) function Pull/Refactor the logic out of the configure functions. Optionally return a list of new variables and/or functions? Will need a concatenate function for tables -*** TODO not-builtin set function -*** TODO not-builtin list contains +*** TODO userlib list contains +*** TODO Extend userlib tests *** TODO Main shell calls Load function on arg and exits +*** TODO Add userlib tests to CI *** TODO Input function *** TODO Lex function *** TODO Read function (Input + Lex) @@ -501,11 +508,12 @@ Overload Load function to call a binary too *** TODO Custom ast pretty print *** TODO Implement Compose for lambdas DOCUMENT AS WELL -*** TODO non built in Map function -*** TODO non built in Reduce function +*** TODO userlib Map function +*** TODO userlib Reduce function *** TODO file operations **** TODO read-to-string **** TODO write-to-file +*** TODO color control library *** TODO Network library **** TODO HTTP Client **** TODO TCP Stream client diff --git a/snippets/basic_minimal_configuration.rls b/snippets/basic_minimal_configuration.rls index 6f2255c..0837ed7 100644 --- a/snippets/basic_minimal_configuration.rls +++ b/snippets/basic_minimal_configuration.rls @@ -1,9 +1,12 @@ ;; comment out to load USERLIB ;; (load (concat HOME "/.relish/userlib.rls")) -(def CFG_RELISH_POSIX - "my job control preference" - "1") +;; if you have userlib +;; (set CFG_RELISH_POSIX "1") +;; else +(def CFG_RELISH_POSIX + (get-doc (q CFG_RELISH_POSIX)) + "1") (echo "Welcome back to relish.") (echo "Enjoy your computing.") diff --git a/snippets/userlib-tests.rls b/snippets/userlib-tests.rls new file mode 100644 index 0000000..e8b9002 --- /dev/null +++ b/snippets/userlib-tests.rls @@ -0,0 +1,43 @@ +;; this file implements unit tests for handwritten userlib functions + +(def passed +'prints if a test has passed' + (test) + (echo (concat "PASSED: " test))) + +(def failed +'prints if a test has failed' + (test) + (echo (concat "FAILED: " test))) + +(def test-cases 'all test cases' + (('set updates var' + (quote + (let ((test-val 0)) + (set test-val 3) + (eq? test-val 3)))) + ('prepend prepends to list' + (quote + (let ((list (2 3 4)) + (list (prepend 1 list)) + (list-head (head list))) + (eq? (car list-head) 1)))) + + ;; add more test cases here + )) + + +(def test-iter 'iterates over test cases' + (head test-cases)) + +;; run all test cases, print output +(while (gt? (len (cdr test-iter)) + 0) + (let ((test (car test-iter)) + (remaining (cdr test-iter)) + (test-name (car test)) + (test-body (cdr test))) + (if (eval test-body) + (passed test-name) + (failed test-name)) + (def test-iter '' (head remaining)))) \ No newline at end of file diff --git a/snippets/userlib.rls b/snippets/userlib.rls index 1e58d88..bdf8303 100644 --- a/snippets/userlib.rls +++ b/snippets/userlib.rls @@ -13,7 +13,7 @@ ;; ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . -;; + ;; USERLIB ;; This file contains a plethora of useful features that are not shipped in the STL diff --git a/src/stl/control.rs b/src/stl/control.rs index 3ceee80..2bcef89 100644 --- a/src/stl/control.rs +++ b/src/stl/control.rs @@ -31,7 +31,6 @@ example: (if my-state-switch pub fn if_callback(ast: &Seg, syms: &mut SymTable) -> Result { let cond: bool; - println!("Y: {}", *ast.car); match *ast.car { Ctr::Seg(ref cond_form) => { if let Ctr::Bool(cond_from_eval) = *eval(cond_form, syms)? {