aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/world
diff options
context:
space:
mode:
authorEduardo Julian2020-12-01 09:27:58 -0400
committerEduardo Julian2020-12-01 09:27:58 -0400
commitcfa0a075b89a0df4618e7009f05c157393cbba72 (patch)
tree4bb658a44cfade42e27f9f6bf87d7118c69af6e0 /stdlib/source/test/lux/world
parent7444deb1b80d469280fcb0684d91c13f752a86d6 (diff)
Added specialized root/2 and root/3 functions in lux/math.
Diffstat (limited to 'stdlib/source/test/lux/world')
-rw-r--r--stdlib/source/test/lux/world/file.lux9
-rw-r--r--stdlib/source/test/lux/world/file/watch.lux155
2 files changed, 162 insertions, 2 deletions
diff --git a/stdlib/source/test/lux/world/file.lux b/stdlib/source/test/lux/world/file.lux
index fa1edcfe8..5c633a048 100644
--- a/stdlib/source/test/lux/world/file.lux
+++ b/stdlib/source/test/lux/world/file.lux
@@ -22,6 +22,8 @@
[time
["." instant]
["." duration]]]
+ ["." / #_
+ ["#." watch]]
{1
["." / (#+ Path File)]}
[///
@@ -78,8 +80,9 @@
duration.from-millis
instant.absolute)))]
($_ _.and
- (creation-and-deletion 0)
- (read-and-write 1 dataL)
+ (..creation-and-deletion 0)
+ (..read-and-write 1 dataL)
+
(wrap (do promise.monad
[#let [path "temp_file_2"]
result (promise.future
@@ -197,4 +200,6 @@
confirmed?))))]
(_.assert "Can move a file from one path to another."
(try.default #0 result))))
+
+ /watch.test
))))
diff --git a/stdlib/source/test/lux/world/file/watch.lux b/stdlib/source/test/lux/world/file/watch.lux
new file mode 100644
index 000000000..8d27ab307
--- /dev/null
+++ b/stdlib/source/test/lux/world/file/watch.lux
@@ -0,0 +1,155 @@
+(.module:
+ [lux #*
+ ["_" test (#+ Test)]
+ [abstract
+ [predicate (#+ Predicate)]
+ [monad (#+ do)]]
+ [control
+ ["." try]
+ ["." exception]
+ [concurrency
+ ["." promise]]
+ [security
+ ["!" capability]]]
+ [data
+ ["." binary ("#\." equivalence)]
+ ["." text ("#\." equivalence)
+ ["%" format (#+ format)]]
+ [collection
+ ["." list]]]
+ [math
+ ["." random (#+ Random) ("#\." monad)]]]
+ {1
+ ["." /]}
+ [////
+ [data
+ ["_." binary]]])
+
+(def: concern
+ (Random [/.Concern (Predicate /.Concern)])
+ ($_ random.either
+ (random\wrap [/.creation /.creation?])
+ (random\wrap [/.modification /.modification?])
+ (random\wrap [/.deletion /.deletion?])
+ ))
+
+(def: concern\\test
+ Test
+ (<| (_.with-cover [/.Concern])
+ ($_ _.and
+ (_.cover [/.creation /.creation?]
+ (and (/.creation? /.creation)
+ (not (/.creation? /.modification))
+ (not (/.creation? /.deletion))))
+ (_.cover [/.modification /.modification?]
+ (and (not (/.modification? /.creation))
+ (/.modification? /.modification)
+ (not (/.modification? /.deletion))))
+ (_.cover [/.deletion /.deletion?]
+ (and (not (/.deletion? /.creation))
+ (not (/.deletion? /.modification))
+ (/.deletion? /.deletion)))
+ (do random.monad
+ [left ..concern
+ right (random.filter (|>> (is? left) not)
+ ..concern)
+ #let [[left left?] left
+ [right right?] right]]
+ (_.cover [/.also]
+ (let [composition (/.also left right)]
+ (and (left? composition)
+ (right? composition)))))
+ (_.cover [/.all]
+ (and (/.creation? /.all)
+ (/.modification? /.all)
+ (/.deletion? /.all)))
+ )))
+
+(def: exception
+ Test
+ (do {! random.monad}
+ [directory (random.ascii/alpha 5)
+ #let [[fs watcher] (/.mock "/")]]
+ ($_ _.and
+ (wrap (do promise.monad
+ [?concern (:: watcher concern directory)
+ ?stop (:: watcher stop directory)]
+ (_.cover' [/.not-being-watched]
+ (and (case ?concern
+ (#try.Failure error)
+ (exception.match? /.not-being-watched error)
+
+ (#try.Success _)
+ false)
+ (case ?stop
+ (#try.Failure error)
+ (exception.match? /.not-being-watched error)
+
+ (#try.Success _)
+ false)))))
+ )))
+
+(def: #export test
+ Test
+ (<| (_.covering /._)
+ (_.with-cover [/.Watcher])
+ ($_ _.and
+ ..concern\\test
+ ..exception
+
+ (do {! random.monad}
+ [directory (random.ascii/alpha 5)
+ #let [/ "/"
+ [fs watcher] (/.mock /)]
+ expected-path (:: ! map (|>> (format directory /))
+ (random.ascii/alpha 5))
+ data (_binary.random 10)]
+ (wrap (do {! promise.monad}
+ [verdict (do (try.with !)
+ [_ (!.use (:: fs create-directory) [directory])
+ _ (:: watcher start /.all directory)
+ poll/0 (:: watcher poll [])
+ #let [no-events-prior-to-creation!
+ (list.empty? poll/0)]
+ file (!.use (:: fs create-file) [expected-path])
+ poll/1 (:: watcher poll [])
+ #let [after-creation!
+ (case poll/1
+ (^ (list [actual-path concern]))
+ (and (text\= expected-path actual-path)
+ (and (/.creation? concern)
+ (not (/.modification? concern))
+ (not (/.deletion? concern))))
+
+ _
+ false)]
+ _ (!.use (:: file over-write) data)
+ poll/2 (:: watcher poll [])
+ #let [after-modification!
+ (case poll/2
+ (^ (list [actual-path concern]))
+ (and (text\= expected-path actual-path)
+ (and (not (/.creation? concern))
+ (/.modification? concern)
+ (not (/.deletion? concern))))
+
+ _
+ false)]
+ _ (!.use (:: file delete) [])
+ poll/3 (:: watcher poll [])
+ #let [after-deletion!
+ (case poll/3
+ (^ (list [actual-path concern]))
+ (and (not (/.creation? concern))
+ (not (/.modification? concern))
+ (/.deletion? concern))
+
+ _
+ false)]]
+ (wrap (and no-events-prior-to-creation!
+ after-creation!
+ after-modification!
+ after-deletion!)))]
+ (_.cover' [/.mock /.polling]
+ (try.default false verdict)))))
+ )))