aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/repository.lux
blob: 9412b5fd5ae9c315407e87c46c4dd29bbadd0793 (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
100
101
102
103
104
105
106
107
(.module:
  [library
   [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]]]
  [\\specification
   ["$." /]]
  [\\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: .public empty
  Store
  (dictionary.empty text.hash))

(def: valid_version
  Version
  "1.2.3-YES")

(def: invalid_version
  Version
  "4.5.6-NO")

(implementation: .public mock
  (/.Mock Store)

  (def: the_description
    "@")
  (def: (on_download uri state)
    (case (dictionary.value uri state)
      (#.Some content)
      (case (binary.size content)
        0 (exception.except ..not_found [uri])
        _ (#try.Success [state content]))
      
      #.None
      (exception.except ..not_found [uri])))
  (def: (on_upload uri content state)
    (if (dictionary.key? state uri)
      (exception.except ..cannot_upload [uri])
      (#try.Success (dictionary.has uri content state)))))

(def: .public test
  Test
  (<| (_.covering /._)
      ($_ _.and
          (_.for [/.mock /.Mock]
                 (do random.monad
                   [_ (in [])]
                   ($/.spec (..artifact ..valid_version)
                            (..artifact ..invalid_version)
                            (/.mock ..mock
                                    (|> ..empty
                                        (dictionary.has (remote.uri ..invalid_version
                                                                    (..artifact ..invalid_version)
                                                                    //artifact/extension.lux_library)
                                                        (binary.empty 0)))))))

          /identity.test
          /origin.test
          /local.test
          /remote.test
          )))