aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/world
diff options
context:
space:
mode:
authorEduardo Julian2021-06-18 14:21:41 -0400
committerEduardo Julian2021-06-18 14:21:41 -0400
commita82bd1eabe94763162c2b0707d9c198fbe9835e3 (patch)
tree032473704af6e7db41e1f6dc87ab995788d8ab17 /stdlib/source/test/lux/world
parent519c0c0c71cdf7ce3dfc64b9781ab826760b3d94 (diff)
Refactored the machinery to make local macros into its own module.
Diffstat (limited to '')
-rw-r--r--stdlib/source/test/lux/world.lux3
-rw-r--r--stdlib/source/test/lux/world/input/keyboard.lux144
-rw-r--r--stdlib/source/test/lux/world/output/video/resolution.lux16
3 files changed, 156 insertions, 7 deletions
diff --git a/stdlib/source/test/lux/world.lux b/stdlib/source/test/lux/world.lux
index 8b560ca40..62e0fc397 100644
--- a/stdlib/source/test/lux/world.lux
+++ b/stdlib/source/test/lux/world.lux
@@ -6,6 +6,8 @@
["#." shell]
["#." console]
["#." program]
+ ["#." input #_
+ ["#/." keyboard]]
["#." output #_
["#/." video #_
["#/." resolution]]]])
@@ -17,5 +19,6 @@
/shell.test
/console.test
/program.test
+ /input/keyboard.test
/output/video/resolution.test
))
diff --git a/stdlib/source/test/lux/world/input/keyboard.lux b/stdlib/source/test/lux/world/input/keyboard.lux
new file mode 100644
index 000000000..e38ce6271
--- /dev/null
+++ b/stdlib/source/test/lux/world/input/keyboard.lux
@@ -0,0 +1,144 @@
+(.module:
+ [lux #*
+ ["_" test (#+ Test)]
+ [abstract
+ [monad (#+ do)]]
+ [data
+ ["." bit ("#\." equivalence)]
+ ["." maybe]
+ [collection
+ ["." list]
+ ["." set (#+ Set)]]]
+ [math
+ ["." random (#+ Random)]
+ [number
+ ["n" nat]]]]
+ {1
+ ["." /]})
+
+(with_expansions [<keys> (as_is /.back_space
+ /.enter
+ /.shift
+ /.control
+ /.alt
+ /.caps_lock
+ /.escape
+ /.space
+ /.page_up
+ /.page_down
+ /.end
+ /.home
+
+ /.left
+ /.up
+ /.right
+ /.down
+
+ /.a
+ /.b
+ /.c
+ /.d
+ /.e
+ /.f
+ /.g
+ /.h
+ /.i
+ /.j
+ /.k
+ /.l
+ /.m
+ /.n
+ /.o
+ /.p
+ /.q
+ /.r
+ /.s
+ /.t
+ /.u
+ /.v
+ /.w
+ /.x
+ /.y
+ /.z
+
+ /.num_pad_0
+ /.num_pad_1
+ /.num_pad_2
+ /.num_pad_3
+ /.num_pad_4
+ /.num_pad_5
+ /.num_pad_6
+ /.num_pad_7
+ /.num_pad_8
+ /.num_pad_9
+
+ /.delete
+ /.num_lock
+ /.scroll_lock
+ /.print_screen
+ /.insert
+ /.windows
+
+ /.f1
+ /.f2
+ /.f3
+ /.f4
+ /.f5
+ /.f6
+ /.f7
+ /.f8
+ /.f9
+ /.f10
+ /.f11
+ /.f12
+ /.f13
+ /.f14
+ /.f15
+ /.f16
+ /.f17
+ /.f18
+ /.f19
+ /.f20
+ /.f21
+ /.f22
+ /.f23
+ /.f24)]
+ (def: listing
+ (List /.Key)
+ (list <keys>))
+
+ (def: catalogue
+ (Set /.Key)
+ (set.from_list n.hash ..listing))
+
+ (def: #export random
+ (Random /.Key)
+ (let [count (list.size ..listing)]
+ (do {! random.monad}
+ [choice (\ ! map (n.% count) random.nat)]
+ (wrap (maybe.assume (list.nth choice ..listing))))))
+
+ (def: #export test
+ Test
+ (<| (_.covering /._)
+ (_.for [/.Key])
+ ($_ _.and
+ (_.cover [<keys>]
+ (n.= (list.size ..listing)
+ (set.size ..catalogue)))
+
+ (_.for [/.Press]
+ (`` ($_ _.and
+ (~~ (template [<pressed?> <function>]
+ [(do random.monad
+ [key ..random
+ #let [sample (<function> key)]]
+ (_.cover [<function>]
+ (and (bit\= <pressed?> (get@ #/.pressed? sample))
+ (n.= key (get@ #/.input sample)))))]
+
+ [#0 /.release]
+ [#1 /.press]
+ ))
+ )))
+ ))))
diff --git a/stdlib/source/test/lux/world/output/video/resolution.lux b/stdlib/source/test/lux/world/output/video/resolution.lux
index f5dcf5380..b7684ed2f 100644
--- a/stdlib/source/test/lux/world/output/video/resolution.lux
+++ b/stdlib/source/test/lux/world/output/video/resolution.lux
@@ -34,17 +34,20 @@
/.wuxga
/.wqhd
/.uhd-4k)]
+ (def: listing
+ (List /.Resolution)
+ (list <resolutions>))
+
(def: catalogue
(Set /.Resolution)
- (set.from_list /.hash (list <resolutions>)))
+ (set.from_list /.hash ..listing))
(def: #export random
(Random /.Resolution)
- (let [listing (set.to_list catalogue)
- count (list.size listing)]
+ (let [count (list.size ..listing)]
(do {! random.monad}
[choice (\ ! map (n.% count) random.nat)]
- (wrap (maybe.assume (list.nth choice listing))))))
+ (wrap (maybe.assume (list.nth choice ..listing))))))
(def: #export test
Test
@@ -57,7 +60,6 @@
($hash.spec /.hash ..random))
(_.cover [<resolutions>]
- (let [listing (set.to_list catalogue)]
- (n.= (list.size listing)
- (set.size catalogue))))
+ (n.= (list.size ..listing)
+ (set.size ..catalogue)))
))))