Big project dir refactor
* split into multi member workspace in preparation for a no_std core * env and posix stuff neatly crammed into a seperate shell project * some pokes at interactive-devel.f * updated ci * removed 'l' shortcut for 'load' and update docs * remove out of date readme content * updated tests * more sensible cond implementation and extra tests * substr stdlib function with tests Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit is contained in:
parent
aa56570d7d
commit
6d2925984f
44 changed files with 967 additions and 779 deletions
|
|
@ -20,44 +20,44 @@
|
|||
;; this file implements unit tests for handwritten userlib functions
|
||||
|
||||
(def passed
|
||||
'prints if a test has passed'
|
||||
"prints if a test has passed"
|
||||
(test)
|
||||
(echo (concat "PASSED: " test)))
|
||||
|
||||
(def failed
|
||||
'prints if a test has failed'
|
||||
"prints if a test has failed"
|
||||
(test)
|
||||
(let (())
|
||||
(echo (concat "FAILED: " test))
|
||||
(exit 1)))
|
||||
|
||||
(def test-cases 'all test cases'
|
||||
(('set updates var'
|
||||
(def test-cases "all test cases"
|
||||
(("set updates var"
|
||||
(quote
|
||||
(let ((test-val 0))
|
||||
(set (q test-val) 3)
|
||||
(eq? test-val 3))))
|
||||
|
||||
('prepend prepends to list'
|
||||
("prepend prepends to list"
|
||||
(quote
|
||||
(let ((list (2 3 4))
|
||||
(list (prepend 1 list))
|
||||
(list-head (pop list)))
|
||||
(eq? (car list-head) 1))))
|
||||
|
||||
('map applies function across list'
|
||||
("map applies function across list"
|
||||
(quote
|
||||
(let ((list (1 2 3))
|
||||
(adder (lambda (x) (add 1 x))))
|
||||
(eq? (map adder list) (2 3 4)))))
|
||||
|
||||
('reduce function adds numbers'
|
||||
("reduce function adds numbers"
|
||||
(quote
|
||||
(let ((list (1 2 3))
|
||||
(adder (lambda (x y) (add x y))))
|
||||
(eq? (reduce adder list) (add 1 2 3)))))
|
||||
|
||||
('cond evaluates the first branch that returns true'
|
||||
("cond evaluates the first branch that returns true"
|
||||
(quote
|
||||
(let ((switch-one false)
|
||||
(switch-two false)
|
||||
|
|
@ -68,7 +68,7 @@
|
|||
(true (toggle switch-three)))))
|
||||
(and (not switch-one) switch-two (not switch-three)))))
|
||||
|
||||
('cond doesnt do anything if all the branches are false'
|
||||
("cond doesnt do anything if all the branches are false"
|
||||
(quote
|
||||
(let ((switch-one false)
|
||||
(switch-two false)
|
||||
|
|
@ -79,27 +79,32 @@
|
|||
(false (toggle switch-three)))))
|
||||
(and (not switch-one) (not switch-two) (not switch-three)))))
|
||||
|
||||
('cond returns the result of the branch that is evaluated'
|
||||
("cond returns the result of the branch that is evaluated"
|
||||
(quote
|
||||
(let ((variable false))
|
||||
(let ((variable "2"))
|
||||
(set (q variable)
|
||||
(cond (q
|
||||
((true true)))))
|
||||
variable)))
|
||||
((true "1")))))
|
||||
(eq? variable "1"))))
|
||||
|
||||
('contains? finds elem in list'
|
||||
("cond does not choke on nil evaluated result"
|
||||
(quote
|
||||
(cdr ((cond (q ((true (assert true)))))
|
||||
true))))
|
||||
|
||||
("contains? finds elem in list"
|
||||
(quote
|
||||
(contains? (1 2 3) 1)))
|
||||
|
||||
('contains? finds last elem in list'
|
||||
("contains? finds last elem in list"
|
||||
(quote
|
||||
(contains? (1 2 3) 3)))
|
||||
|
||||
('contains? doesnt find elem not in list'
|
||||
("contains? doesnt find elem not in list"
|
||||
(quote
|
||||
(not (contains? (1 2 3) 4))))
|
||||
|
||||
('get-paths properly splits path into segments'
|
||||
("get-paths properly splits path into segments"
|
||||
(quote
|
||||
(let ((PATH "/seg1:/seg2")
|
||||
(split-path (get-paths)))
|
||||
|
|
@ -107,20 +112,20 @@
|
|||
(contains? split-path "/seg1")
|
||||
(contains? split-path "/seg2")))))
|
||||
|
||||
('add-path properly adds a new path segment to PATH'
|
||||
("add-path properly adds a new path segment to PATH"
|
||||
(quote
|
||||
(let ((PATH "/seg1:/seg2")
|
||||
(new-path "/seg3"))
|
||||
(add-path new-path)
|
||||
(contains? (get-paths) new-path))))
|
||||
|
||||
('join operates as expected'
|
||||
("join operates as expected"
|
||||
(quote
|
||||
(let ((l ("1" 2 (3))))
|
||||
(eq? (join l ".")
|
||||
"1.2.(3)"))))
|
||||
|
||||
('extend extends sets'
|
||||
("extend extends sets"
|
||||
(quote
|
||||
(let ((s1 (1 2 3))
|
||||
(s2 (4 5 6)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue