aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/world/program.lux
blob: 3067422e09598b2c4f0a12afdca80aa00e91f470 (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
(.using
 [library
  [lux (.except)
   ["_" test (.only Test)]
   [abstract
    [monad (.only do)]]
   [control
    ["[0]" pipe]
    ["[0]" io]
    ["[0]" maybe (.open: "[1]#[0]" functor)]
    ["[0]" try]
    ["[0]" exception]
    [parser
     [environment (.only Environment)]]]
   [data
    ["[0]" text (.open: "[1]#[0]" equivalence)]
    [collection
     ["[0]" dictionary]
     ["[0]" list]]]
   [math
    ["[0]" random (.only Random)]
    [number
     ["n" nat]]]]]
 [\\library
  ["[0]" / (.only)
   [//
    [file (.only Path)]]]]
 [\\specification
  ["$[0]" /]])

(def: (environment env_size)
  (-> Nat (Random Environment))
  (random.dictionary text.hash env_size
                     (random.alphabetic 5)
                     (random.alphabetic 5)))

(def: path
  (Random Path)
  (random.alphabetic 5))

(def: .public test
  Test
  (<| (_.covering /._)
      (do [! random.monad]
        [env_size (at ! each (|>> (n.% 10) ++) random.nat)
         environment (..environment env_size)
         home ..path
         directory ..path

         unknown (random.alphabetic 1)]
        (all _.and
             (_.for [/.mock /.async]
                    ($/.spec (/.async (/.mock environment home directory))))
             (_.coverage [/.environment]
               (let [program (/.mock environment home directory)]
                 (io.run!
                  (do io.monad
                    [actual (/.environment io.monad program)]
                    (in (and (n.= (dictionary.size environment)
                                  (dictionary.size actual))
                             (|> actual
                                 dictionary.entries
                                 (list.every? (function (_ [key value])
                                                (|> environment
                                                    (dictionary.value key)
                                                    (maybe#each (text#= value))
                                                    (maybe.else false)))))))))))
             (_.coverage [/.unknown_environment_variable]
               (let [program (/.mock environment home directory)]
                 (|> unknown
                     (at program variable)
                     io.run!
                     (pipe.case {try.#Success _}
                       false
                       
                       {try.#Failure error}
                       (exception.match? /.unknown_environment_variable error)))))
             ))))