aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorMike Beller <bellermike@gmail.com>2021-01-10 16:55:22 -0500
committerMike Beller <bellermike@gmail.com>2021-01-10 16:55:22 -0500
commit17a9d7788e76e30991f4f529603f65d3efdd077f (patch)
tree84c7104d7a937489e95eb8b03467c43fab735653 /test
parentAdd init.janet so a user can do (use spork) (diff)
Working versions of misc/timeit and misc/set*
Diffstat (limited to 'test')
-rw-r--r--test/suite1.janet44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/suite1.janet b/test/suite1.janet
index 879057b..2cf9005 100644
--- a/test/suite1.janet
+++ b/test/suite1.janet
@@ -2,5 +2,49 @@
(import ../spork/misc)
(start-suite 1)
+
+#misc/dedent
(assert (= (misc/dedent " a\n b\n c\n d") "a\n b\n c\n d") "dedent")
+
+#misc/timeit
+(defmacro- capture-stdout
+ [form]
+ (with-syms [buf res]
+ ~(do
+ (def ,buf (buffer/new 1024))
+ (with-dyns [:out ,buf]
+ (def ,res ,form)
+ [,res (string ,buf)]))))
+
+(do
+ (def [result output]
+ (capture-stdout
+ (misc/timeit (loop [i :range [1 100000]] i) "foo:")))
+ (assert (nil? result))
+ (def m (peg/match '(* "foo: " (<- (some :S)) " seconds\n" -1) output))
+ (assert (truthy? m) "timeit -- invalid output")
+ (assert (scan-number (in m 0)) "timeit -- invalid number of seconds"))
+
+(do
+ (def [result output]
+ (capture-stdout
+ (misc/timeit "someresult")))
+ (assert (= result "someresult") "timeit2 -- invalid return")
+ (def m (peg/match '(* "Elapsed time: " (<- (some :S)) " seconds\n" -1) output))
+ (assert (truthy? m) "timeit2 -- invalid output")
+ (assert (scan-number (in m 0)) "timeit2 -- invalid number of seconds"))
+
+#misc/set*
+(do
+ (var x 2)
+ (var y 3)
+ (misc/set* [x y] [y (+ x y)])
+ (print x " " y)
+ (assert (and (= x 3) (= y 5)) "set* 1"))
+
+(do
+ (def x @[2 3])
+ (misc/set* [[x 0] [x 1]] [(in x 1) (+ (in x 0) (in x 1))])
+ (assert (deep= x @[3 5])))
+
(end-suite)