blob: 7c9267b1689ac30881585cfeb93c25ddd6d51dfe (
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
|
(.module:
[library
[lux (#- char)
["_" test (#+ Test)]
[abstract
[monad (#+ Monad do)]
[\\specification
["$." equivalence]
["$." codec]]]
[control
pipe
["." try]
["p" parser
["</>" xml]]]
[data
["." name]
["." maybe]
["." text ("#\." equivalence)
["%" format (#+ format)]]
[collection
["." dictionary]
["." list ("#\." functor)]]]
[math
["." random (#+ Random) ("#\." monad)]
[number
["n" nat]]]]]
[\\library
["." / (#+ XML)]])
(def: char_range
Text
(format "_"
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
(def: char
(Random Nat)
(do {! random.monad}
[idx (|> random.nat (\ ! map (n.% (text.size char_range))))]
(wrap (maybe.assume (text.nth idx char_range)))))
(def: (size bottom top)
(-> Nat Nat (Random Nat))
(let [constraint (|>> (n.% top) (n.max bottom))]
(random\map constraint random.nat)))
(def: (text bottom top)
(-> Nat Nat (Random Text))
(do random.monad
[size (..size bottom top)]
(random.text ..char size)))
(def: identifier
(Random Name)
(random.and (..text 0 10)
(..text 1 10)))
(def: #export random
(Random XML)
(random.rec (function (_ random)
(random.or (..text 1 10)
(do random.monad
[size (..size 0 2)]
($_ random.and
..identifier
(random.dictionary name.hash size ..identifier (..text 0 10))
(random.list size random)))))))
(def: #export test
Test
(<| (_.covering /._)
(_.for [/.XML])
($_ _.and
(_.for [/.equivalence]
($equivalence.spec /.equivalence ..random))
(_.for [/.codec]
($codec.spec /.equivalence /.codec ..random))
(do {! random.monad}
[(^@ identifier [namespace name]) ..identifier]
(`` ($_ _.and
(~~ (template [<type> <format>]
[(_.cover [<type> <format>]
(and (text\= name (<format> ["" name]))
(let [identifier (<format> identifier)]
(and (text.starts_with? namespace identifier)
(text.ends_with? name identifier)))))]
[/.Tag /.tag]
[/.Attribute /.attribute]
))
(_.cover [/.Attrs /.attributes]
(dictionary.empty? /.attributes))
)))
)))
|