diff options
Diffstat (limited to 'stdlib/source/test/lux/world/file.lux')
-rw-r--r-- | stdlib/source/test/lux/world/file.lux | 83 |
1 files changed, 43 insertions, 40 deletions
diff --git a/stdlib/source/test/lux/world/file.lux b/stdlib/source/test/lux/world/file.lux index 173bd7586..b59202972 100644 --- a/stdlib/source/test/lux/world/file.lux +++ b/stdlib/source/test/lux/world/file.lux @@ -1,7 +1,6 @@ (.module: [lux #* ["%" data/text/format (#+ format)] - ["r" math/random (#+ Random) ("#\." monad)] ["_" test (#+ Test)] [abstract/monad (#+ do)] [control @@ -14,11 +13,13 @@ [data ["." binary (#+ Binary)] ["." text] - [number - ["n" nat] - ["i" int]] [collection ["." list]]] + [math + ["." random (#+ Random) ("#\." monad)] + [number + ["n" nat] + ["i" int]]] [time ["." instant] ["." duration]]] @@ -36,49 +37,51 @@ (def: (creation_and_deletion number) (-> Nat Test) - (r\wrap (do promise.monad - [#let [path (format "temp_file_" (%.nat number))] - result (promise.future - (do (try.with io.monad) - [#let [check_existence! (: (IO (Try Bit)) - (try.lift io.monad (/.exists? io.monad /.default path)))] - pre! check_existence! - file (!.use (\ /.default create_file) path) - post! check_existence! - _ (!.use (\ file delete) []) - remains? check_existence!] - (wrap (and (not pre!) - post! - (not remains?)))))] - (_.assert "Can create/delete files." - (try.default #0 result))))) + (random\wrap + (do promise.monad + [#let [path (format "temp_file_" (%.nat number))] + result (promise.future + (do (try.with io.monad) + [#let [check_existence! (: (IO (Try Bit)) + (try.lift io.monad (/.exists? io.monad /.default path)))] + pre! check_existence! + file (!.use (\ /.default create_file) path) + post! check_existence! + _ (!.use (\ file delete) []) + remains? check_existence!] + (wrap (and (not pre!) + post! + (not remains?)))))] + (_.assert "Can create/delete files." + (try.default #0 result))))) (def: (read_and_write number data) (-> Nat Binary Test) - (r\wrap (do promise.monad - [#let [path (format "temp_file_" (%.nat number))] - result (promise.future - (do (try.with io.monad) - [file (!.use (\ /.default create_file) path) - _ (!.use (\ file over_write) data) - content (!.use (\ file content) []) - _ (!.use (\ file delete) [])] - (wrap (\ binary.equivalence = data content))))] - (_.assert "Can write/read files." - (try.default #0 result))))) + (random\wrap + (do promise.monad + [#let [path (format "temp_file_" (%.nat number))] + result (promise.future + (do (try.with io.monad) + [file (!.use (\ /.default create_file) path) + _ (!.use (\ file over_write) data) + content (!.use (\ file content) []) + _ (!.use (\ file delete) [])] + (wrap (\ binary.equivalence = data content))))] + (_.assert "Can write/read files." + (try.default #0 result))))) (def: #export test Test (<| (_.context (%.name (name_of /._))) - (do {! r.monad} - [file_size (|> r.nat (\ ! map (|>> (n.% 100) (n.max 10)))) + (do {! random.monad} + [file_size (|> random.nat (\ ! map (|>> (n.% 100) (n.max 10)))) dataL (_binary.random file_size) dataR (_binary.random file_size) - new_modified (|> r.int (\ ! map (|>> i.abs - (i.% +10,000,000,000,000) - truncate_millis - duration.from_millis - instant.absolute)))] + new_modified (|> random.int (\ ! map (|>> i.abs + (i.% +10,000,000,000,000) + truncate_millis + duration.from_millis + instant.absolute)))] ($_ _.and ## (..creation_and_deletion 0) ## (..read_and_write 1 dataL) @@ -152,12 +155,12 @@ ## [dir (!.use (\ /.default create_directory) dir_path) ## pre_files (!.use (\ dir files) []) ## pre_directories (!.use (\ dir directories) []) - + ## file (!.use (\ /.default create_file) (format dir_path "/" file_path)) ## inner_dir (!.use (\ /.default create_directory) (format dir_path "/" inner_dir_path)) ## post_files (!.use (\ dir files) []) ## post_directories (!.use (\ dir directories) []) - + ## _ (!.use (\ file delete) []) ## _ (!.use (\ inner_dir discard) []) ## _ (!.use (\ dir discard) [])] |