(.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 [ ] [(_.cover [ ] (and (text\= name ( ["" name])) (let [identifier ( identifier)] (and (text.starts_with? namespace identifier) (text.ends_with? name identifier)))))] [/.Tag /.tag] [/.Attribute /.attribute] )) (_.cover [/.Attrs /.attributes] (dictionary.empty? /.attributes)) ))) )))