aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/metadata/snapshot.lux
blob: 2283afd1921db6a52e266b377b5f46a65bd95555 (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
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

(.require
 [library
  [lux (.except)
   [abstract
    [monad (.only do)]
    ["[0]" equivalence
     ["[1]T" \\test]]]
   [control
    ["[0]" maybe]
    ["[0]" try (.use "[1]#[0]" functor)]
    [concurrency
     ["[0]" async]]]
   [data
    ["[0]" text (.use "[1]#[0]" equivalence)]
    [format
     ["[0]" xml
      ["<[1]>" \\parser]]]
    [collection
     ["[0]" list]]]
   [math
    ["[0]" random (.only Random) (.use "[1]#[0]" monad)]
    [number
     ["n" nat]]]
   [meta
    ["[0]" code]]
   [world
    ["[0]" file]
    ["[0]" environment
     ["program" /]
     ["[1]" \\parser]]
    ["[0]" time (.only)
     ["[0]" date]
     ["[0]" year]
     ["[0]" month]
     ["[0]" instant (.only Instant)]
     ["[0]" duration]]]
   [test
    ["[0]" unit]
    ["_" property (.only Test)]]]]
 ["$[0]" ///
  ["[1][0]" artifact (.only)
   ["[1]/[0]" type]
   ["[1]/[0]" time]
   ["[1]/[0]" snapshot
    ["[1]/[0]" version]]]]
 [\\program
  ["[0]" / (.only)
   ["/[1]" // (.only)
    ["/[1]" //
     [artifact
      [versioning (.only Versioning)]
      ["[1][0]" snapshot]]
     ["[1][0]" repository
      ["[1]/[0]" local]]]]]])

(def random_instant
  (Random Instant)
  (do [! random.monad]
    [year (of ! each (|>> (n.% 9,000) (n.+ 1,000) .int) random.nat)
     month (of ! each (|>> (n.% 12) (n.+ 1)) random.nat)
     day_of_month (of ! each (|>> (n.% 28) (n.+ 1)) random.nat)
     hour (of ! each (n.% 24) random.nat)
     minute (of ! each (n.% 60) random.nat)
     second (of ! each (n.% 60) random.nat)]
    (in (try.trusted
         (do try.monad
           [year (year.year year)
            month (month.by_number month)
            date (date.date year month day_of_month)
            time (time.time
                  [time.#hour hour
                   time.#minute minute
                   time.#second second
                   time.#milli_second 0])]
           (in (instant.of_date_time date time)))))))

(def random_versioning
  (Random Versioning)
  (all random.and
       (random#in {///snapshot.#Local})
       $///artifact/time.random
       (random.list 5 $///artifact/snapshot/version.random)
       ))

(def .public random
  (Random /.Metadata)
  (all random.and
       $///artifact.random
       ..random_versioning
       ))

(def .public test
  Test
  (<| (_.covering /._)
      (_.for [/.Metadata])
      (do random.monad
        [expected ..random
         .let [artifact (the /.#artifact expected)]]
        (all _.and
             (_.for [/.equivalence]
                    (equivalenceT.spec /.equivalence ..random))
             
             (_.coverage [/.format /.parser]
               (|> expected
                   /.format
                   list
                   (<xml>.result /.parser)
                   (try#each (of /.equivalence = expected))
                   (try.else false)))
             (_.coverage [/.uri]
               (text#= (//.remote_artifact_uri artifact)
                       (/.uri artifact)))
             (do random.monad
               [home (random.lower_cased 5)
                working_directory (random.lower_cased 5)
                .let [program (program.async (program.mock environment.empty home working_directory))
                      fs (file.mock (of file.default separator))
                      repository (///repository/local.repository program fs)]]
               (in (do async.monad
                     [wrote? (/.write repository artifact expected)
                      actual (/.read repository artifact)]
                     (unit.coverage [/.write /.read]
                       (and (when wrote?
                              {try.#Success _} true
                              {try.#Failure _} false)
                            (when actual
                              {try.#Success actual}
                              (of /.equivalence = expected actual)
                              
                              {try.#Failure _}
                              false))))))
             ))))