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

(def: #export test
  Test
  (<| (_.covering /._)
      (do random.monad
        [sample @profile.random
         #let [fs (file.mock (:: file.default separator))]]
        (wrap (do {! promise.monad}
                [outcome (/.do! fs sample)]
                (case outcome
                  (#try.Success path)
                  (do !
                    [verdict (do ///action.monad
                               [expected (|> (///pom.write sample)
                                             (try@map (|>> (:: xml.codec encode) encoding.to-utf8))
                                             (:: ! wrap))
                                file (: (Promise (Try (File Promise)))
                                        (file.get-file promise.monad fs path))
                                actual (!.use (:: file content) [])

                                #let [expected-path!
                                      (text@= ///pom.file path)

                                      expected-content!
                                      (:: binary.equivalence = expected actual)]]
                               (wrap (and expected-path!
                                          expected-content!)))]
                    (_.claim [/.do!]
                             (try.default false verdict)))
                  
                  (#try.Failure error)
                  (_.claim [/.do!]
                           (case (get@ #///.identity sample)
                             (#.Some _)
                             false

                             #.None
                             true))))))))