Add userlib tests
Document userlib in readme extend example configuration to include userlib
This commit is contained in:
parent
1ee9ba55fb
commit
34e77903a6
5 changed files with 64 additions and 11 deletions
20
Readme.org
20
Readme.org
|
|
@ -174,11 +174,13 @@ To be specific, typing ~(a)~ usually results in a symbol lookup for ~a~, and the
|
||||||
#+BEGIN_SRC lisp
|
#+BEGIN_SRC lisp
|
||||||
(quote a) ;; returns the symbol a
|
(quote a) ;; returns the symbol a
|
||||||
(quote (add 1 2)) ;; returns the following tree: (add 1 2)
|
(quote (add 1 2)) ;; returns the following tree: (add 1 2)
|
||||||
|
(q a) ;; returns the symbol a
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
(note that ~quote~ may be shortened to ~q~)
|
||||||
|
|
||||||
We can use this to build structures that evaluate into new data:
|
We can use this to build structures that evaluate into new data:
|
||||||
#+BEGIN_SRC lisp
|
#+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
|
(myiter 0)) ;; store an iterator starting at 0
|
||||||
(while (lt? myiter 4) ;; loop until the iterator >= 4
|
(while (lt? myiter 4) ;; loop until the iterator >= 4
|
||||||
(inc myiter) ;; increment the iterator
|
(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 is sort of like a lint roller.
|
||||||
It also contains considerably subpar implementations of Relish's internals that are kept around for historical reasons.
|
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
|
** Easy patterns
|
||||||
This section contains examples of common composites of control flow that can be used to build more complex or effective applications
|
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.
|
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 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.
|
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
|
*** TODO Load (load a script) function
|
||||||
Pull/Refactor the logic out of the configure functions.
|
Pull/Refactor the logic out of the configure functions.
|
||||||
Optionally return a list of new variables and/or functions?
|
Optionally return a list of new variables and/or functions?
|
||||||
Will need a concatenate function for tables
|
Will need a concatenate function for tables
|
||||||
*** TODO not-builtin set function
|
*** TODO userlib list contains
|
||||||
*** TODO not-builtin list contains
|
*** TODO Extend userlib tests
|
||||||
*** TODO Main shell calls Load function on arg and exits
|
*** TODO Main shell calls Load function on arg and exits
|
||||||
|
*** TODO Add userlib tests to CI
|
||||||
*** TODO Input function
|
*** TODO Input function
|
||||||
*** TODO Lex function
|
*** TODO Lex function
|
||||||
*** TODO Read function (Input + Lex)
|
*** TODO Read function (Input + Lex)
|
||||||
|
|
@ -501,11 +508,12 @@ Overload Load function to call a binary too
|
||||||
*** TODO Custom ast pretty print
|
*** TODO Custom ast pretty print
|
||||||
*** TODO Implement Compose for lambdas
|
*** TODO Implement Compose for lambdas
|
||||||
DOCUMENT AS WELL
|
DOCUMENT AS WELL
|
||||||
*** TODO non built in Map function
|
*** TODO userlib Map function
|
||||||
*** TODO non built in Reduce function
|
*** TODO userlib Reduce function
|
||||||
*** TODO file operations
|
*** TODO file operations
|
||||||
**** TODO read-to-string
|
**** TODO read-to-string
|
||||||
**** TODO write-to-file
|
**** TODO write-to-file
|
||||||
|
*** TODO color control library
|
||||||
*** TODO Network library
|
*** TODO Network library
|
||||||
**** TODO HTTP Client
|
**** TODO HTTP Client
|
||||||
**** TODO TCP Stream client
|
**** TODO TCP Stream client
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
;; comment out to load USERLIB
|
;; comment out to load USERLIB
|
||||||
;; (load (concat HOME "/.relish/userlib.rls"))
|
;; (load (concat HOME "/.relish/userlib.rls"))
|
||||||
|
|
||||||
(def CFG_RELISH_POSIX
|
;; if you have userlib
|
||||||
"my job control preference"
|
;; (set CFG_RELISH_POSIX "1")
|
||||||
"1")
|
;; else
|
||||||
|
(def CFG_RELISH_POSIX
|
||||||
|
(get-doc (q CFG_RELISH_POSIX))
|
||||||
|
"1")
|
||||||
|
|
||||||
(echo "Welcome back to relish.")
|
(echo "Welcome back to relish.")
|
||||||
(echo "Enjoy your computing.")
|
(echo "Enjoy your computing.")
|
||||||
|
|
|
||||||
43
snippets/userlib-tests.rls
Normal file
43
snippets/userlib-tests.rls
Normal file
|
|
@ -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))))
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
;;
|
;;
|
||||||
;; You should have received a copy of the GNU General Public License
|
;; You should have received a copy of the GNU General Public License
|
||||||
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
;;
|
|
||||||
;; USERLIB
|
;; USERLIB
|
||||||
;; This file contains a plethora of useful features that are not shipped in the STL
|
;; This file contains a plethora of useful features that are not shipped in the STL
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ example: (if my-state-switch
|
||||||
|
|
||||||
pub fn if_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
pub fn if_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
||||||
let cond: bool;
|
let cond: bool;
|
||||||
println!("Y: {}", *ast.car);
|
|
||||||
match *ast.car {
|
match *ast.car {
|
||||||
Ctr::Seg(ref cond_form) => {
|
Ctr::Seg(ref cond_form) => {
|
||||||
if let Ctr::Bool(cond_from_eval) = *eval(cond_form, syms)? {
|
if let Ctr::Bool(cond_from_eval) = *eval(cond_form, syms)? {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue