aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/type/resource.lux
blob: 298b95ad7be24b09da53d32b603e0e62ff7d9dc9 (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
(.module:
  [lux #*
   ["%" data/text/format (#+ format)]
   ["r" math/random (#+ Random)]
   ["_" test (#+ Test)]
   [abstract
    [monad
     [indexed (#+ do)]]]
   [control
    ["." io]]
   [data
    [number
     ["n" nat]]]]
  {1
   ["." / (#+ Res)]})

(def: #export test
  Test
  (<| (_.context (%.name (name-of /._)))
      ($_ _.and
          (_.test "Can produce and consume keys in an ordered manner."
                  (<| (n.= (n.+ 123 456))
                      io.run
                      /.run-sync
                      (do /.sync
                        [res|left (/.ordered-sync 123)
                         res|right (/.ordered-sync 456)
                         right (/.read-sync res|right)
                         left (/.read-sync res|left)]
                        (wrap (n.+ left right)))))
          (_.test "Can exchange commutative keys."
                  (<| (n.= (n.+ 123 456))
                      io.run
                      /.run-sync
                      (do /.sync
                        [res|left (/.commutative-sync 123)
                         res|right (/.commutative-sync 456)
                         _ (/.exchange-sync [1 0])
                         left (/.read-sync res|left)
                         right (/.read-sync res|right)]
                        (wrap (n.+ left right)))))
          (_.test "Can group and un-group keys."
                  (<| (n.= (n.+ 123 456))
                      io.run
                      /.run-sync
                      (do /.sync
                        [res|left (/.commutative-sync 123)
                         res|right (/.commutative-sync 456)
                         _ (/.group-sync 2)
                         _ (/.un-group-sync 2)
                         right (/.read-sync res|right)
                         left (/.read-sync res|left)]
                        (wrap (n.+ left right)))))
          )))