aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/control/security/capability.lux
blob: e47e715096028f8e2e6451a1629c6e2193d07cc3 (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
(.using
 [library
  [lux (.except)
   ["_" test (.only Test)]
   [abstract
    [monad (.only do)]]
   [control
    ["[0]" io (.only IO)]
    [concurrency
     ["[0]" async]]]
   [math
    ["[0]" random]
    [number
     ["n" nat]]]]]
 [\\library
  ["[0]" /]])

(/.capability: (Can_Shift a)
  (can_shift [a Nat] [a Nat]))

(/.capability: Can_IO
  (can_io [] (IO Nat)))

(def: .public test
  Test
  (<| (_.covering /._)
      (do random.monad
        [shift random.nat
         base random.nat
         .let [expected (n.+ shift base)]
         pass_through (random.ascii 1)]
        (_.for [/.Capability]
               (all _.and
                    (_.coverage [/.capability: /.use]
                      (let [capability (..can_shift (function (_ [no_op raw])
                                                      [no_op (n.+ shift raw)]))
                            [untouched actual] (/.use capability [pass_through base])]
                        (and (same? pass_through untouched)
                             (n.= expected actual))))
                    (in (let [capability (..can_io (function (_ _) (io.io expected)))]
                          (do async.monad
                            [actual (/.use (/.async capability) [])]
                            (_.coverage' [/.async]
                              (n.= expected actual)))))
                    )))))