diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/world/env.jvm.lux | 2 | ||||
-rw-r--r-- | stdlib/test/test/lux/world/file.lux | 213 |
2 files changed, 105 insertions, 110 deletions
diff --git a/stdlib/source/lux/world/env.jvm.lux b/stdlib/source/lux/world/env.jvm.lux index 4db48fee6..e2511416e 100644 --- a/stdlib/source/lux/world/env.jvm.lux +++ b/stdlib/source/lux/world/env.jvm.lux @@ -23,7 +23,7 @@ (entrySet [] (Set (Map$Entry k v)))) (host.import: java/lang/System - (#static getenv [] (java/util/Map String String))) + (#static getenv [] (Map String String))) (def: (consume-iterator f iterator) (All [a b] (-> (-> a b) (Iterator a) (List b))) diff --git a/stdlib/test/test/lux/world/file.lux b/stdlib/test/test/lux/world/file.lux index 75f08e97c..e126b8703 100644 --- a/stdlib/test/test/lux/world/file.lux +++ b/stdlib/test/test/lux/world/file.lux @@ -2,14 +2,13 @@ lux (lux [io] (control [monad #+ do]) - (concurrency ["P" promise] - ["T" task]) - (data ["e" error] + (concurrency [promise]) + (data [error] [text] text/format [number]) - (time ["i" instant] - ["d" duration]) + (time [instant] + [duration]) (world ["@" file] [blob]) ["r" math/random]) @@ -27,113 +26,111 @@ code r.nat last-modified (|> r.int (:: @ map (|>> (:: number.Number<Int> abs) truncate-millis - d.from-millis - i.absolute)))] + duration.from-millis + instant.absolute)))] ($_ seq - (wrap (do P.Monad<Promise> + (wrap (do promise.Monad<Promise> [#let [file (format "temp_file_" (%n (n/+ +0 code)))] - result (P.future - (do io.Monad<Process> - [pre (@.exists? file) - _ (@.write dataL file) - post (@.exists? file) - deleted? (@.delete file) - remains? (@.exists? file)] - (wrap (and (not pre) post - deleted? (not remains?)))))] + result (promise.future + (do (:: @.JVM@System &monad) + [pre! (@.exists? @.JVM@System file) + _ (:: @.JVM@System write dataL file) + post! (@.exists? @.JVM@System file) + _ (:: @.JVM@System delete file) + remains? (@.exists? @.JVM@System file)] + (wrap (and (not pre!) post! + (not remains?)))))] (assert "Can create/delete files." - (e.default false result)))) - (wrap (do P.Monad<Promise> + (error.default false result)))) + (wrap (do promise.Monad<Promise> [#let [file (format "temp_file_" (%n (n/+ +1 code)))] - result (P.future - (do io.Monad<Process> - [_ (@.write dataL file) - output (@.read file) - _ (@.delete file)] + result (promise.future + (do (:: @.JVM@System &monad) + [_ (:: @.JVM@System write dataL file) + output (:: @.JVM@System read file) + _ (:: @.JVM@System delete file)] (wrap (:: blob.Equivalence<Blob> = dataL output))))] (assert "Can write/read files." - (e.default false result)))) - (wrap (do P.Monad<Promise> + (error.default false result)))) + (wrap (do promise.Monad<Promise> [#let [file (format "temp_file_" (%n (n/+ +2 code)))] - result (P.future - (do io.Monad<Process> - [_ (@.write dataL file) - read-size (@.size file) - _ (@.delete file)] + result (promise.future + (do (:: @.JVM@System &monad) + [_ (:: @.JVM@System write dataL file) + read-size (:: @.JVM@System size file) + _ (:: @.JVM@System delete file)] (wrap (n/= file-size read-size))))] (assert "Can read file size." - (e.default false result)))) - (wrap (do P.Monad<Promise> + (error.default false result)))) + (wrap (do promise.Monad<Promise> [#let [file (format "temp_file_" (%n (n/+ +3 code)))] - result (P.future - (do io.Monad<Process> - [_ (@.write dataL file) - _ (@.append dataR file) - output (@.read file) - read-size (@.size file) - _ (@.delete file)] + result (promise.future + (do (:: @.JVM@System &monad) + [_ (:: @.JVM@System write dataL file) + _ (:: @.JVM@System append dataR file) + output (:: @.JVM@System read file) + read-size (:: @.JVM@System size file) + _ (:: @.JVM@System delete file)] (wrap (and (n/= (n/* +2 file-size) read-size) - (:: blob.Equivalence<Blob> = dataL (e.assume (blob.slice +0 (dec file-size) output))) - (:: blob.Equivalence<Blob> = dataR (e.assume (blob.slice file-size (dec read-size) output)))))))] + (:: blob.Equivalence<Blob> = dataL (error.assume (blob.slice +0 (dec file-size) output))) + (:: blob.Equivalence<Blob> = dataR (error.assume (blob.slice file-size (dec read-size) output)))))))] (assert "Can append to files." - (e.default false result)))) - (wrap (do P.Monad<Promise> + (error.default false result)))) + (wrap (do promise.Monad<Promise> [#let [dir (format "temp_dir_" (%n (n/+ +4 code)))] - result (P.future - (do io.Monad<Process> - [pre (@.exists? dir) - _ (@.make-directory dir) - post (@.exists? dir) - deleted? (@.delete dir) - remains? (@.exists? dir)] - (wrap (and (not pre) post - deleted? (not remains?)))))] + result (promise.future + (do (:: @.JVM@System &monad) + [pre! (@.exists? @.JVM@System dir) + _ (:: @.JVM@System make-directory dir) + post! (@.exists? @.JVM@System dir) + _ (:: @.JVM@System delete dir) + remains? (@.exists? @.JVM@System dir)] + (wrap (and (not pre!) post! + (not remains?)))))] (assert "Can create/delete directories." - (e.default false result)))) - (wrap (do P.Monad<Promise> + (error.default false result)))) + (wrap (do promise.Monad<Promise> [#let [file (format "temp_file_" (%n (n/+ +5 code))) dir (format "temp_dir_" (%n (n/+ +5 code)))] - result (P.future - (do io.Monad<Process> - [_ (@.write dataL file) - file-is-file (@.file? file) - file-is-directory (@.directory? file) - _ (@.delete file) - _ (@.make-directory dir) - directory-is-file (@.file? dir) - directory-is-directory (@.directory? dir) - _ (@.delete dir)] + result (promise.future + (do (:: @.JVM@System &monad) + [_ (:: @.JVM@System write dataL file) + file-is-file (:: @.JVM@System file? file) + file-is-directory (:: @.JVM@System directory? file) + _ (:: @.JVM@System delete file) + _ (:: @.JVM@System make-directory dir) + directory-is-file (:: @.JVM@System file? dir) + directory-is-directory (:: @.JVM@System directory? dir) + _ (:: @.JVM@System delete dir)] (wrap (and file-is-file (not file-is-directory) (not directory-is-file) directory-is-directory))))] (assert "Can differentiate files from directories." - (e.default false result)))) - (wrap (do P.Monad<Promise> + (error.default false result)))) + (wrap (do promise.Monad<Promise> [#let [file (format "temp_file_" (%n (n/+ +6 code))) dir (format "temp_dir_" (%n (n/+ +6 code)))] - result (P.future - (do io.Monad<Process> - [_ (@.make-directory dir) + result (promise.future + (do (:: @.JVM@System &monad) + [_ (:: @.JVM@System make-directory dir) #let [file' (format dir "/" file)] - _ (@.write dataL file') - read-size (@.size file') - deleted-file (@.delete file') - deleted-dir (@.delete dir)] - (wrap (and (n/= file-size read-size) - deleted-file - deleted-dir))))] + _ (:: @.JVM@System write dataL file') + read-size (:: @.JVM@System size file') + _ (:: @.JVM@System delete file') + _ (:: @.JVM@System delete dir)] + (wrap (n/= file-size read-size))))] (assert "Can create files inside of directories." - (e.default false result)))) - (wrap (do P.Monad<Promise> + (error.default false result)))) + (wrap (do promise.Monad<Promise> [#let [file (format "temp_file_" (%n (n/+ +7 code))) dir (format "temp_dir_" (%n (n/+ +7 code)))] - result (P.future - (do io.Monad<Process> - [_ (@.make-directory dir) + result (promise.future + (do (:: @.JVM@System &monad) + [_ (:: @.JVM@System make-directory dir) #let [file' (format dir "/" file)] - _ (@.write dataL file') - children (@.files dir) - _ (@.delete file') - _ (@.delete dir)] + _ (:: @.JVM@System write dataL file') + children (:: @.JVM@System files dir) + _ (:: @.JVM@System delete file') + _ (:: @.JVM@System delete dir)] (wrap (case children (^ (list child)) (text.ends-with? file' child) @@ -141,32 +138,30 @@ _ false))))] (assert "Can list files inside a directory." - (e.default false result)))) - (wrap (do P.Monad<Promise> + (error.default false result)))) + (wrap (do promise.Monad<Promise> [#let [file (format "temp_file_" (%n (n/+ +8 code)))] - result (P.future - (do io.Monad<Process> - [_ (@.write dataL file) - was-modified? (@.modify last-modified file) - time-read (@.last-modified file) - _ (@.delete file)] - (wrap (and was-modified? - (:: i.Equivalence<Instant> = last-modified time-read)))))] + result (promise.future + (do (:: @.JVM@System &monad) + [_ (:: @.JVM@System write dataL file) + _ (:: @.JVM@System modify last-modified file) + time-read (:: @.JVM@System last-modified file) + _ (:: @.JVM@System delete file)] + (wrap (:: instant.Equivalence<Instant> = last-modified time-read))))] (assert "Can change the time of last modification." - (e.default false result)))) - (wrap (do P.Monad<Promise> + (error.default false result)))) + (wrap (do promise.Monad<Promise> [#let [file0 (format "temp_file_" (%n (n/+ +9 code)) "0") file1 (format "temp_file_" (%n (n/+ +9 code)) "1")] - result (P.future - (do io.Monad<Process> - [_ (@.write dataL file0) - pre (@.exists? file0) - moved? (@.move file1 file0) - post (@.exists? file0) - confirmed? (@.exists? file1) - deleted? (@.delete file1)] - (wrap (and pre moved? (not post) - confirmed? deleted?))))] + result (promise.future + (do (:: @.JVM@System &monad) + [_ (:: @.JVM@System write dataL file0) + pre! (@.exists? @.JVM@System file0) + _ (:: @.JVM@System move file1 file0) + post! (@.exists? @.JVM@System file0) + confirmed? (@.exists? @.JVM@System file1) + _ (:: @.JVM@System delete file1)] + (wrap (and pre! (not post!) confirmed?))))] (assert "Can move a file from one path to another." - (e.default false result)))) + (error.default false result)))) ))) |