aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/metadata/artifact.lux
blob: 5ba4bdbe49206931a7b7c2e6a576fc7abb989bad (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
(.module:
  [library
   [lux #*
    ["_" test (#+ Test)]
    [abstract
     [monad (#+ do)]
     [\\specification
      ["$." equivalence]]]
    [control
     ["." try ("#\." functor)]
     [parser
      ["." environment]
      ["<.>" xml]]
     [concurrency
      ["." promise]]]
    [data
     ["." maybe]
     ["." text ("#\." equivalence)]
     [collection
      ["." list]]]
    [macro
     ["." code]]
    [math
     ["." random (#+ Random)]
     [number
      ["n" nat]]]
    ["." time
     ["." date]
     ["." year]
     ["." month]
     ["." instant]
     ["." duration]]
    [world
     ["." file]
     ["." program]]]]
  [\\program
   ["." /
    ["/#" //
     ["/#" // #_
      ["#." artifact]
      ["#." repository #_
       ["#/." local]]]]]])

(def: #export random
  (Random /.Metadata)
  ($_ random.and
      (random.ascii/alpha 5)
      (random.ascii/alpha 5)
      (random.list 5 (random.ascii/alpha 5))
      (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: #export test
  Test
  (<| (_.covering /._)
      (_.for [/.Metadata])
      (do random.monad
        [expected ..random
         #let [artifact {#///artifact.group (get@ #/.group expected)
                         #///artifact.name (get@ #/.name expected)
                         #///artifact.version (|> expected
                                                  (get@ #/.versions)
                                                  list.head
                                                  (maybe.default ""))}]]
        ($_ _.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))))
            (_.cover [/.uri]
                     (text\= (//.remote_project_uri artifact)
                             (/.uri artifact)))
            (do random.monad
              [home (random.ascii/lower 5)
               working_directory (random.ascii/lower 5)
               #let [program (program.async (program.mock environment.empty home working_directory))
                     fs (file.mock (\ file.default separator))
                     repository (///repository/local.repository program fs)]]
              (wrap (do promise.monad
                      [wrote? (/.write repository artifact expected)
                       actual (/.read repository artifact)]
                      (_.cover' [/.write /.read]
                                (and (case wrote?
                                       (#try.Success _) true
                                       (#try.Failure _) false)
                                     (case actual
                                       (#try.Success actual)
                                       (\ /.equivalence = expected actual)
                                       
                                       (#try.Failure _)
                                       false))))))
            ))))