aboutsummaryrefslogtreecommitdiff
path: root/stdlib/test/test/lux/compiler/default/phase/synthesis/structure.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/test/test/lux/compiler/default/phase/synthesis/structure.lux')
-rw-r--r--stdlib/test/test/lux/compiler/default/phase/synthesis/structure.lux63
1 files changed, 63 insertions, 0 deletions
diff --git a/stdlib/test/test/lux/compiler/default/phase/synthesis/structure.lux b/stdlib/test/test/lux/compiler/default/phase/synthesis/structure.lux
new file mode 100644
index 000000000..924a4126d
--- /dev/null
+++ b/stdlib/test/test/lux/compiler/default/phase/synthesis/structure.lux
@@ -0,0 +1,63 @@
+(.module:
+ [lux #*
+ [control
+ [monad (#+ do)]
+ pipe]
+ [data
+ [bit ("bit/." Equivalence<Bit>)]
+ ["." product]
+ ["." error]
+ [collection
+ ["." list]]]
+ [compiler
+ [default
+ ["." phase
+ ["." analysis]
+ ["//" synthesis (#+ Synthesis)
+ ["." expression]]
+ [extension
+ ["." bundle]]]]]
+ [math
+ ["r" random]]
+ test]
+ ["." //primitive])
+
+(context: "Variants"
+ (<| (times +100)
+ (do @
+ [size (|> r.nat (:: @ map (|>> (n/% +10) (n/+ +2))))
+ tagA (|> r.nat (:: @ map (n/% size)))
+ memberA //primitive.primitive]
+ ($_ seq
+ (test "Can synthesize variants."
+ (|> (analysis.sum-analysis size tagA memberA)
+ expression.synthesize
+ (phase.run [bundle.empty //.init])
+ (case> (#error.Success (#//.Structure (#//.Variant [leftsS right?S valueS])))
+ (let [tagS (if right?S (inc leftsS) leftsS)]
+ (and (n/= tagA tagS)
+ (|> tagS (n/= (dec size)) (bit/= right?S))
+ (//primitive.corresponds? memberA valueS)))
+
+ _
+ #0)))
+ ))))
+
+(context: "Tuples"
+ (<| (times +100)
+ (do @
+ [size (|> r.nat (:: @ map (|>> (n/% +10) (n/max +2))))
+ membersA (r.list size //primitive.primitive)]
+ ($_ seq
+ (test "Can synthesize tuple."
+ (|> (analysis.product-analysis membersA)
+ expression.synthesize
+ (phase.run [bundle.empty //.init])
+ (case> (#error.Success (#//.Structure (#//.Tuple membersS)))
+ (and (n/= size (list.size membersS))
+ (list.every? (product.uncurry //primitive.corresponds?)
+ (list.zip2 membersA membersS)))
+
+ _
+ #0)))
+ ))))