aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/parser.lux
blob: 497533fbf5ac5c336305e356dc227aa26e0a53d9 (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
(.module:
  [lux #*
   ["_" test (#+ Test)]
   [abstract
    [monad (#+ do)]
    [hash (#+ Hash)]]
   [control
    [pipe (#+ case>)]
    ["." try]
    [parser
     ["<c>" code]]]
   [data
    ["." text
     ["%" format (#+ format)]]
    [number
     ["n" nat]]
    [collection
     ["." set (#+ Set)]
     ["." dictionary (#+ Dictionary)]
     ["." list ("#@." functor)]]]
   [math
    ["." random (#+ Random) ("#@." monad)]]
   [macro
    ["." code]]]
  {#program
   ["." /
    ["/#" // #_
     ["#" profile]
     ["#." project (#+ Project)]
     ["#." artifact (#+ Artifact)]
     ["#." dependency (#+ Repository Dependency)]
     ["#." format]]]})

(def: distribution
  (Random //.Distribution)
  (random.or (random@wrap [])
             (random@wrap [])))

(def: license
  (Random //.License)
  ($_ random.and
      (random.ascii/alpha 1)
      (random.ascii/alpha 1)
      ..distribution))

(def: scm
  (Random //.SCM)
  (random.ascii/alpha 1))

(def: organization
  (Random //.Organization)
  ($_ random.and
      (random.ascii/alpha 1)
      (random.ascii/alpha 1)))

(def: email
  (Random //.Email)
  (random.ascii/alpha 1))

(def: developer
  (Random //.Developer)
  ($_ random.and
      (random.ascii/alpha 1)
      (random.ascii/alpha 1)
      (random.maybe organization)))

(def: contributor
  (Random //.Contributor)
  ..developer)

(def: (list-of random)
  (All [a] (-> (Random a) (Random (List a))))
  (do {@ random.monad}
    [size (:: @ map (n.% 5) random.nat)]
    (random.list size random)))

(def: (set-of hash random)
  (All [a] (-> (Hash a) (Random a) (Random (Set a))))
  (:: random.functor map
      (set.from-list hash)
      (..list-of random)))

(def: (dictionary-of key-hash key-random value-random)
  (All [k v] (-> (Hash k) (Random k) (Random v) (Random (Dictionary k v))))
  (:: random.functor map
      (dictionary.from-list key-hash)
      (..list-of (random.and key-random value-random))))

(def: info
  (Random //.Info)
  ($_ random.and
      (random.maybe (random.ascii/alpha 1))
      (random.maybe ..scm)
      (random.maybe (random.ascii/alpha 1))
      (..list-of ..license)
      (random.maybe ..organization)
      (..list-of ..developer)
      (..list-of ..contributor)
      ))

(def: name
  (Random //.Name)
  (random.ascii/alpha 1))

(def: artifact
  (Random Artifact)
  ($_ random.and
      (random.ascii/alpha 1)
      (random.ascii/alpha 1)
      (random.ascii/alpha 1)))

(def: repository
  (Random Repository)
  (random.ascii/alpha 1))

(def: dependency
  (Random Dependency)
  ($_ random.and
      ..artifact
      (random.ascii/alpha 1)))

(def: source
  (Random //.Source)
  (random.ascii/alpha 1))

(def: target
  (Random //.Target)
  (random.ascii/alpha 1))

(def: profile
  (Random //.Profile)
  ($_ random.and
      (..list-of ..name)
      (random.maybe ..artifact)
      (random.maybe ..info)
      (..set-of text.hash ..repository)
      (..set-of //dependency.hash ..dependency)
      (..set-of text.hash ..source)
      (random.maybe ..target)
      (random.maybe (random.ascii/alpha 1))
      (random.maybe (random.ascii/alpha 1))
      (..dictionary-of text.hash (random.ascii/alpha 1) ..repository)
      ))

(def: project
  (Random Project)
  (..dictionary-of text.hash ..name ..profile))

(def: with-default-sources
  (-> //.Profile //.Profile)
  (update@ #//.sources
           (: (-> (Set //.Source) (Set //.Source))
              (function (_ sources)
                (if (set.empty? sources)
                  (set.from-list text.hash (list //.default-source))
                  sources)))))

(def: single-profile
  Test
  (do random.monad
    [expected ..profile]
    (_.test "Single profile."
            (|> expected
                //format.profile
                list
                (<c>.run /.project)
                (case> (#try.Success actual)
                       (|> expected
                           ..with-default-sources
                           [//.default]
                           list
                           (dictionary.from-list text.hash)
                           (:: //project.equivalence = actual))
                       
                       (#try.Failure error)
                       false)))))

(def: (with-empty-profile project)
  (-> Project Project)
  (if (dictionary.empty? project)
    //project.empty
    project))

(def: multiple-profiles
  Test
  (do random.monad
    [expected ..project]
    (_.test "Multiple profiles."
            (|> expected
                //format.project
                list
                (<c>.run /.project)
                (case> (#try.Success actual)
                       (|> expected
                           ..with-empty-profile
                           dictionary.entries
                           (list@map (function (_ [name profile])
                                       [name (..with-default-sources profile)]))
                           (dictionary.from-list text.hash)
                           (:: //project.equivalence = actual))
                       
                       (#try.Failure error)
                       false)))))

(def: #export test
  Test
  (<| (_.covering /._)
      (_.with-cover [/.project]
        ($_ _.and
            ..single-profile
            ..multiple-profiles
            ))))