(.module: [lux #* ["_" test (#+ Test)] [abstract [monad (#+ do)] [hash (#+ Hash)]] [control [pipe (#+ case>)] ["." try] [parser ["" code]]] [data ["." text] [number ["n" nat]] [collection ["." set (#+ Set)] ["." dictionary (#+ Dictionary)] ["." list ("#@." functor)]]] [math ["." random (#+ Random) ("#@." monad)]] [macro ["." code]]] [// ["@." profile]] {#program ["." / ["/#" // #_ ["#" profile] ["#." project (#+ Project)] ["#." artifact (#+ Artifact)] ["#." dependency (#+ Repository Dependency)] ["#." format]]]}) (def: name (Random //.Name) (random.ascii/alpha 1)) (def: (list-of random) (All [a] (-> (Random a) (Random (List a)))) (do {! random.monad} [size (:: ! map (n.% 5) random.nat)] (random.list size random))) (def: (dictionary-of key-hash key-random value-random) (All [k v] (-> (Hash k) (Random k) (Random v) (Random (Dictionary k v)))) (:: random.functor map (dictionary.from-list key-hash) (..list-of (random.and key-random value-random)))) (def: random (Random Project) (..dictionary-of text.hash ..name @profile.random)) (def: with-default-sources (-> //.Profile //.Profile) (update@ #//.sources (: (-> (Set //.Source) (Set //.Source)) (function (_ sources) (if (set.empty? sources) (set.from-list text.hash (list //.default-source)) sources))))) (def: single-profile Test (do random.monad [expected @profile.random] (_.test "Single profile." (|> expected //format.profile list (.run /.project) (case> (#try.Success actual) (|> expected ..with-default-sources (//project.project //.default) (:: //project.equivalence = actual)) (#try.Failure error) false))))) (def: (with-empty-profile project) (-> Project Project) (if (dictionary.empty? project) (//project.project //.default (:: //.monoid identity)) project)) (def: multiple-profiles Test (do random.monad [expected ..random] (_.test "Multiple profiles." (|> expected //format.project list (.run /.project) (case> (#try.Success actual) (|> expected ..with-empty-profile dictionary.entries (list@map (function (_ [name profile]) [name (..with-default-sources profile)])) (dictionary.from-list text.hash) (:: //project.equivalence = actual)) (#try.Failure error) false))))) (def: #export test Test (<| (_.covering /._) (_.covering //format._) (_.with-cover [/.project //format.Format //format.profile //format.project] ($_ _.and ..single-profile ..multiple-profiles ))))