(.module: [library [lux #* ["_" test (#+ Test)] [abstract [monad (#+ do)] [hash (#+ Hash)]] [control [pipe (#+ case>)] ["." try] [parser ["<.>" code]]] [data ["." text] [collection ["." set (#+ Set)] ["." dictionary (#+ Dictionary)] ["." list ("#\." functor)]]] [math ["." random (#+ Random)] [number ["n" nat]]] [macro ["." code]]]] [// ["@." profile]] [\\program ["." / ["/#" // #_ ["#" profile] ["#." project (#+ Project)] ["#." artifact (#+ Artifact)] ["#." dependency (#+ 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 (\ ! each (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 each (dictionary.of_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) (revised@ #//.sources (: (-> (Set //.Source) (Set //.Source)) (function (_ sources) (if (set.empty? sources) (set.of_list text.hash (list //.default_source)) sources))))) (def: with_default_repository (-> //.Profile //.Profile) (revised@ #//.repositories (set.has //.default_repository))) (def: single_profile Test (do random.monad [expected @profile.random] (_.test "Single profile." (|> expected //format.profile list (.result /.project) (case> (#try.Success actual) (|> expected ..with_default_sources ..with_default_repository (//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 (.result /.project) (case> (#try.Success actual) (|> expected ..with_empty_profile dictionary.entries (list\each (function (_ [name profile]) [name (|> profile ..with_default_sources ..with_default_repository)])) (dictionary.of_list text.hash) (\ //project.equivalence = actual)) (#try.Failure error) false))))) (def: .public test Test (<| (_.covering /._) (_.covering //format._) (_.for [/.project //format.Format //format.profile //format.project] ($_ _.and ..single_profile ..multiple_profiles ))))