-
-
Notifications
You must be signed in to change notification settings - Fork 424
/
Copy pathTestHelpers.cs
240 lines (177 loc) · 9.57 KB
/
TestHelpers.cs
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
using System;
using LanguageExt.Common;
using LanguageExt.Effects;
using LanguageExt.Sys.Test;
using Xunit;
namespace LanguageExt;
public static class AssertExt
{
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Either helpers
//
public static void AssertLeft<L, R>(this Either<L, R> ma) =>
AssertLeft(ma, "Expected to be in a Left state");
public static void AssertLeft<L, R>(this Either<L, R> ma, string userMessage) =>
Assert.True(ma.IsLeft, userMessage);
public static void AssertRight<L, R>(this Either<L, R> ma) =>
AssertRight(ma, "Expected to be in a Right state");
public static void AssertRight<L, R>(this Either<L, R> ma, string userMessage) =>
Assert.True(ma.IsRight, userMessage);
public static void AssertLeft<L, R>(this Either<L, R> ma, L expected) =>
AssertLeft(ma, expected, $"Expected to be in a Left state with a value of {expected}");
public static void AssertLeft<L, R>(this Either<L, R> ma, L expected, string userMessage) =>
Assert.True(ma.IsLeft && expected.Equals((L)ma), userMessage);
public static void AssertRight<L, R>(this Either<L, R> ma, R expected) =>
AssertRight(ma, expected, $"Expected to be in a Right state with a value of {expected}");
public static void AssertRight<L, R>(this Either<L, R> ma, R expected, string userMessage) =>
Assert.True(ma.IsRight && expected.Equals((R)ma), userMessage);
public static void AssertLeft<L, R>(this Either<L, R> ma, Func<L, bool> predicate) =>
AssertLeft(ma, predicate, "Expected to be in a Left state with a predicate that returns true");
public static void AssertLeft<L, R>(this Either<L, R> ma, Func<L, bool> predicate, string userMessage) =>
Assert.True(ma.IsLeft && predicate((L)ma), userMessage);
public static void AssertRight<L, R>(this Either<L, R> ma, Func<R, bool> predicate) =>
AssertRight(ma, predicate, "Expected to be in a Right state with a predicate that returns true");
public static void AssertRight<L, R>(this Either<L, R> ma, Func<R, bool> predicate, string userMessage) =>
Assert.True(ma.IsRight && predicate((R)ma), userMessage);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Option helpers
//
public static void AssertNone<A>(this Option<A> ma) =>
AssertNone(ma, "Expected to be in a None state");
public static void AssertNone<A>(this Option<A> ma, string userMessage) =>
Assert.True(ma.IsNone, userMessage);
public static void AssertSome<A>(this Option<A> ma) =>
AssertSome(ma, "Expected to be in a Some state");
public static void AssertSome<A>(this Option<A> ma, string userMessage) =>
Assert.True(ma.IsSome, userMessage);
public static void AssertSome<A>(this Option<A> ma, A expected) =>
AssertSome(ma, expected, $"Expected to be in a Some state with a value of {expected}");
public static void AssertSome<A>(this Option<A> ma, A expected, string userMessage) =>
Assert.True(ma.IsSome && expected.Equals((A)ma), userMessage);
public static void AssertSome<A>(this Option<A> ma, Func<A, bool> predicate) =>
AssertSome(ma, predicate, "Expected to be in a Some state with a predicate that returns true");
public static void AssertSome<A>(this Option<A> ma, Func<A, bool> predicate, string userMessage) =>
Assert.True(ma.IsSome && predicate((A)ma), userMessage);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Fin helpers
//
public static void AssertFail<A>(this Fin<A> ma) =>
AssertFail(ma, "Expected to be in a Fail state");
public static void AssertFail<A>(this Fin<A> ma, string userMessage) =>
Assert.True(ma.IsFail, userMessage);
public static void AssertSucc<A>(this Fin<A> ma) =>
AssertSucc(ma, "Expected to be in a Succ state");
public static void AssertSucc<A>(this Fin<A> ma, string userMessage) =>
Assert.True(ma.IsSucc, userMessage);
public static void AssertFail<A>(this Fin<A> ma, Error expected) =>
AssertFail(ma, expected, $"Expected to be in a Fail state with a value of {expected}");
public static void AssertFail<A>(this Fin<A> ma, Error expected, string userMessage) =>
Assert.True(ma.IsFail && expected.Is((Error)ma), userMessage);
public static void AssertSucc<A>(this Fin<A> ma, A expected) =>
AssertSucc(ma, expected, $"Expected to be in a Succ state with a value of {expected}");
public static void AssertSucc<A>(this Fin<A> ma, A expected, string userMessage) =>
Assert.True(ma.IsSucc && expected.Equals((A)ma), userMessage);
public static void AssertFail<A>(this Fin<A> ma, Func<Error, bool> predicate) =>
AssertFail(ma, predicate, "Expected to be in a Fail state with a predicate that returns true");
public static void AssertFail<A>(this Fin<A> ma, Func<Error, bool> predicate, string userMessage) =>
Assert.True(ma.IsFail && predicate((Error)ma), userMessage);
public static void AssertSucc<A>(this Fin<A> ma, Func<A, bool> predicate) =>
AssertSucc(ma, predicate, "Expected to be in a Succ state with a predicate that returns true");
public static void AssertSucc<A>(this Fin<A> ma, Func<A, bool> predicate, string userMessage) =>
Assert.True(ma.IsSucc && predicate((A)ma), userMessage);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Eff helpers
//
public static void AssertFail<A>(this Eff<Runtime, A> ma)
{
using var rt = Runtime.New();
ma.Run(rt, EnvIO.New()).AssertFail();
}
public static void AssertFail<A>(this Eff<Runtime, A> ma, string userMessage)
{
using var rt = Runtime.New();
ma.Run(rt, EnvIO.New()).AssertFail(userMessage);
}
public static void AssertSucc<A>(this Eff<Runtime, A> ma)
{
using var rt = Runtime.New();
ma.Run(rt, EnvIO.New()).AssertSucc();
}
public static void AssertSucc<A>(this Eff<Runtime, A> ma, string userMessage)
{
using var rt = Runtime.New();
ma.Run(rt, EnvIO.New()).AssertSucc(userMessage);
}
public static void AssertFail<A>(this Eff<Runtime, A> ma, Error expected)
{
using var rt = Runtime.New();
ma.Run(rt, EnvIO.New()).AssertFail(expected);
}
public static void AssertFail<A>(this Eff<Runtime, A> ma, Error expected, string userMessage)
{
using var rt = Runtime.New();
ma.Run(rt, EnvIO.New()).AssertFail(expected, userMessage);
}
public static void AssertSucc<A>(this Eff<Runtime, A> ma, A expected)
{
using var rt = Runtime.New();
ma.Run(rt, EnvIO.New()).AssertSucc(expected);
}
public static void AssertSucc<A>(this Eff<Runtime, A> ma, A expected, string userMessage)
{
using var rt = Runtime.New();
ma.Run(rt, EnvIO.New()).AssertSucc(expected, userMessage);
}
public static void AssertFail<A>(this Eff<Runtime, A> ma, Func<Error, bool> predicate)
{
using var rt = Runtime.New();
ma.Run(rt, EnvIO.New()).AssertFail(predicate);
}
public static void AssertFail<A>(this Eff<Runtime, A> ma, Func<Error, bool> predicate, string userMessage)
{
using var rt = Runtime.New();
ma.Run(rt, EnvIO.New()).AssertFail(predicate, userMessage);
}
public static void AssertSucc<A>(this Eff<Runtime, A> ma, Func<A, bool> predicate)
{
using var rt = Runtime.New();
ma.Run(rt, EnvIO.New()).AssertSucc(predicate);
}
public static void AssertSucc<A>(this Eff<Runtime, A> ma, Func<A, bool> predicate, string userMessage)
{
using var rt = Runtime.New();
ma.Run(rt, EnvIO.New()).AssertSucc(predicate, userMessage);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Eff helpers
//
public static void AssertFail<A>(this Eff<A> ma) =>
ma.Run().AssertFail();
public static void AssertFail<A>(this Eff<A> ma, string userMessage) =>
ma.Run().AssertFail(userMessage);
public static void AssertSucc<A>(this Eff<A> ma) =>
ma.Run().AssertSucc();
public static void AssertSucc<A>(this Eff<A> ma, string userMessage) =>
ma.Run().AssertSucc(userMessage);
public static void AssertFail<A>(this Eff<A> ma, Error expected) =>
ma.Run().AssertFail(expected);
public static void AssertFail<A>(this Eff<A> ma, Error expected, string userMessage) =>
ma.Run().AssertFail(expected, userMessage);
public static void AssertSucc<A>(this Eff<A> ma, A expected) =>
ma.Run().AssertSucc(expected);
public static void AssertSucc<A>(this Eff<A> ma, A expected, string userMessage) =>
ma.Run().AssertSucc(expected, userMessage);
public static void AssertFail<A>(this Eff<A> ma, Func<Error, bool> predicate) =>
ma.Run().AssertFail(predicate);
public static void AssertFail<A>(this Eff<A> ma, Func<Error, bool> predicate, string userMessage) =>
ma.Run().AssertFail(predicate, userMessage);
public static void AssertSucc<A>(this Eff<A> ma, Func<A, bool> predicate) =>
ma.Run().AssertSucc(predicate);
public static void AssertSucc<A>(this Eff<A> ma, Func<A, bool> predicate, string userMessage) =>
ma.Run().AssertSucc(predicate, userMessage);
}