blob: 54b29cff70fc389caa9b3ea775447e940e16a3be (
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
|
(.module:
[library
[lux #*
["_" test (#+ Test)]
[abstract
[monad (#+ do)]
[\\spec
["$." equivalence]
["$." hash]]]
[math
["." random (#+ Random) ("#\." monad)]]
[data
["." text ("#\." equivalence)
["." encoding (#+ Encoding)]]
[collection
["." list]]]]]
["." / #_
["#." language]
["#." territory]]
[\\library
["." /
["." 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))
(_.for [/.hash]
(do {! random.monad}
[fixed_language ..random_language
fixed_territory ..random_territory
fixed_encoding ..random_encoding]
($_ _.and
(|> ..random_language
(\ ! map (function (_ language)
(/.locale language (#.Some fixed_territory) (#.Some fixed_encoding))))
($hash.spec /.hash))
(|> ..random_territory
(\ ! map (function (_ territory)
(/.locale fixed_language (#.Some territory) (#.Some fixed_encoding))))
($hash.spec /.hash))
(|> ..random_encoding
(\ ! map (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))]]
(_.cover [/.locale /.code]
(and language_check
territory_check
encoding_check)))
/language.test
/territory.test
)))
|