|
1 | 1 | /// Wraps a function in a spy |
2 | 2 | /// - Parameter closure: The function to wrap |
3 | 3 | /// - Returns: The spy and and the wrapped function |
4 | | -public func spy<Result>( |
5 | | - _ closure: @escaping @Sendable () -> Result |
6 | | -) -> (Spy, @Sendable () -> Result) { |
7 | | - let spy = Spy() |
8 | | - return (spy, { |
| 4 | +public func spy<each A, Result>( |
| 5 | + _ closure: @escaping @Sendable (repeat each A) -> Result |
| 6 | +) -> (Spy<repeat each A>, @Sendable (repeat each A) -> Result) { |
| 7 | + let spy = Spy<repeat each A>() |
| 8 | + |
| 9 | + return (spy, { (a: repeat each A) -> Result in |
9 | 10 | spy.increment() |
10 | | - spy.recordCall() |
11 | | - return closure() |
| 11 | + spy.recordCall(repeat each a) |
| 12 | + return closure(repeat each a) |
12 | 13 | }) |
13 | 14 | } |
14 | 15 |
|
15 | 16 | /// Wraps a function in a spy |
16 | 17 | /// - Parameter closure: The function to wrap |
17 | 18 | /// - Returns: The spy and and the wrapped function |
18 | | -public func spy<A, Result>( |
19 | | - _ closure: @escaping @Sendable (A) -> Result |
20 | | -) -> (Spy1<A>, @Sendable (A) -> Result) { |
21 | | - let spy = Spy1<A>() |
22 | | - return (spy, { a in |
| 19 | +public func spy<each A, Result>( |
| 20 | + _ closure: @escaping @Sendable (repeat each A) throws -> Result |
| 21 | +) -> (Spy<repeat each A>, @Sendable (repeat each A) throws -> Result) { |
| 22 | + let spy = Spy<repeat each A>() |
| 23 | + |
| 24 | + return (spy, { (a: repeat each A) throws -> Result in |
23 | 25 | spy.increment() |
24 | | - spy.recordCall(a) |
25 | | - return closure(a) |
| 26 | + spy.recordCall(repeat each a) |
| 27 | + return try closure(repeat each a) |
26 | 28 | }) |
27 | 29 | } |
28 | 30 |
|
29 | 31 | /// Wraps a function in a spy |
30 | 32 | /// - Parameter closure: The function to wrap |
31 | 33 | /// - Returns: The spy and and the wrapped function |
32 | | -public func spy<A, B, Result>( |
33 | | - _ closure: @escaping @Sendable (A, B) -> Result |
34 | | -) -> (Spy2<A, B>, @Sendable (A, B) -> Result) { |
35 | | - let spy = Spy2<A, B>() |
36 | | - return (spy, { a, b in |
| 34 | +public func spy<each A, Result>( |
| 35 | + _ closure: @escaping @Sendable (repeat each A) async -> Result |
| 36 | +) -> (Spy<repeat each A>, @Sendable (repeat each A) async -> Result) { |
| 37 | + let spy = Spy<repeat each A>() |
| 38 | + |
| 39 | + return (spy, { (a: repeat each A) async -> Result in |
37 | 40 | spy.increment() |
38 | | - spy.recordCall(a, b) |
39 | | - return closure(a, b) |
| 41 | + spy.recordCall(repeat each a) |
| 42 | + return await closure(repeat each a) |
40 | 43 | }) |
41 | 44 | } |
42 | 45 |
|
43 | | -/// Wraps a function in a spy |
44 | | -/// - Parameter closure: The function to wrap |
45 | | -/// - Returns: The spy and and the wrapped function |
46 | | -public func spy<A, B, C, Result>( |
47 | | - _ closure: @escaping @Sendable (A, B, C) -> Result |
48 | | -) -> (Spy3<A, B, C>, @Sendable (A, B, C) -> Result) { |
49 | | - let spy = Spy3<A, B, C>() |
50 | | - return (spy, { a, b, c in |
51 | | - spy.increment() |
52 | | - spy.recordCall(a, b, c) |
53 | | - return closure(a, b, c) |
54 | | - }) |
55 | | -} |
56 | | - |
57 | | -/// Wraps a function in a spy |
58 | | -/// - Parameter closure: The function to wrap |
59 | | -/// - Returns: The spy and and the wrapped function |
60 | | -public func spy<A, B, C, D, Result>( |
61 | | - _ closure: @escaping @Sendable (A, B, C, D) -> Result |
62 | | -) -> (Spy4<A, B, C, D>, @Sendable (A, B, C, D) -> Result) { |
63 | | - let spy = Spy4<A, B, C, D>() |
64 | | - return (spy, { a, b, c, d in |
65 | | - spy.increment() |
66 | | - spy.recordCall(a, b, c, d) |
67 | | - return closure(a, b, c, d) |
68 | | - }) |
69 | | -} |
70 | | - |
71 | | -/// Wraps a function in a spy |
72 | | -/// - Parameter closure: The function to wrap |
73 | | -/// - Returns: The spy and and the wrapped function |
74 | | -public func spy<Result>( |
75 | | - _ closure: @escaping @Sendable () throws -> Result |
76 | | -) -> (Spy, @Sendable () throws -> Result) { |
77 | | - let spy = Spy() |
78 | | - return (spy, { |
79 | | - spy.increment() |
80 | | - spy.recordCall() |
81 | | - return try closure() |
82 | | - }) |
83 | | -} |
84 | 46 |
|
85 | 47 | /// Wraps a function in a spy |
86 | 48 | /// - Parameter closure: The function to wrap |
87 | 49 | /// - Returns: The spy and and the wrapped function |
88 | | -public func spy<A, Result>( |
89 | | - _ closure: @escaping @Sendable (A) throws -> Result |
90 | | -) -> (Spy1<A>, @Sendable (A) throws -> Result) { |
91 | | - let spy = Spy1<A>() |
92 | | - return (spy, { a in |
| 50 | +public func spy<each A, Result>( |
| 51 | + _ closure: @escaping @Sendable (repeat each A) async throws -> Result |
| 52 | +) -> (Spy<repeat each A>, @Sendable (repeat each A) async throws -> Result) { |
| 53 | + let spy = Spy<repeat each A>() |
| 54 | + |
| 55 | + return (spy, { (a: repeat each A) async throws -> Result in |
93 | 56 | spy.increment() |
94 | | - spy.recordCall(a) |
95 | | - return try closure(a) |
| 57 | + spy.recordCall(repeat each a) |
| 58 | + return try await closure(repeat each a) |
96 | 59 | }) |
97 | 60 | } |
98 | | - |
99 | | -/// Wraps a function in a spy |
100 | | -/// - Parameter closure: The function to wrap |
101 | | -/// - Returns: The spy and and the wrapped function |
102 | | -public func spy<A, B, Result>( |
103 | | - _ closure: @escaping @Sendable (A, B) throws -> Result |
104 | | -) -> (Spy2<A, B>, @Sendable (A, B) throws -> Result) { |
105 | | - let spy = Spy2<A, B>() |
106 | | - return (spy, { a, b in |
107 | | - spy.increment() |
108 | | - spy.recordCall(a, b) |
109 | | - return try closure(a, b) |
110 | | - }) |
111 | | -} |
112 | | - |
113 | | -/// Wraps a function in a spy |
114 | | -/// - Parameter closure: The function to wrap |
115 | | -/// - Returns: The spy and and the wrapped function |
116 | | -public func spy<A, B, C, Result>( |
117 | | - _ closure: @escaping @Sendable (A, B, C) throws -> Result |
118 | | -) -> (Spy3<A, B, C>, @Sendable (A, B, C) throws -> Result) { |
119 | | - let spy = Spy3<A, B, C>() |
120 | | - return (spy, { a, b, c in |
121 | | - spy.increment() |
122 | | - spy.recordCall(a, b, c) |
123 | | - return try closure(a, b, c) |
124 | | - }) |
125 | | -} |
126 | | - |
127 | | -/// Wraps a function in a spy |
128 | | -/// - Parameter closure: The function to wrap |
129 | | -/// - Returns: The spy and and the wrapped function |
130 | | -public func spy<A, B, C, D, Result>( |
131 | | - _ closure: @escaping @Sendable (A, B, C, D) throws -> Result |
132 | | -) -> (Spy4<A, B, C, D>, @Sendable (A, B, C, D) throws -> Result) { |
133 | | - let spy = Spy4<A, B, C, D>() |
134 | | - return (spy, { a, b, c, d in |
135 | | - spy.increment() |
136 | | - spy.recordCall(a, b, c, d) |
137 | | - return try closure(a, b, c, d) |
138 | | - }) |
139 | | -} |
140 | | - |
141 | | -/// Wraps a function in a spy |
142 | | -/// - Parameter closure: The function to wrap |
143 | | -/// - Returns: The spy and and the wrapped function |
144 | | -public func spy<Result>( |
145 | | - _ closure: @escaping @Sendable () async throws -> Result |
146 | | -) -> (Spy, @Sendable () async throws -> Result) { |
147 | | - let spy = Spy() |
148 | | - return (spy, { |
149 | | - spy.increment() |
150 | | - spy.recordCall() |
151 | | - return try await closure() |
152 | | - }) |
153 | | -} |
154 | | - |
155 | | -/// Wraps a function in a spy |
156 | | -/// - Parameter closure: The function to wrap |
157 | | -/// - Returns: The spy and and the wrapped function |
158 | | -public func spy<A, Result>( |
159 | | - _ closure: @escaping @Sendable (A) async throws -> Result |
160 | | -) -> (Spy1<A>, @Sendable (A) async throws -> Result) { |
161 | | - let spy = Spy1<A>() |
162 | | - return (spy, { a in |
163 | | - spy.increment() |
164 | | - spy.recordCall(a) |
165 | | - return try await closure(a) |
166 | | - }) |
167 | | -} |
168 | | - |
169 | | -/// Wraps a function in a spy |
170 | | -/// - Parameter closure: The function to wrap |
171 | | -/// - Returns: The spy and and the wrapped function |
172 | | -public func spy<A, B, Result>( |
173 | | - _ closure: @escaping @Sendable (A, B) async throws -> Result |
174 | | -) -> (Spy2<A, B>, @Sendable (A, B) async throws -> Result) { |
175 | | - let spy = Spy2<A, B>() |
176 | | - return (spy, { a, b in |
177 | | - spy.increment() |
178 | | - spy.recordCall(a, b) |
179 | | - return try await closure(a, b) |
180 | | - }) |
181 | | -} |
182 | | - |
183 | | -/// Wraps a function in a spy |
184 | | -/// - Parameter closure: The function to wrap |
185 | | -/// - Returns: The spy and and the wrapped function |
186 | | -public func spy<A, B, C, Result>( |
187 | | - _ closure: @escaping @Sendable (A, B, C) async throws -> Result |
188 | | -) -> (Spy3<A, B, C>, @Sendable (A, B, C) async throws -> Result) { |
189 | | - let spy = Spy3<A, B, C>() |
190 | | - return (spy, { a, b, c in |
191 | | - spy.increment() |
192 | | - spy.recordCall(a, b, c) |
193 | | - return try await closure(a, b, c) |
194 | | - }) |
195 | | -} |
196 | | - |
197 | | -/// Wraps a function in a spy |
198 | | -/// - Parameter closure: The function to wrap |
199 | | -/// - Returns: The spy and and the wrapped function |
200 | | -public func spy<A, B, C, D, Result>( |
201 | | - _ closure: @escaping @Sendable (A, B, C, D) async throws -> Result |
202 | | -) -> (Spy4<A, B, C, D>, @Sendable (A, B, C, D) async throws -> Result) { |
203 | | - let spy = Spy4<A, B, C, D>() |
204 | | - return (spy, { a, b, c, d in |
205 | | - spy.increment() |
206 | | - spy.recordCall(a, b, c, d) |
207 | | - return try await closure(a, b, c, d) |
208 | | - }) |
209 | | -} |
210 | | - |
0 commit comments