aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/tool/compiler/meta/archive/module/document.lux
blob: 0647858d35d489952173af8dba3a0f834da41cf2 (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
91
92
93
94
95
96
97
(.using
 [library
  [lux (.except)
   ["_" test (.only Test)]
   [abstract
    [monad (.only do)]]
   [control
    ["[0]" pipe]
    ["[0]" try (.open: "[1]#[0]" functor)]
    ["[0]" exception]]
   [data
    ["[0]" binary
     ["[1]F" \\format]
     ["<[1]>" \\parser]]]
   [math
    ["[0]" random]
    [number
     ["[0]" nat]]]]]
 [\\library
  ["[0]" / (.only)
   [///
    ["[1][0]" signature (.open: "[1]#[0]" equivalence)]
    ["[1][0]" key]]]]
 ["[0]" ///
  ["[1][0]" signature]])

(def .public test
  Test
  (<| (_.covering /._)
      (_.for [/.Document])
      (do random.monad
        [signature/0 ///signature.random
         signature/1 (random.only (|>> (/signature#= signature/0) not)
                                  ///signature.random)
         .let [key/0 (/key.key signature/0 0)
               key/1 (/key.key signature/1 0)]
         expected random.nat]
        (all _.and
             (_.coverage [/.document /.content]
               (|> expected
                   (/.document key/0)
                   (/.content key/0)
                   (try#each (same? expected))
                   (try.else false)))
             (_.coverage [/.signature]
               (|> expected
                   (/.document key/0)
                   /.signature
                   (same? signature/0)))
             (_.coverage [/.marked?]
               (and (|> expected
                        (/.document key/0)
                        (/.marked? key/0)
                        (pipe.case
                          {try.#Success it} true
                          {try.#Failure error} false))
                    (|> expected
                        (/.document key/0)
                        (/.marked? key/1)
                        (pipe.case
                          {try.#Success it} false
                          {try.#Failure error} true))))
             (_.coverage [/.invalid_signature]
               (and (|> expected
                        (/.document key/0)
                        (/.content key/1)
                        (pipe.case
                          {try.#Success it}
                          false
                          
                          {try.#Failure error}
                          (exception.match? /.invalid_signature error)))
                    (|> expected
                        (/.document key/0)
                        (/.marked? key/1)
                        (pipe.case
                          {try.#Success it}
                          false
                          
                          {try.#Failure error}
                          (exception.match? /.invalid_signature error)))))
             (_.coverage [/.writer /.parser]
               (|> expected
                   (/.document key/0)
                   (binaryF.result (/.writer binaryF.nat))
                   (<binary>.result (/.parser key/0 <binary>.nat))
                   (pipe.case
                     {try.#Success it}
                     (and (/signature#= signature/0 (/.signature it))
                          (|> it
                              (/.content key/0)
                              (try#each (nat.= expected))
                              (try.else false)))
                     
                     {try.#Failure error}
                     false)))
             ))))