aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/type/abstract.lux
blob: ee1b7fc4a4f0a1d6867c8b81de4cd1585580d975 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
(.module:
  [library
   [lux "*"
    ["_" test {"+" [Test]}]
    ["[0]" meta]
    [abstract
     [monad {"+" [do]}]]
    [control
     ["[0]" try]
     ["[0]" exception]
     [parser
      ["<[0]>" code]]]
    [data
     ["[0]" text ("[1]#[0]" equivalence)]]
    ["[0]" macro
     [syntax {"+" [syntax:]}]
     ["[0]" code]
     ["[0]" template]]
    ["[0]" math
     ["[0]" random]
     [number
      ["n" nat]]]]]
  [\\library
   ["[0]" /]])

(template.with_locals [g!Foo g!Bar]
  (as_is (template [<syntax> <meta>]
           [(syntax: (<syntax> [])
              (do meta.monad
                [frame <meta>]
                (in (list (code.text (value@ /.#name frame))))))]

           [current /.current]
           [specific (/.specific (template.text [g!Foo]))]
           )

         (syntax: (with_no_active_frames [macro <code>.any])
           (function (_ compiler)
             (let [verdict (case ((macro.expansion macro) compiler)
                             {try.#Failure error}
                             (exception.match? /.no_active_frames error)
                             
                             {try.#Success _}
                             false)]
               {try.#Success [compiler (list (code.bit verdict))]})))

         (with_expansions [no_current! (..with_no_active_frames (..current))
                           no_specific! (..with_no_active_frames (..specific))]
           (/.abstract: (g!Foo a)
             Text

             (/.abstract: (g!Bar a)
               Nat

               (def: .public test
                 Test
                 (<| (_.covering /._)
                     (_.for [/.abstract:])
                     (do random.monad
                       [expected_foo (random.ascii/lower 5)
                        expected_bar random.nat]
                       ($_ _.and
                           (_.cover [/.:abstraction]
                                    (and (exec (: (g!Foo Text)
                                                  (/.:abstraction g!Foo expected_foo))
                                           true)
                                         (exec (: (g!Bar Text)
                                                  (/.:abstraction expected_bar))
                                           true)))
                           (_.cover [/.:representation]
                                    (and (|> expected_foo
                                             (/.:abstraction g!Foo)
                                             (: (g!Foo Bit))
                                             (/.:representation g!Foo)
                                             (text#= expected_foo))
                                         (|> (/.:abstraction expected_bar)
                                             (: (g!Bar Bit))
                                             /.:representation
                                             (n.= expected_bar))))
                           (_.cover [/.:transmutation]
                                    (and (exec (|> expected_foo
                                                   (/.:abstraction g!Foo)
                                                   (: (g!Foo .Macro))
                                                   (/.:transmutation g!Foo)
                                                   (: (g!Foo .Lux)))
                                           true)
                                         (exec (|> (/.:abstraction expected_bar)
                                                   (: (g!Bar .Macro))
                                                   /.:transmutation
                                                   (: (g!Bar .Lux)))
                                           true)))
                           (_.cover [/.^:representation]
                                    (and (let [(/.^:representation g!Foo actual_foo)
                                               (: (g!Foo .Module)
                                                  (/.:abstraction g!Foo expected_foo))]
                                           (text#= expected_foo actual_foo))
                                         (let [(/.^:representation actual_bar)
                                               (: (g!Bar .Module)
                                                  (/.:abstraction expected_bar))]
                                           (n.= expected_bar actual_bar))))
                           (_.for [/.Frame]
                                  ($_ _.and
                                      (_.cover [/.current]
                                               (text#= (template.text [g!Bar])
                                                       (..current)))
                                      (_.cover [/.specific]
                                               (text#= (template.text [g!Foo])
                                                       (..specific)))
                                      (_.cover [/.no_active_frames]
                                               (and no_current!
                                                    no_specific!))
                                      ))
                           )))))))))