blob: 4da17a05980279455c9c04152f445337853a9423 (
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
|
(.module:
[lux #*
["_" test (#+ Test)]
[abstract
["." hash (#+ Hash)]
["." equivalence (#+ Equivalence)]
["." monad (#+ do)]]
[control
["." io]
["." try]
["." exception (#+ exception:)]]
[data
["." binary (#+ Binary)]
["." text
["%" format (#+ format)]]
[collection
["." dictionary (#+ Dictionary)]]]
[math
["." random (#+ Random)]]]
[//
["@." 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)
(equivalence.product text.equivalence
text.equivalence))
(def: artifact
(-> Version Artifact)
(|>> ["com.github.luxlang" "test-artifact"]))
(def: item-hash
(Hash [Artifact Extension])
(hash.product //artifact.hash
text.hash))
(exception: (not-found {artifact Artifact}
{extension Extension})
(exception.report
["Artifact" (//artifact.format artifact)]
["Extension" (%.text extension)]))
(exception: (invalid-identity {[user _] Identity})
(exception.report
["User" (%.text user)]))
(type: Store
(Dictionary [Artifact Extension] Binary))
(def: #export empty
Store
(dictionary.new ..item-hash))
(structure: #export (simulation identity)
(-> Identity (/.Simulation Store))
(def: (on-download artifact extension state)
(case (dictionary.get [artifact extension] state)
(#.Some content)
(exception.return [state content])
#.None
(exception.throw ..not-found [artifact extension])))
(def: (on-upload requester artifact extension content state)
(if (\ identity-equivalence = identity requester)
(exception.return (dictionary.put [artifact extension] 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)))
))))
|