(.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)]]]] [// ["@." artifact]] {#spec ["$." /]} {#program ["." / (#+ Identity) ["/#" // #_ ["#." artifact (#+ Version Artifact) ["#/." extension (#+ Extension)]]]]}) (def: #export identity (Random Identity) (random.and (random.ascii/alpha 10) (random.ascii/alpha 10))) (def: identity-equivalence (Equivalence Identity) (product.equivalence text.equivalence text.equivalence)) (def: artifact (-> Version Artifact) (|>> ["com.github.luxlang" "test-artifact"])) (exception: (not-found {uri URI}) (exception.report ["URI" (%.text uri)])) (exception: (invalid-identity {[user _] Identity}) (exception.report ["User" (%.text user)])) (type: Store (Dictionary URI Binary)) (def: #export empty Store (dictionary.new text.hash)) (structure: #export (simulation identity) (-> Identity (/.Simulation Store)) (def: (on-download uri state) (case (dictionary.get uri state) (#.Some content) (exception.return [state content]) #.None (exception.throw ..not-found [uri]))) (def: (on-upload requester uri content state) (if (\ identity-equivalence = identity requester) (exception.return (dictionary.put uri content state)) (exception.throw ..invalid-identity [requester])))) (def: #export test Test (<| (_.covering /._) (do {! random.monad} [valid ..identity invalid (random.filter (|>> (\ identity-equivalence = valid) not) ..identity)] ($_ _.and (_.for [/.mock /.Simulation] ($/.spec valid (..artifact "1.2.3-YES") invalid (..artifact "4.5.6-NO") (/.mock (..simulation valid) ..empty))) ))))