mirror of
https://github.com/janet-lang/janet
synced 2025-10-16 00:07:40 +00:00
Merge branch 'janet-lang:master' into master
This commit is contained in:
@@ -333,4 +333,29 @@
|
||||
|
||||
(assert (pos? (length (gensym))) "gensym not empty, regression #753")
|
||||
|
||||
|
||||
# os/clock. These tests might prove fragile under CI because they
|
||||
# rely on measured time. We'll see.
|
||||
|
||||
(defmacro measure-time [clocks & body]
|
||||
(def [t1 t2] [(gensym) (gensym)])
|
||||
~(do
|
||||
(def ,t1 (map |(os/clock $) ,clocks))
|
||||
,;body
|
||||
(def ,t2 (map |(os/clock $) ,clocks))
|
||||
(zipcoll ,clocks (map |(- ;$) (map tuple ,t2 ,t1))))
|
||||
)
|
||||
|
||||
# Spin for 0.1 seconds
|
||||
(def dt (measure-time [:realtime :monotonic :cputime]
|
||||
(def t1 (os/clock :monotonic))
|
||||
(while (< (- (os/clock :monotonic) t1) 0.1) true)))
|
||||
(assert (> (dt :monotonic) 0.10))
|
||||
(assert (> (dt :cputime) 0.05))
|
||||
|
||||
# Sleep for 0.1 seconds
|
||||
(def dt (measure-time [:realtime :monotonic :cputime] (os/sleep 0.1)))
|
||||
(assert (> (dt :monotonic) 0.10))
|
||||
(assert (< (dt :cputime) 0.05))
|
||||
|
||||
(end-suite)
|
||||
|
@@ -253,4 +253,13 @@
|
||||
# Check missing struct proto bug.
|
||||
(assert (struct/getproto (struct/with-proto {:a 1} :b 2 :c nil)) "missing struct proto")
|
||||
|
||||
# Test thaw and freeze
|
||||
(def table-to-freeze @{:c 22 :b [1 2 3 4] :d @"test" :e "test2"})
|
||||
(def table-to-freeze-with-inline-proto @{:a @[1 2 3] :b @[1 2 3 4] :c 22 :d @"test" :e @"test2"})
|
||||
(def struct-to-thaw (struct/with-proto {:a [1 2 3]} :c 22 :b [1 2 3 4] :d "test" :e "test2"))
|
||||
(table/setproto table-to-freeze @{:a @[1 2 3]})
|
||||
(assert (deep= {:a [1 2 3] :b [1 2 3 4] :c 22 :d "test" :e "test2"} (freeze table-to-freeze)))
|
||||
(assert (deep= table-to-freeze-with-inline-proto (thaw table-to-freeze)))
|
||||
(assert (deep= table-to-freeze-with-inline-proto (thaw struct-to-thaw)))
|
||||
|
||||
(end-suite)
|
||||
|
Reference in New Issue
Block a user