aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/input.lux
blob: b9f8195f625821c12ebe7cf12826e3200b71aba7 (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
(.require
 [library
  [lux (.except)
   [abstract
    [monad (.only do)]]
   [control
    ["[0]" try (.only Try)]
    [concurrency
     ["[0]" async (.only Async)]]]
   [data
    [text
     ["%" \\format]
     [encoding
      ["[0]" utf8]]]
    [collection
     ["[0]" set (.only Set)]]]
   [math
    ["[0]" random]]
   [world
    ["[0]" file]]
   ["_" test (.only Test)
    ["[0]" unit]]]]
 [//
  ["$[0]" profile]]
 [\\program
  ["[0]" / (.only)
   ["/[1]" //
    ["[1]" profile (.only Profile)]
    ["[1][0]" project]
    ["[1][0]" action]
    ["[1][0]" format]
    [repository
     [remote (.only Address)]]]]])

(def (with_default_source sources)
  (-> (Set //.Source) (Set //.Source))
  (if (set.empty? sources)
    (set.has //.default_source sources)
    sources))

(def with_default_repository
  (-> (Set Address) (Set Address))
  (set.has //.default_repository))

(def .public test
  Test
  (<| (_.covering /._)
      (do [! random.monad]
        [expected (at ! each (has //.#parents (list)) $profile.random)
         .let [fs (is (file.System Async)
                      (file.mock (at file.default separator)))]]
        (in (do async.monad
              [verdict (do //action.monad
                         [.let [profile (|> expected
                                            (//project.project //.default)
                                            //format.project
                                            %.code
                                            (at utf8.codec encoded))]
                          _ (at fs write //project.file profile)
                          actual (is (Async (Try Profile))
                                     (/.read async.monad fs (list //.default)))]
                         (in (at //.equivalence =
                                 (|> expected
                                     (revised //.#sources ..with_default_source)
                                     (revised //.#repositories ..with_default_repository))
                                 actual)))]
              (unit.coverage [/.read]
                (try.else false verdict)))))))