(.module: [library [lux #* ["_" test (#+ Test)] [abstract [monad (#+ do)] [\\specification ["$." equivalence]]] [control ["." try]] [data ["." product] ["." text [encoding ["." utf8]]] [format ["." xml (#+ XML)]] [collection ["." set (#+ Set)]]] [math ["." random (#+ Random)] [number ["n" nat]]] [world ["." file]]]] [// ["$." profile] [// [lux [data ["$." binary]]]]] [\\program ["." / ["/#" // #_ ["#" profile] ["#." hash ("#\." equivalence)] ["#." pom] [dependency ["#." status]] [repository ["#." origin]]]]]) (def: .public random (Random [//.Profile /.Package]) (do {! random.monad} [content_size (\ ! map (n.% 100) random.nat) content ($binary.random content_size) [profile pom] (random.one (function (_ profile) (try.maybe (do try.monad [pom (//pom.write profile)] (in [profile pom])))) $profile.random)] (in [profile (/.local pom content)]))) (def: .public test Test (<| (_.covering /._) (_.for [/.Package]) (do {! random.monad} [[profile package] ..random] ($_ _.and (_.for [/.equivalence] ($equivalence.spec /.equivalence (\ ! map product.right ..random))) (_.cover [/.local?] (/.local? (with@ #/.origin (#//origin.Local "~/yolo") package))) (_.cover [/.remote?] (/.remote? (with@ #/.origin (#//origin.Remote "https://example.com") package))) (_.cover [/.local] (let [expected_pom (|> package (value@ #/.pom) product.left) expected_library (|> package (value@ #/.library) product.left) local (/.local expected_pom expected_library) [actual_pom binary_pom pom_status] (value@ #/.pom local) [actual_library library_status] (value@ #/.library local)] (and (case (value@ #/.origin local) (#//origin.Local "") true _ false) (let [expected_sha1 (//hash.sha-1 expected_library) expected_md5 (//hash.md5 expected_library)] (and (same? expected_library actual_library) (case library_status (#//status.Verified actual_sha1 expected_md5) (and (//hash\= expected_sha1 actual_sha1) (//hash\= expected_md5 expected_md5)) _ false))) (let [expected_sha1 (//hash.sha-1 binary_pom) expected_md5 (//hash.md5 binary_pom)] (and (same? expected_pom actual_pom) (|> (do try.monad [xml_pom (\ utf8.codec decoded binary_pom) decoded_pom (\ xml.codec decoded xml_pom)] (in (\ xml.equivalence = actual_pom decoded_pom))) (try.else false)) (case pom_status (#//status.Verified actual_sha1 expected_md5) (and (//hash\= expected_sha1 actual_sha1) (//hash\= expected_md5 expected_md5)) _ false)))))) (_.cover [/.dependencies] (let [expected (value@ #//.dependencies profile)] (case (/.dependencies package) (#try.Success actual) (\ set.equivalence = expected actual) (#try.Failure error) false))) (_.cover [/.repositories] (let [expected (value@ #//.repositories profile)] (case (/.repositories package) (#try.Success actual) (\ set.equivalence = expected actual) (#try.Failure error) false))) ))))