aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/input.lux
blob: dc424afc80bcccbfc694340083da3ef0ab766b92 (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
(.module:
  [lux #*
   ["_" test (#+ Test)]
   [abstract
    [monad (#+ do)]]
   [control
    ["." try (#+ Try)]
    [concurrency
     ["." promise (#+ Promise)]]
    [security
     ["!" capability]]]
   [data
    ["." binary]
    ["." text
     ["%" format (#+ format)]
     ["." encoding]]
    [collection
     ["." set (#+ Set)]]]
   [math
    ["." random (#+ Random)]]
   [world
    ["." file (#+ File)]]]
  [//
   ["@." profile]]
  {#program
   ["." /
    ["/#" // #_
     ["#" profile (#+ Profile)]
     ["#." project]
     ["#." action]
     ["#." format]]]})

(def: (with-default-source sources)
  (-> (Set //.Source) (Set //.Source))
  (if (set.empty? sources)
    (set.add //.default-source sources)
    sources))

(def: #export test
  Test
  (<| (_.covering /._)
      (do {! random.monad}
        [expected (\ ! map (set@ #//.parents (list)) @profile.random)
         #let [fs (: (file.System Promise)
                     (file.mock (\ file.default separator)))]]
        (wrap (do promise.monad
                [verdict (do //action.monad
                           [file (: (Promise (Try (File Promise)))
                                    (file.get-file promise.monad fs //project.file))
                            _ (|> expected
                                  //format.profile
                                  %.code
                                  encoding.to-utf8
                                  (!.use (\ file over-write)))
                            actual (: (Promise (Try Profile))
                                      (/.read promise.monad fs //.default))]
                           (wrap (\ //.equivalence =
                                    (update@ #//.sources ..with-default-source expected)
                                    actual)))]
                (_.cover' [/.read]
                          (try.default false verdict)))))))