aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/meta/symbol.lux
blob: 261015a31d5ae30fd583e4a6ca85d8bad9870080 (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
(.using
 [library
  [lux "*"
   ["_" test {"+" Test}]
   [abstract
    [monad {"+" do}]
    [\\specification
     ["$[0]" equivalence]
     ["$[0]" hash]
     ["$[0]" order]
     ["$[0]" codec]]]
   [data
    ["[0]" text]]
   [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))))
         (^let symbol1 [module1 short1]) (..random sizeM1 sizeS1)
         ... Second Symbol
         sizeM2 (|> random.nat (# ! each (n.% 100)))
         sizeS2 (|> random.nat (# ! each (|>> (n.% 100) (n.max 1))))
         (^let 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))
                                 (_.test "Encoding a symbol without a module component results in text equal to the short of the symbol."
                                         (if (text.empty? module1)
                                           (same? short1 (# /.codec encoded symbol1))
                                           #1))))

                   (_.cover [/.separator]
                            (let [it (# /.codec encoded symbol1)]
                              (if (text.empty? module1)
                                (same? short1 it)
                                (text.contains? /.separator it))))
                   (_.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)))))))
                   )))))