aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/locale.lux
blob: 8d114aacd8528ef1a410acf1784e72ad1fac94e1 (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
98
(.using
 [library
  [lux (.except)
   ["_" test (.only Test)]
   [abstract
    [monad (.only do)]
    [\\specification
     ["$[0]" equivalence]
     ["$[0]" hash]]]
   [math
    ["[0]" random (.only Random) (.open: "[1]#[0]" monad)]]
   [data
    ["[0]" text (.open: "[1]#[0]" equivalence)
     ["[0]" encoding (.only Encoding)]]
    [collection
     ["[0]" list]]]]]
 ["[0]" /
  ["[1][0]" language]
  ["[1][0]" territory]]
 [\\library
  ["[0]" / (.only)
   ["[0]" language (.only Language)]
   ["[0]" territory (.only Territory)]]])

(def random_language
  (Random Language)
  (random.either (random#in language.afar)
                 (random#in language.zaza)))

(def random_territory
  (Random Territory)
  (random.either (random#in territory.afghanistan)
                 (random#in territory.zimbabwe)))

(def random_encoding
  (Random Encoding)
  (random.either (random#in encoding.ascii)
                 (random#in encoding.koi8_u)))

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

(def .public test
  Test
  (<| (_.covering /._)
      (_.for [/.Locale])
      (all _.and
           (_.for [/.equivalence]
                  ($equivalence.spec /.equivalence ..random_locale))
           (_.for [/.hash]
                  (do [! random.monad]
                    [fixed_language ..random_language
                     fixed_territory ..random_territory
                     fixed_encoding ..random_encoding]
                    (all _.and
                         (|> ..random_language
                             (at ! each (function (_ language)
                                          (/.locale language {.#Some fixed_territory} {.#Some fixed_encoding})))
                             ($hash.spec /.hash))
                         (|> ..random_territory
                             (at ! each (function (_ territory)
                                          (/.locale fixed_language {.#Some territory} {.#Some fixed_encoding})))
                             ($hash.spec /.hash))
                         (|> ..random_encoding
                             (at ! each (function (_ encoding)
                                          (/.locale fixed_language {.#Some fixed_territory} {.#Some encoding})))
                             ($hash.spec /.hash))
                         )))
           
           (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))]]
             (_.coverage [/.locale /.code]
               (and language_check
                    territory_check
                    encoding_check)))
           
           /language.test
           /territory.test
           )))