(.module: [library [lux #* ["_" test (#+ Test)] [abstract [monad (#+ do)] [\\specification ["$." equivalence]]] [control ["." maybe] ["." try ("#\." functor)] [parser ["." environment] ["<.>" xml]] [concurrency ["." async]]] [data ["." text ("#\." equivalence)] [collection ["." list]]] [macro ["." code]] [math ["." random (#+ Random) ("#\." monad)] [number ["n" nat]]] ["." time ["." date] ["." year] ["." month] ["." instant (#+ Instant)] ["." duration]] [world ["." file] ["." program]]]] ["$." /// #_ ["#." artifact ["#/." type] ["#/." time] ["#/." snapshot #_ ["#/." version]]]] [\\program ["." / ["/#" // ["/#" // #_ [artifact [versioning (#+ Versioning)] ["#." snapshot]] ["#." repository #_ ["#/." local]]]]]]) (def: random_instant (Random Instant) (do {! random.monad} [year (\ ! map (|>> (n.% 9,000) (n.+ 1,000) .int) random.nat) month (\ ! map (|>> (n.% 12) (n.+ 1)) random.nat) day_of_month (\ ! map (|>> (n.% 28) (n.+ 1)) random.nat) hour (\ ! map (n.% 24) random.nat) minute (\ ! map (n.% 60) random.nat) second (\ ! map (n.% 60) random.nat)] (in (try.assumed (do try.monad [year (year.year year) month (month.by_number month) date (date.date year month day_of_month) time (time.time {#time.hour hour #time.minute minute #time.second second #time.milli_second 0})] (in (instant.of_date_time date time))))))) (def: random_versioning (Random Versioning) ($_ random.and (random\in #///snapshot.Local) $///artifact/time.random (random.list 5 $///artifact/snapshot/version.random) )) (def: .public random (Random /.Metadata) ($_ random.and $///artifact.random ..random_versioning )) (def: .public test Test (<| (_.covering /._) (_.for [/.Metadata]) (do random.monad [expected ..random .let [artifact (get@ #/.artifact expected)]] ($_ _.and (_.for [/.equivalence] ($equivalence.spec /.equivalence ..random)) (_.cover [/.format /.parser] (|> expected /.format list (.result /.parser) (try\map (\ /.equivalence = expected)) (try.else false))) (_.cover [/.uri] (text\= (//.remote_artifact_uri artifact) (/.uri artifact))) (do random.monad [home (random.ascii/lower 5) working_directory (random.ascii/lower 5) .let [program (program.async (program.mock environment.empty home working_directory)) fs (file.mock (\ file.default separator)) repository (///repository/local.repository program fs)]] (in (do async.monad [wrote? (/.write repository artifact expected) actual (/.read repository artifact)] (_.cover' [/.write /.read] (and (case wrote? (#try.Success _) true (#try.Failure _) false) (case actual (#try.Success actual) (\ /.equivalence = expected actual) (#try.Failure _) false)))))) ))))