aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/meta/compiler/language/lux/phase/analysis/reference.lux
blob: e88482764489cc13f1c47037daeec701a003bda6 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
(.require
 [library
  [lux (.except)
   ["_" test (.only Test)]
   [abstract
    [monad (.only do)]]
   [control
    ["[0]" pipe]
    ["[0]" try (.use "[1]#[0]" functor)]
    ["[0]" exception]]
   [data
    ["[0]" product]
    ["[0]" text]]
   [math
    ["[0]" random]]
   [meta
    ["[0]" type (.use "[1]#[0]" equivalence)
     ["$[1]" \\test]]]]]
 [\\library
  ["[0]" / (.only)
   ["/[1]" //
    [//
     ["[1][0]" extension]
     [//
      ["[1][0]" analysis (.only)
       ["[2][0]" scope]
       ["[2][0]" module]
       ["[2][0]" type (.only)
        ["$[1]" \\test]]]
      [///
       ["[1][0]" phase (.use "[1]#[0]" monad)]]]]]]])

(def .public test
  Test
  (<| (_.covering /._)
      (do [! random.monad]
        [lux $//type.random_state
         .let [state [//extension.#bundle //extension.empty
                      //extension.#state lux]]
         expected_name (random.lower_case 1)
         expected_type ($type.random 0)
         expected_module (random.lower_case 2)
         import (random.lower_case 3)
         expected_label (random.lower_case 4)
         record? random.bit]
        (all _.and
             (_.coverage [/.reference]
               (let [can_find_local_variable!
                     (|> (/.reference ["" expected_name])
                         (//scope.with_local [expected_name expected_type])
                         //type.inferring
                         //scope.with
                         (//module.with 0 expected_module)
                         (//phase#each product.right)
                         (//phase.result state)
                         (try#each (|>> product.right
                                        (pipe.case
                                          [actual_type (//analysis.local 0)]
                                          (type#= expected_type actual_type)

                                          _
                                          false)))
                         (try.else false))

                     can_find_foreign_variable!
                     (|> (/.reference ["" expected_name])
                         //type.inferring
                         //scope.with
                         (//scope.with_local [expected_name expected_type])
                         //scope.with
                         (//module.with 0 expected_module)
                         (//phase#each product.right)
                         (//phase.result state)
                         (try#each (|>> product.right
                                        product.right
                                        (pipe.case
                                          [actual_type (//analysis.foreign 0)]
                                          (type#= expected_type actual_type)

                                          _
                                          false)))
                         (try.else false))

                     can_find_local_definition!
                     (|> (do //phase.monad
                           [_ (//module.define expected_name {.#Definition [#0 expected_type []]})]
                           (/.reference ["" expected_name]))
                         //type.inferring
                         (//module.with 0 expected_module)
                         (//phase.result state)
                         (try#each (|>> product.right
                                        (pipe.case
                                          [actual_type (//analysis.constant [actual_module actual_name])]
                                          (and (type#= expected_type actual_type)
                                               (same? expected_module actual_module)
                                               (same? expected_name actual_name))

                                          _
                                          false)))
                         (try.else false))

                     can_find_foreign_definition!
                     (|> (do //phase.monad
                           [_ (//module.with 0 import
                                (//module.define expected_name {.#Definition [#1 expected_type []]}))
                            _ (//module.import import)]
                           (/.reference [import expected_name]))
                         //type.inferring
                         (//module.with 0 expected_module)
                         (//phase.result state)
                         (try#each (|>> product.right
                                        (pipe.case
                                          [actual_type (//analysis.constant [actual_module actual_name])]
                                          (and (type#= expected_type actual_type)
                                               (same? import actual_module)
                                               (same? expected_name actual_name))

                                          _
                                          false)))
                         (try.else false))

                     can_find_alias!
                     (|> (do //phase.monad
                           [_ (//module.with 0 import
                                (//module.define expected_name {.#Definition [#1 expected_type []]}))
                            _ (//module.import import)
                            _ (//module.define expected_name {.#Alias [import expected_name]})]
                           (/.reference [expected_module expected_name]))
                         //type.inferring
                         (//module.with 0 expected_module)
                         (//phase.result state)
                         (try#each (|>> product.right
                                        (pipe.case
                                          [actual_type (//analysis.constant [actual_module actual_name])]
                                          (and (type#= expected_type actual_type)
                                               (same? import actual_module)
                                               (same? expected_name actual_name))

                                          _
                                          false)))
                         (try.else false))

                     can_find_type!
                     (|> (do //phase.monad
                           [_ (//module.define expected_name {.#Type [#0 expected_type
                                                                      (if record?
                                                                        {.#Right [expected_label (list)]}
                                                                        {.#Left [expected_label (list)]})]})]
                           (/.reference [expected_module expected_name]))
                         //type.inferring
                         (//module.with 0 expected_module)
                         (//phase.result state)
                         (try#each (|>> product.right
                                        (pipe.case
                                          [actual_type (//analysis.constant [actual_module actual_name])]
                                          (and (type#= .Type actual_type)
                                               (same? expected_module actual_module)
                                               (same? expected_name actual_name))

                                          _
                                          false)))
                         (try.else false))]
                 (and can_find_local_variable!
                      can_find_foreign_variable!
                      
                      can_find_local_definition!
                      can_find_foreign_definition!

                      can_find_alias!
                      can_find_type!)))
             (_.coverage [/.foreign_module_has_not_been_imported]
               (let [scenario (is (-> Type Global Bit)
                                  (function (_ expected_type it)
                                    (|> (do //phase.monad
                                          [_ (//module.with 0 import
                                               (//module.define expected_name it))
                                           _ (/.reference [import expected_name])]
                                          (in false))
                                        (//type.expecting expected_type)
                                        (//module.with 0 expected_module)
                                        (//phase#each product.right)
                                        (//phase.result state)
                                        (exception.otherwise (text.contains? (the exception.#label /.foreign_module_has_not_been_imported)))
                                        )))]
                 (and (scenario expected_type {.#Definition [#1 expected_type []]})
                      (scenario .Type {.#Type [#1 expected_type
                                               (if record?
                                                 {.#Right [expected_label (list)]}
                                                 {.#Left [expected_label (list)]})]}))))
             (_.coverage [/.definition_has_not_been_exported]
               (let [scenario (is (-> Type Global Bit)
                                  (function (_ expected_type it)
                                    (|> (do //phase.monad
                                          [_ (//module.with 0 import
                                               (//module.define expected_name it))
                                           _ (/.reference [import expected_name])]
                                          (in false))
                                        (//type.expecting expected_type)
                                        (//module.with 0 expected_module)
                                        (//phase#each product.right)
                                        (//phase.result state)
                                        (exception.otherwise (text.contains? (the exception.#label /.definition_has_not_been_exported)))
                                        )))]
                 (and (scenario expected_type {.#Definition [#0 expected_type []]})
                      (scenario .Type {.#Type [#0 expected_type
                                               (if record?
                                                 {.#Right [expected_label (list)]}
                                                 {.#Left [expected_label (list)]})]}))))
             (_.coverage [/.labels_are_not_definitions]
               (let [scenario (is (-> Type Global Bit)
                                  (function (_ expected_type it)
                                    (|> (do //phase.monad
                                          [_ (//module.with 0 import
                                               (//module.define expected_label it))
                                           _ (/.reference [import expected_label])]
                                          (in false))
                                        (//type.expecting expected_type)
                                        (//module.with 0 expected_module)
                                        (//phase#each product.right)
                                        (//phase.result state)
                                        (exception.otherwise (text.contains? (the exception.#label /.labels_are_not_definitions))))))]
                 (and (scenario expected_type {.#Tag [#1 expected_type (list) 0]})
                      (scenario expected_type {.#Slot [#1 expected_type (list) 0]}))))
             ))))