aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/data/name.lux
blob: 958d236bf70b058860c06611431236315d3aaf5f (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
(.module:
  [library
   [lux #*
    ["_" test (#+ Test)]
    [abstract
     [monad (#+ do)]
     [\\spec
      ["$." equivalence]
      ["$." hash]
      ["$." order]
      ["$." codec]]]
    [control
     pipe]
    [data
     ["." text ("#\." equivalence)]]
    [math
     ["." random (#+ Random)]
     [number
      ["n" nat]]]]]
  [\\library
   ["." /]])

(def: #export (random module_size short_size)
  (-> Nat Nat (Random Name))
  (random.and (random.ascii/alpha module_size)
              (random.ascii/alpha short_size)))

(def: #export test
  Test
  (<| (_.covering /._)
      (do {! random.monad}
        [## First Name
         sizeM1 (|> random.nat (\ ! map (n.% 100)))
         sizeS1 (|> random.nat (\ ! map (|>> (n.% 100) (n.max 1))))
         (^@ name1 [module1 short1]) (..random sizeM1 sizeS1)
         ## Second Name
         sizeM2 (|> random.nat (\ ! map (n.% 100)))
         sizeS2 (|> random.nat (\ ! map (|>> (n.% 100) (n.max 1))))
         (^@ name2 [module2 short2]) (..random sizeM2 sizeS2)]
        (_.for [.Name]
               ($_ _.and
                   (_.for [/.equivalence]
                          ($equivalence.spec /.equivalence (..random sizeM1 sizeS1)))
                   (_.for [/.hash]
                          (|> (random.ascii 1)
                              (\ ! map (|>> [""]))
                              ($hash.spec /.hash)))
                   (_.for [/.order]
                          ($order.spec /.order (..random sizeM1 sizeS1)))
                   (_.for [/.codec]
                          (_.and ($codec.spec /.equivalence /.codec (..random sizeM1 sizeS1))
                                 (let [(^open "/\.") /.codec]
                                   (_.test "Encoding an name without a module component results in text equal to the short of the name."
                                           (if (text.empty? module1)
                                             (text\= short1 (/\encode name1))
                                             #1)))))
                   
                   (_.cover [/.module /.short]
                            (and (is? module1 (/.module name1))
                                 (is? short1 (/.short name1))))
                   (_.for [.name_of]
                          (let [(^open "/\.") /.equivalence]
                            ($_ _.and
                                (_.test "Can obtain Name from identifier."
                                        (and (/\= [.prelude_module "yolo"] (.name_of .yolo))
                                             (/\= ["test/lux/data/name" "yolo"] (.name_of ..yolo))
                                             (/\= ["" "yolo"] (.name_of yolo))
                                             (/\= ["library/lux/test" "yolo"] (.name_of library/lux/test.yolo))))
                                (_.test "Can obtain Name from tag."
                                        (and (/\= [.prelude_module "yolo"] (.name_of #.yolo))
                                             (/\= ["test/lux/data/name" "yolo"] (.name_of #..yolo))
                                             (/\= ["" "yolo"] (.name_of #yolo))
                                             (/\= ["library/lux/test" "yolo"] (.name_of #library/lux/test.yolo)))))))
                   )))))