(.module: [lux #* ["_" test (#+ Test)] [abstract [equivalence (#+ Equivalence)] [hash (#+ Hash)] ["." monad (#+ do)]] [control ["." io] ["." try] ["." exception (#+ exception:)]] [data ["." product] ["." binary (#+ Binary)] ["." text ["%" format (#+ format)]] [collection ["." dictionary (#+ Dictionary)]]] [math ["." random (#+ Random)]] [world [net ["." uri (#+ URI)]]]] ["." / #_ ["#." identity] ["#." origin] ["#." local] ["#." remote] [// ["@." artifact]]] {#spec ["$." /]} {#program ["." / ["." remote] ["/#" // #_ ["#." artifact (#+ Version Artifact) ["#/." extension (#+ Extension)]]]]}) (def: artifact (-> Version Artifact) (|>> ["com.github.luxlang" "test-artifact"])) (exception: (not_found {uri URI}) (exception.report ["URI" (%.text uri)])) (exception: (cannot_upload {uri URI}) (exception.report ["URI" (%.text uri)])) (type: Store (Dictionary URI Binary)) (def: #export empty Store (dictionary.new text.hash)) (def: valid_version Version "1.2.3-YES") (def: invalid_version Version "4.5.6-NO") (implementation: #export mock (/.Mock Store) (def: the_description "@") (def: (on_download uri state) (case (dictionary.get uri state) (#.Some content) (case (binary.size content) 0 (exception.throw ..not_found [uri]) _ (exception.return [state content])) #.None (exception.throw ..not_found [uri]))) (def: (on_upload uri content state) (if (dictionary.key? state uri) (exception.throw ..cannot_upload [uri]) (exception.return (dictionary.put uri content state))))) (def: #export test Test (<| (_.covering /._) ($_ _.and (_.for [/.mock /.Mock] (do random.monad [_ (wrap [])] ($/.spec (..artifact ..valid_version) (..artifact ..invalid_version) (/.mock ..mock (|> ..empty (dictionary.put (remote.uri ..invalid_version (..artifact ..invalid_version) //artifact/extension.lux_library) (binary.create 0))))))) /identity.test /origin.test /local.test /remote.test )))