diff options
Diffstat (limited to 'stdlib/source/test/lux/tool/compiler/phase/synthesis/structure.lux')
| -rw-r--r-- | stdlib/source/test/lux/tool/compiler/phase/synthesis/structure.lux | 75 | 
1 files changed, 75 insertions, 0 deletions
diff --git a/stdlib/source/test/lux/tool/compiler/phase/synthesis/structure.lux b/stdlib/source/test/lux/tool/compiler/phase/synthesis/structure.lux new file mode 100644 index 000000000..4e7f6c3b5 --- /dev/null +++ b/stdlib/source/test/lux/tool/compiler/phase/synthesis/structure.lux @@ -0,0 +1,75 @@ +(.module: +  [lux #* +   [abstract ["." monad (#+ do)]] +   [data +    text/format +    ["." name]] +   ["r" math/random (#+ Random) ("#@." monad)] +   ["_" test (#+ Test)] +   [control +    pipe] +   [data +    ["." bit ("#@." equivalence)] +    ["." product] +    ["." error] +    [collection +     ["." list]]]] +  ["." // #_ +   ["#." primitive]] +  {1 +   ["." / #_ +    ["/#" // +     ["/#" // +      [extension +       ["#." bundle]] +      ["/#" // +       ["#." analysis (#+ Analysis)] +       ["#." synthesis (#+ Synthesis)]]]]]}) + +(def: variant +  Test +  (do r.monad +    [size (|> r.nat (:: @ map (|>> (n/% 10) (n/+ 2)))) +     tagA (|> r.nat (:: @ map (n/% size))) +     #let [right? (n/= (dec size) tagA) +           lefts (if right? +                   (dec tagA) +                   tagA)] +     memberA //primitive.primitive] +    (_.test "Can synthesize variants." +            (|> (////analysis.variant [lefts right? memberA]) +                //.phase +                (///.run [///bundle.empty ////synthesis.init]) +                (case> (^ (#error.Success (////synthesis.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))) +                        +                       _ +                       false))))) + +(def: tuple +  Test +  (do r.monad +    [size (|> r.nat (:: @ map (|>> (n/% 10) (n/max 2)))) +     membersA (r.list size //primitive.primitive)] +    (_.test "Can synthesize tuple." +            (|> (////analysis.tuple membersA) +                //.phase +                (///.run [///bundle.empty ////synthesis.init]) +                (case> (^ (#error.Success (////synthesis.tuple membersS))) +                       (and (n/= size (list.size membersS)) +                            (list.every? (product.uncurry //primitive.corresponds?) +                                         (list.zip2 membersA membersS))) + +                       _ +                       false))))) + +(def: #export test +  Test +  (<| (_.context (%name (name-of #////synthesis.Structure))) +      ($_ _.and +          ..variant +          ..tuple +          )))  | 
