aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/repository/local.lux
blob: 34ae887d7ac7906c702833d3fe1c1116b19d167c (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
(.module:
  [library
   [lux #*
    ["_" test (#+ Test)]
    [abstract
     [monad (#+ do)]]
    [control
     ["." try ("#\." functor)]
     [parser
      ["." environment]]
     [concurrency
      ["." async]]]
    [data
     ["." binary ("#\." equivalence)]
     [text
      [encoding
       ["." utf8]]]]
    [math
     ["." random]]
    [world
     ["." file]
     ["." program]]]]
  [\\program
   ["." /]])

(def: .public test
  Test
  (<| (_.covering /._)
      (do {! random.monad}
        [/ (random.ascii/upper 1)
         home (random.ascii/lower 10)
         working_directory (random.ascii/lower 10)
         .let [fs (file.mock /)
               program (program.async (program.mock environment.empty home working_directory))
               repo (/.repository program fs)]

         uri (random.ascii/lower 10)
         expected (\ ! each (\ utf8.codec encoded)
                     (random.ascii/lower 10))]
        ($_ _.and
            (in (do async.monad
                  [before_upload (\ repo download uri)
                   _ (\ repo upload uri expected)
                   actual (\ repo download uri)]
                  (_.cover' [/.repository]
                            (and (case before_upload
                                   (#try.Success _) false
                                   (#try.Failure _) true)
                                 (|> actual
                                     (try\each (binary\= expected))
                                     (try.else false))))))
            ))))