aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/world
diff options
context:
space:
mode:
authorEduardo Julian2019-06-20 23:38:59 -0400
committerEduardo Julian2019-06-20 23:38:59 -0400
commitcf17b08c5d9b3aedc8aaa2b11456dcb69dec6049 (patch)
tree7ded5a1f866485223c34e1b97193aeb0b63b5456 /stdlib/source/test/lux/world
parentfbc9f6f9186254263255f03a9378216adfbeaa0e (diff)
Moved "lux/world/binary" to "lux/data/binary".
Diffstat (limited to 'stdlib/source/test/lux/world')
-rw-r--r--stdlib/source/test/lux/world/binary.lux90
-rw-r--r--stdlib/source/test/lux/world/file.lux10
2 files changed, 5 insertions, 95 deletions
diff --git a/stdlib/source/test/lux/world/binary.lux b/stdlib/source/test/lux/world/binary.lux
deleted file mode 100644
index 8fb17114e..000000000
--- a/stdlib/source/test/lux/world/binary.lux
+++ /dev/null
@@ -1,90 +0,0 @@
-(.module:
- [lux #*
- ["%" data/text/format (#+ format)]
- ["r" math/random (#+ Random)]
- ["_" test (#+ Test)]
- [abstract
- ["." monad (#+ do)]
- {[0 #test]
- [/
- ["$." equivalence]]}]
- [data
- ["." error (#+ Error)]
- [number
- ["." i64]
- ["." nat]]
- [collection
- ["." list]]]]
- {1
- ["." / (#+ Binary)]})
-
-(def: (succeed result)
- (-> (Error Bit) Bit)
- (case result
- (#error.Failure _)
- #0
-
- (#error.Success output)
- output))
-
-(def: #export (binary size)
- (-> Nat (Random Binary))
- (let [output (/.create size)]
- (loop [idx 0]
- (if (n/< size idx)
- (do r.monad
- [byte r.nat]
- (exec (error.assume (/.write/8 idx byte output))
- (recur (inc idx))))
- (:: r.monad wrap output)))))
-
-(def: (bits-io bytes read write value)
- (-> Nat (-> Nat Binary (Error Nat)) (-> Nat Nat Binary (Error Any)) Nat Bit)
- (let [binary (/.create bytes)
- cap (case bytes
- 8 (dec 0)
- _ (|> 1 (i64.left-shift (n/* 8 bytes)) dec))
- capped-value (i64.and cap value)]
- (succeed
- (do error.monad
- [_ (write 0 value binary)
- output (read 0 binary)]
- (wrap (n/= capped-value output))))))
-
-(def: #export test
- Test
- (<| (_.context (%.name (name-of /._)))
- (do r.monad
- [#let [gen-size (|> r.nat (:: @ map (|>> (n/% 100) (n/max 8))))]
- binary-size gen-size
- random-binary (binary binary-size)
- value r.nat
- #let [gen-idx (|> r.nat (:: @ map (n/% binary-size)))]
- [from to] (r.and gen-idx gen-idx)
- #let [[from to] [(n/min from to) (n/max from to)]]]
- ($_ _.and
- ($equivalence.spec /.equivalence (binary binary-size))
- (_.test "Can get size of binary."
- (|> random-binary /.size (n/= binary-size)))
- (_.test "Can read/write 8-bit values."
- (bits-io 1 /.read/8 /.write/8 value))
- (_.test "Can read/write 16-bit values."
- (bits-io 2 /.read/16 /.write/16 value))
- (_.test "Can read/write 32-bit values."
- (bits-io 4 /.read/32 /.write/32 value))
- (_.test "Can read/write 64-bit values."
- (bits-io 8 /.read/64 /.write/64 value))
- (_.test "Can slice binaries."
- (let [slice-size (|> to (n/- from) inc)
- random-slice (error.assume (/.slice from to random-binary))
- idxs (list.n/range 0 (dec slice-size))
- reader (function (_ binary idx) (/.read/8 idx binary))]
- (and (n/= slice-size (/.size random-slice))
- (case [(monad.map error.monad (reader random-slice) idxs)
- (monad.map error.monad (|>> (n/+ from) (reader random-binary)) idxs)]
- [(#error.Success slice-vals) (#error.Success binary-vals)]
- (:: (list.equivalence nat.equivalence) = slice-vals binary-vals)
-
- _
- #0))))
- ))))
diff --git a/stdlib/source/test/lux/world/file.lux b/stdlib/source/test/lux/world/file.lux
index c0c3f7d18..451f4671b 100644
--- a/stdlib/source/test/lux/world/file.lux
+++ b/stdlib/source/test/lux/world/file.lux
@@ -11,6 +11,7 @@
[security
["!" capability]]]
[data
+ ["." binary (#+ Binary)]
["." error (#+ Error)]
["." text]
[number
@@ -19,13 +20,12 @@
["." list]]]
[time
["." instant]
- ["." duration]]
- [world
- ["." binary (#+ Binary)]]]
+ ["." duration]]]
{1
["." / (#+ Path File)]}
- [//
- ["_." binary]])
+ [///
+ [data
+ ["_." binary]]])
(def: truncate-millis
(let [millis +1,000]