aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/meta/configuration.lux
blob: 9776472d5fb38594e84709a29b0480317cce59ff (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
79
80
81
82
83
84
85
86
87
88
89
90
(.using
 [library
  [lux "*"
   ["_" test {"+" Test}]
   ["[0]" meta]
   [abstract
    [monad {"+" do}]
    [\\specification
     ["$[0]" equivalence]
     ["$[0]" monoid]]]
   [control
    ["[0]" try ("[1]#[0]" functor)]
    ["[0]" exception]
    ["<>" parser
     ["<[0]>" text]
     ["<[0]>" code]]]
   [data
    ["[0]" text]
    [collection
     ["[0]" list]]]
   ["[0]" macro
    [syntax {"+" syntax:}]
    ["[0]" code]]
   [math
    ["[0]" random {"+" Random} ("[1]#[0]" monad)]]]]
 [\\library
  ["[0]" /]])

(def: .public (random amount)
  (-> Nat (Random /.Configuration))
  (case amount
    0 (random#in /.empty)
    _ (do [! random.monad]
        [feature (random.ascii/upper amount)
         value (random.ascii/lower amount)]
        (# ! each (|>> (list& [feature value]))
           (random (-- amount))))))

(syntax: (failure [it <code>.any])
  (function (_ lux)
    (case (macro.expansion it lux)
      {try.#Failure error}
      {try.#Success [lux (list (code.text error))]}
      
      {try.#Success _}
      {try.#Failure ""})))

(def: .public test
  Test
  (<| (_.covering /._)
      (_.for [/.Configuration])
      (do [! random.monad]
        [expected (..random 5)]
        ($_ _.and
            (_.for [/.equivalence]
                   ($equivalence.spec /.equivalence (..random 5)))
            (_.for [/.monoid]
                   ($monoid.spec /.equivalence /.monoid (..random 5)))

            (_.cover [/.empty]
                     (list.empty? /.empty))
            (_.cover [/.format /.parser]
                     (|> expected
                         /.format
                         (<text>.result /.parser)
                         (try#each (# /.equivalence = expected))
                         (try.else false)))
            (_.cover [/.for]
                     (and (and (/.for [["left" "<<<"
                                        "right" ">>>"]
                                       true]
                                      false)
                               (/.for [["left" "<<<"]
                                       true]
                                      false)
                               (/.for [["right" ">>>"]
                                       true]
                                      false))
                          (and (/.for [["yolo" ""]
                                       false]
                                      true)
                               (/.for [["left" "yolo"]
                                       false]
                                      true))))
            (_.cover [/.invalid]
                     (and (text.contains? (value@ exception.#label /.invalid)
                                          (..failure (/.for [])))
                          (text.contains? (value@ exception.#label /.invalid)
                                          (..failure (/.for [["left" "yolo"] false])))))
            ))))