aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/tool/compiler/meta/archive/registry.lux
blob: 893f1da72f28d6b2aef5330313bdbfbd8572af80 (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
(.using
 [library
  [lux "*"
   ["_" test {"+" Test}]
   [abstract
    [monad {"+" do}]]
   [control
    ["[0]" maybe ("[1]#[0]" functor)]
    ["[0]" try ("[1]#[0]" functor)]
    [parser
     ["<[0]>" binary]]]
   [data
    ["[0]" product]
    ["[0]" text]
    [collection
     ["[0]" sequence {"+" Sequence}]
     ["[0]" set {"+" Set}]
     ["[0]" list ("[1]#[0]" mix functor)]]
    [format
     ["[0]" binary]]]
   [math
    ["[0]" random {"+" Random}]
    [number
     ["n" nat]]]]]
 [\\library
  ["[0]" /
   [//
    ["[0]" unit]
    ["[0]" artifact
     ["[0]" category]]]]])

(template: (tagged? <tag> <it>)
  [(case <it>
     {<tag> _}
     true
     
     _
     false)])

(def: random_dependency
  (Random unit.ID)
  ($_ random.and
      random.nat
      random.nat
      ))

(def: (random_dependencies amount)
  (-> Nat (Random (Set unit.ID)))
  (random.set unit.hash amount ..random_dependency))

(def: .public test
  Test
  (<| (_.covering /._)
      (_.for [/.Registry])
      (do [! random.monad]
        [expected_name (random.ascii/lower 5)
         mandatory? random.bit
         expected_dependencies (..random_dependencies 5)
         
         expected_amount (# ! each (n.% 10) random.nat)
         expected_names (|> (random.ascii/lower 1)
                            (random.set text.hash expected_amount)
                            (# ! each set.list))]
        (`` ($_ _.and
                (_.cover [/.empty]
                         (|> /.empty
                             /.artifacts
                             sequence.size
                             (n.= 0)))
                (_.cover [/.resource]
                         (let [[@it registry] (/.resource mandatory? expected_dependencies /.empty)]
                           (case (sequence.list (/.artifacts registry))
                             (^ (list [artifact actual_dependencies]))
                             (and (same? @it (value@ artifact.#id artifact))
                                  (same? mandatory? (value@ artifact.#mandatory? artifact))
                                  (tagged? category.#Anonymous (value@ artifact.#category artifact))
                                  (same? expected_dependencies actual_dependencies))

                             _
                             false)))
                (~~ (template [<new> <expected>' <query> <tag> <wrong_new> <wrong_expected>']
                      [(_.cover [<new> <query>]
                                (let [<expected> <expected>'
                                      <wrong_expected> <wrong_expected>']
                                  (and (let [[@it registry] (<new> <expected> mandatory? expected_dependencies /.empty)]
                                         (and (case (<query> registry)
                                                (^ (list actual_name))
                                                (same? <expected> actual_name)

                                                _
                                                false)
                                              (case (sequence.list (/.artifacts registry))
                                                (^ (list [artifact actual_dependencies]))
                                                (and (same? @it (value@ artifact.#id artifact))
                                                     (same? mandatory? (value@ artifact.#mandatory? artifact))
                                                     (case (value@ artifact.#category artifact)
                                                       {<tag> actual_name}
                                                       (same? <expected> actual_name)

                                                       _
                                                       false)
                                                     (same? expected_dependencies actual_dependencies))

                                                _
                                                false)))
                                       (let [[@it registry] (<wrong_new> <wrong_expected> mandatory? expected_dependencies /.empty)]
                                         (case (<query> registry)
                                           (^ (list))
                                           true

                                           _
                                           false)))))]

                      [/.definition (: category.Definition [expected_name {.#None}]) /.definitions category.#Definition /.analyser expected_name]
                      [/.analyser expected_name /.analysers category.#Analyser /.synthesizer expected_name]
                      [/.synthesizer expected_name /.synthesizers category.#Synthesizer /.generator expected_name]
                      [/.generator expected_name /.generators category.#Generator /.directive expected_name]
                      [/.directive expected_name /.directives category.#Directive /.custom expected_name]
                      [/.custom expected_name /.customs category.#Custom /.definition (: category.Definition [expected_name {.#None}])]
                      ))
                (_.cover [/.id]
                         (and (~~ (template [<new> <expected>' <name>]
                                    [(let [<expected> <expected>'
                                           [@expected registry] (<new> <expected> mandatory? expected_dependencies /.empty)]
                                       (|> (/.id (<name> <expected>) registry)
                                           (maybe#each (same? @expected))
                                           (maybe.else false)))]

                                    [/.definition (: category.Definition [expected_name {.#None}]) product.left]
                                    [/.analyser expected_name |>]
                                    [/.synthesizer expected_name |>]
                                    [/.generator expected_name |>]
                                    [/.directive expected_name |>]
                                    [/.custom expected_name |>]
                                    ))))
                (_.cover [/.artifacts]
                         (and (~~ (template [<new> <query> <equivalence> <$>]
                                    [(let [expected/* (list#each <$> expected_names)
                                           [ids registry] (: [(Sequence artifact.ID) /.Registry]
                                                             (list#mix (function (_ expected [ids registry])
                                                                         (let [[@new registry] (<new> expected mandatory? expected_dependencies registry)]
                                                                           [(sequence.suffix @new ids) registry]))
                                                                       [sequence.empty /.empty]
                                                                       expected/*))
                                           it (/.artifacts registry)]
                                       (and (n.= expected_amount (sequence.size it))
                                            (list.every? (function (_ [@it [it dependencies]])
                                                           (same? @it (value@ artifact.#id it)))
                                                         (list.zipped/2 (sequence.list ids) (sequence.list it)))
                                            (# (list.equivalence <equivalence>) = expected/* (<query> registry))))]

                                    [/.definition /.definitions category.definition_equivalence (: (-> Text category.Definition)
                                                                                                   (function (_ it)
                                                                                                     [it {.#None}]))]
                                    [/.analyser /.analysers text.equivalence (|>>)]
                                    [/.synthesizer /.synthesizers text.equivalence (|>>)]
                                    [/.generator /.generators text.equivalence (|>>)]
                                    [/.directive /.directives text.equivalence (|>>)]
                                    [/.custom /.customs text.equivalence (|>>)]
                                    ))))
                (_.cover [/.writer /.parser]
                         (and (~~ (template [<new> <expected>' <name>]
                                    [(let [<expected> <expected>'
                                           [@expected before] (<new> <expected> mandatory? expected_dependencies /.empty)]
                                       (|> before
                                           (binary.result /.writer)
                                           (<binary>.result /.parser)
                                           (try#each (|>> (/.id (<name> <expected>))
                                                          (maybe#each (same? @expected))
                                                          (maybe.else false)))
                                           (try.else false)))]

                                    [/.definition (: category.Definition [expected_name {.#None}]) product.left]
                                    [/.analyser expected_name |>]
                                    [/.synthesizer expected_name |>]
                                    [/.generator expected_name |>]
                                    [/.directive expected_name |>]
                                    [/.custom expected_name |>]
                                    ))))
                )))))