aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/metadata/snapshot.lux
blob: 1858cae257d88efeedd9c36384c4498229f4048d (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
(.module:
  [lux #*
   ["_" test (#+ Test)]
   [abstract
    [monad (#+ do)]
    {[0 #spec]
     [/
      ["$." equivalence]]}]
   [control
    ["." try ("#\." functor)]
    [parser
     ["<.>" xml]]]
   [math
    [number
     ["n" nat]]]
   ["." time
    ["." date]
    ["." year]
    ["." month]
    ["." instant (#+ Instant)]
    ["." duration]]
   [math
    ["." random (#+ Random) ("#\." monad)]]
   [macro
    ["." code]]]
  ["$." /// #_
   ["#." artifact
    ["#/." type]
    ["#/." time]
    ["#/." snapshot #_
     ["#/." version]]]]
  {#program
   ["." /
    [///
     [artifact
      [versioning (#+ Versioning)]
      ["#." snapshot]]]]})

(def: random_instant
  (Random Instant)
  (do {! random.monad}
    [year (\ ! map (|>> (n.% 9,000) (n.+ 1,000) .int) random.nat)
     month (\ ! map (|>> (n.% 12) (n.+ 1)) random.nat)
     day_of_month (\ ! map (|>> (n.% 28) (n.+ 1)) random.nat)
     hour (\ ! map (n.% 24) random.nat)
     minute (\ ! map (n.% 60) random.nat)
     second (\ ! map (n.% 60) random.nat)]
    (wrap (try.assume
           (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})]
             (wrap (instant.from_date_time date time)))))))

(def: random_versioning
  (Random Versioning)
  ($_ random.and
      (random\wrap #/snapshot.Local)
      $///artifact/time.random
      (random.list 5 $///artifact/snapshot/version.random)
      ))

(def: #export random
  (Random /.Metadata)
  ($_ random.and
      $///artifact.random
      ..random_versioning
      ))

(def: #export test
  Test
  (<| (_.covering /._)
      (_.for [/.Metadata])
      ($_ _.and
          (_.for [/.equivalence]
                 ($equivalence.spec /.equivalence ..random))
          (do random.monad
            [expected ..random]
            (_.cover [/.format /.parser]
                     (|> expected
                         /.format
                         list
                         (<xml>.run /.parser)
                         (try\map (\ /.equivalence = expected))
                         (try.default false))))
          )))