aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/locale.lux
blob: 5693eb2c4317f9926ea4231e0a0d5200298f546b (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
(.module:
  [lux #*
   ["_" test (#+ Test)]
   [abstract
    [monad (#+ do)]
    {[0 #spec]
     [/
      ["$." equivalence]]}]
   [math
    ["." random (#+ Random) ("#\." monad)]]
   [data
    ["." text ("#\." equivalence)
     ["." encoding (#+ Encoding)]]
    [collection
     ["." list]]]]
  ["." / #_
   ["#." language]
   ["#." territory]]
  {1
   ["." /
    ["." language (#+ Language)]
    ["." territory (#+ Territory)]]})

(def: random_language
  (Random Language)
  (random.either (random\wrap language.afar)
                 (random\wrap language.zaza)))

(def: random_territory
  (Random Territory)
  (random.either (random\wrap territory.afghanistan)
                 (random\wrap territory.zimbabwe)))

(def: random_encoding
  (Random Encoding)
  (random.either (random\wrap encoding.ascii)
                 (random\wrap encoding.koi8_u)))

(def: random_locale
  (Random /.Locale)
  (do random.monad
    [language ..random_language
     territory ..random_territory
     encoding ..random_encoding]
    (wrap (/.locale language (#.Some territory) (#.Some encoding)))))

(def: #export test
  Test
  (<| (_.covering /._)
      (_.for [/.Locale])
      ($_ _.and
          (_.for [/.equivalence]
                 ($equivalence.spec /.equivalence ..random_locale))
          
          (do random.monad
            [language ..random_language
             territory ..random_territory
             encoding ..random_encoding
             #let [l_locale (/.locale language #.None #.None)
                   lt_locale (/.locale language (#.Some territory) #.None)
                   le_locale (/.locale language #.None (#.Some encoding))
                   lte_locale (/.locale language (#.Some territory) (#.Some encoding))]
             #let [language_check (and (text\= (language.code language)
                                               (/.code l_locale))
                                       (list.every? (|>> /.code (text.starts_with? (language.code language)))
                                                    (list lt_locale le_locale lte_locale)))
                   territory_check (list.every? (|>> /.code (text.contains? (territory.long_code territory)))
                                                (list lt_locale lte_locale))
                   encoding_check (list.every? (|>> /.code (text.ends_with? (encoding.name encoding)))
                                               (list le_locale lte_locale))]]
            (_.cover [/.locale /.code]
                     (and language_check
                          territory_check
                          encoding_check)))
          
          /language.test
          /territory.test
          )))