forked from fsprojects/FsUnit
-
Notifications
You must be signed in to change notification settings - Fork 2
/
FsUnit.fs
77 lines (45 loc) · 1.75 KB
/
FsUnit.fs
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
// TODO : Add license header
namespace FsUnit
open NUnit.Framework
open NUnit.Framework.Constraints
//
[<AutoOpen>]
module TopLevelOperators =
let Null = NullConstraint()
let Empty = EmptyConstraint()
let EmptyString = EmptyStringConstraint()
let NullOrEmptyString = NullOrEmptyStringConstraint()
let True = TrueConstraint()
let False = FalseConstraint()
let NaN = NaNConstraint()
let unique = UniqueItemsConstraint()
let should (f : 'a -> #Constraint) x (y : obj) =
let c = f x
let y =
match y with
| :? (unit -> unit) -> box (TestDelegate(y :?> unit -> unit))
| _ -> y
Assert.That(y, c)
let equal x = EqualConstraint(x)
let equalWithin tolerance x = equal(x).Within tolerance
let contain x = ContainsConstraint(x)
let haveLength n = Has.Length.EqualTo(n)
let haveCount n = Has.Count.EqualTo(n)
let be = id
let sameAs x = SameAsConstraint(x)
let throw = Throws.TypeOf
let greaterThan x = GreaterThanConstraint(x)
let greaterThanOrEqualTo x = GreaterThanOrEqualConstraint(x)
let lessThan x = LessThanConstraint(x)
let lessThanOrEqualTo x = LessThanOrEqualConstraint(x)
let shouldFail (f : unit -> unit) =
TestDelegate(f) |> should throw typeof<AssertionException>
let endWith (s:string) = EndsWithConstraint s
let startWith (s:string) = StartsWithConstraint s
let ofExactType<'a> = ExactTypeConstraint(typeof<'a>)
let instanceOfType<'a> = InstanceOfTypeConstraint(typeof<'a>)
let not' x = NotConstraint(x)
/// Deprecated operators. These will be removed in a future version of FsUnit.
module FsUnitDepricated =
[<System.Obsolete>]
let not x = not' x