aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/specification/compositor/generation/reference.lux
diff options
context:
space:
mode:
authorEduardo Julian2021-07-15 00:45:15 -0400
committerEduardo Julian2021-07-15 00:45:15 -0400
commit0abd5bd3c0e38e352e9ba38268e04e1c858ab01e (patch)
treefe0af9e70413e9fc4f3848e0642920fca501c626 /stdlib/source/specification/compositor/generation/reference.lux
parent89ca40f2f101b2b38187eab5cf905371cd47eb57 (diff)
Re-named "spec" hierarchy to "specification".
Diffstat (limited to 'stdlib/source/specification/compositor/generation/reference.lux')
-rw-r--r--stdlib/source/specification/compositor/generation/reference.lux60
1 files changed, 60 insertions, 0 deletions
diff --git a/stdlib/source/specification/compositor/generation/reference.lux b/stdlib/source/specification/compositor/generation/reference.lux
new file mode 100644
index 000000000..665175ab4
--- /dev/null
+++ b/stdlib/source/specification/compositor/generation/reference.lux
@@ -0,0 +1,60 @@
+(.module:
+ [lux #*
+ ["_" test (#+ Test)]
+ [abstract
+ [monad (#+ do)]]
+ [control
+ [pipe (#+ case>)]
+ ["." try]]
+ [data
+ [number
+ ["n" nat]
+ ["f" frac]]]
+ [tool
+ [compiler
+ ["." reference]
+ ["." synthesis]]]
+ [math
+ ["r" random (#+ Random)]]]
+ [///
+ [common (#+ Runner Definer)]])
+
+(def: name
+ (Random Name)
+ (let [name-part (r.ascii/upper-alpha 5)]
+ [(r.and name-part name-part)]))
+
+(def: (definition define)
+ (-> Definer Test)
+ (do r.monad
+ [name ..name
+ expected r.safe-frac]
+ (_.test "Definitions."
+ (|> (define name (synthesis.f64 expected))
+ (case> (#try.Success actual)
+ (f.= expected (:as Frac actual))
+
+ (#try.Failure _)
+ false)))))
+
+(def: (variable run)
+ (-> Runner Test)
+ (do {! r.monad}
+ [register (|> r.nat (\ ! map (n.% 100)))
+ expected r.safe-frac]
+ (_.test "Local variables."
+ (|> (synthesis.branch/let [(synthesis.f64 expected)
+ register
+ (synthesis.variable/local register)])
+ (run "variable")
+ (case> (#try.Success actual)
+ (f.= expected (:as Frac actual))
+
+ (#try.Failure _)
+ false)))))
+
+(def: #export (spec runner definer)
+ (-> Runner Definer Test)
+ ($_ _.and
+ (..definition definer)
+ (..variable runner)))