aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/parser.lux
blob: 1152a1dba7dc3357742f0c54dc66e47a4a540d2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
(.module:
  [library
   [lux "*"
    ["_" test {"+" [Test]}]
    [abstract
     [monad {"+" [do]}]
     [hash {"+" [Hash]}]]
    [control
     [pipe {"+" [case>]}]
     ["[0]" try]
     [parser
      ["<[0]>" code]]]
    [data
     ["[0]" text]
     [collection
      ["[0]" set {"+" [Set]}]
      ["[0]" dictionary {"+" [Dictionary]}]
      ["[0]" list ("[1]\[0]" functor)]]]
    [math
     ["[0]" random {"+" [Random]}]
     [number
      ["n" nat]]]
    [macro
     ["[0]" code]]]]
  [//
   ["@[0]" profile]]
  [\\program
   ["[0]" /
    ["/[1]" // "_"
     ["[1]" profile]
     ["[1][0]" project {"+" [Project]}]
     ["[1][0]" artifact {"+" [Artifact]}]
     ["[1][0]" dependency {"+" [Dependency]}]
     ["[1][0]" 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: (with_empty_profile project)
  (-> Project Project)
  (if (dictionary.empty? project)
    (//project.project //.default (\ //.monoid identity))
    project))

(def: .public test
  Test
  (<| (_.covering /._)
      (_.covering //format._)
      (do random.monad
        [expected ..random]
        (_.cover [/.project
                  //format.Format //format.project]
                 (|> expected
                     //format.project
                     list
                     (<code>.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))))))