aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/meta/symbol.lux
blob: cdd0517704c8d6913d9690f934c64e6be52264ea (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
(.using
  [library
   [lux "*"
    ["_" test {"+" Test}]
    [abstract
     [monad {"+" do}]
     [\\specification
      ["$[0]" equivalence]
      ["$[0]" hash]
      ["$[0]" order]
      ["$[0]" codec]]]
    [control
     pipe]
    [data
     ["[0]" text ("[1]#[0]" equivalence)]]
    [math
     ["[0]" random {"+" Random}]
     [number
      ["n" nat]]]]]
  [\\library
   ["[0]" /]])

(def: .public (random module_size short_size)
  (-> Nat Nat (Random Symbol))
  (random.and (random.ascii/alpha module_size)
              (random.ascii/alpha short_size)))

(def: .public test
  Test
  (<| (_.covering /._)
      (do [! random.monad]
        [... First Symbol
         sizeM1 (|> random.nat (# ! each (n.% 100)))
         sizeS1 (|> random.nat (# ! each (|>> (n.% 100) (n.max 1))))
         (^@ symbol1 [module1 short1]) (..random sizeM1 sizeS1)
         ... Second Symbol
         sizeM2 (|> random.nat (# ! each (n.% 100)))
         sizeS2 (|> random.nat (# ! each (|>> (n.% 100) (n.max 1))))
         (^@ symbol2 [module2 short2]) (..random sizeM2 sizeS2)]
        (_.for [.Symbol]
               ($_ _.and
                   (_.for [/.equivalence]
                          ($equivalence.spec /.equivalence (..random sizeM1 sizeS1)))
                   (_.for [/.hash]
                          (|> (random.ascii 1)
                              (# ! each (|>> [""]))
                              ($hash.spec /.hash)))
                   (_.for [/.order]
                          ($order.spec /.order (..random sizeM1 sizeS1)))
                   (_.for [/.codec]
                          (_.and ($codec.spec /.equivalence /.codec (..random sizeM1 sizeS1))
                                 (let [(^open "/#[0]") /.codec]
                                   (_.test "Encoding a symbol without a module component results in text equal to the short of the symbol."
                                           (if (text.empty? module1)
                                             (text#= short1 (/#encoded symbol1))
                                             #1)))))
                   
                   (_.cover [/.module /.short]
                            (and (same? module1 (/.module symbol1))
                                 (same? short1 (/.short symbol1))))
                   (_.for [.symbol]
                          (let [(^open "/#[0]") /.equivalence]
                            ($_ _.and
                                (_.test "Can obtain Symbol from a symbol."
                                        (and (/#= [.prelude_module "yolo"] (.symbol .yolo))
                                             (/#= ["test/lux/meta/symbol" "yolo"] (.symbol ..yolo))
                                             (/#= ["" "yolo"] (.symbol yolo))
                                             (/#= ["library/lux/test" "yolo"] (.symbol library/lux/test.yolo)))))))
                   )))))