Skip to content

Commit 2705833

Browse files
committed
Merge pull request #66 from sergey-tihon/master
Added support of `Empty` operator for xUnit, MsTest and MbUnit
2 parents 04b34cb + e57070f commit 2705833

File tree

9 files changed

+110
-20
lines changed

9 files changed

+110
-20
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
* Enable substring checks https://github.com/fsprojects/FsUnit/pull/45
55
* Fixed assertion message for NUnit equal constraint - https://github.com/fsprojects/FsUnit/pull/60
66
* Added support of `shouldFail` operator for xUnit, MsTest and MbUnit - https://github.com/fsprojects/FsUnit/pull/64
7-
* Added support of `instanceOfType` operator for xUnit, MsTest and MbUnit -
7+
* Added support of `instanceOfType` operator for xUnit, MsTest and MbUnit - https://github.com/fsprojects/FsUnit/pull/65
8+
* Added support of `Empty` operator for xUnit, MsTest and MbUnit -
89

910
### 1.3.1.0 - 26 July 2015
1011
* Bump NUnit version up to 2.6.4

docs/content/operators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Operators comparison across frameworks
44
| Operator | NUnit | xUnit | MSTest | MbUnit |
55
|------------------------|:-----:|:-----:|:------:|:------:|
66
| `Null` | + | + | + | + |
7-
| `Empty` | + | | | |
7+
| `Empty` | + | + | + | + |
88
| `EmptyString` | + | + | + | + |
99
| `NullOrEmptyString` | + | + | + | + |
1010
| `True` | + | + | + | + |

src/FsUnit.MbUnit/FsUnit.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ let be = CustomMatchers.be
3737

3838
let Null = CustomMatchers.Null
3939

40+
let Empty = CustomMatchers.Empty
41+
4042
let EmptyString = CustomMatchers.EmptyString
4143

4244
let NullOrEmptyString = CustomMatchers.NullOrEmptyString

src/FsUnit.MsTestUnit/FsUnit.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ let be = CustomMatchers.be
4747

4848
let Null = CustomMatchers.Null
4949

50+
let Empty = CustomMatchers.Empty
51+
5052
let EmptyString = CustomMatchers.EmptyString
5153

5254
let NullOrEmptyString = CustomMatchers.NullOrEmptyString

src/FsUnit.Xunit/CustomMatchers.fs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ let be = id
4444

4545
let Null = Is.Null()
4646

47+
let Empty = CustomMatcher<obj>("A non empty", fun o ->
48+
match o with
49+
| :? string as s -> s.Trim() = ""
50+
| :? list<_> as l -> List.isEmpty l
51+
| :? array<_> as a -> Array.isEmpty a
52+
| :? seq<_> as s -> Seq.isEmpty s
53+
| :? System.Collections.IEnumerable as e -> e |> Seq.cast |> Seq.isEmpty
54+
| _ -> false)
55+
4756
let EmptyString = CustomMatcher<obj>("A non empty string", fun s -> (string s).Trim() = "")
4857

4958
let NullOrEmptyString = CustomMatcher<obj>("A not empty or not null string", fun s -> String.IsNullOrEmpty(unbox s))

src/FsUnit.Xunit/FsUnit.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ let be = CustomMatchers.be
5151

5252
let Null = CustomMatchers.Null
5353

54+
let Empty = CustomMatchers.Empty
55+
5456
let EmptyString = CustomMatchers.EmptyString
5557

5658
let NullOrEmptyString = CustomMatchers.NullOrEmptyString

tests/FsUnit.MbUnit.Test/beEmptyTests.fs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,50 @@ open NHamcrest.Core
77
type ``be Empty tests`` ()=
88
[<Test>] member test.
99
``empty List should be Empty`` ()=
10-
[].IsEmpty |> should be True
10+
[] |> should be Empty
11+
12+
[<Test>] member test.
13+
``non-empty List should fail to be Empty`` ()=
14+
shouldFail (fun () -> [1] |> should be Empty)
1115

1216
[<Test>] member test.
1317
``non-empty List should not be Empty`` ()=
14-
[1].IsEmpty |> should not' (be True)
18+
[1] |> should not' (be Empty)
19+
20+
[<Test>] member test.
21+
``empty List should fail to not be Empty`` ()=
22+
shouldFail (fun () -> [] |> should not' (be Empty))
1523

1624
[<Test>] member test.
1725
``empty Array should be Empty`` ()=
18-
[||] |> Array.isEmpty |> should be True
26+
[||] |> should be Empty
27+
28+
[<Test>] member test.
29+
``non-empty Array should fail to be Empty`` ()=
30+
shouldFail (fun () -> [|1|] |> should be Empty)
1931

2032
[<Test>] member test.
2133
``non-empty Array should not be Empty`` ()=
22-
[|1|] |> Array.isEmpty |> should not' (be True)
34+
[|1|] |> should not' (be Empty)
35+
36+
[<Test>] member test.
37+
``empty Array should fail to not be Empty`` ()=
38+
shouldFail (fun () -> [||] |> should not' (be Empty))
2339

2440
[<Test>] member test.
2541
``empty Seq should be Empty`` ()=
26-
Seq.empty |> Seq.isEmpty |> should be True
42+
Seq.empty |> should be Empty
43+
44+
[<Test>] member test.
45+
``non-empty Seq should fail to be Empty`` ()=
46+
shouldFail (fun () -> seq { yield 1 } |> should be Empty)
2747

2848
[<Test>] member test.
2949
``non-empty Seq should not be Empty`` ()=
30-
seq { yield 1 } |> Seq.isEmpty |> should not' (be True)
50+
seq { yield 1 } |> should not' (be Empty)
51+
52+
[<Test>] member test.
53+
``empty Seq should fail to not be Empty`` ()=
54+
shouldFail (fun () -> Seq.empty |> should not' (be Empty))
55+
3156

tests/FsUnit.MsTest.Test/beEmptyTests.fs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,49 @@ open NHamcrest.Core
77
type ``be Empty tests`` ()=
88
[<TestMethod>] member test.
99
``empty List should be Empty`` ()=
10-
[].IsEmpty |> should be True
10+
[] |> should be Empty
11+
12+
[<TestMethod>] member test.
13+
``non-empty List should fail to be Empty`` ()=
14+
shouldFail (fun () -> [1] |> should be Empty)
1115

1216
[<TestMethod>] member test.
1317
``non-empty List should not be Empty`` ()=
14-
[1].IsEmpty |> should not' (be True)
18+
[1] |> should not' (be Empty)
19+
20+
[<TestMethod>] member test.
21+
``empty List should fail to not be Empty`` ()=
22+
shouldFail (fun () -> [] |> should not' (be Empty))
1523

1624
[<TestMethod>] member test.
1725
``empty Array should be Empty`` ()=
18-
[||] |> Array.isEmpty |> should be True
26+
[||] |> should be Empty
27+
28+
[<TestMethod>] member test.
29+
``non-empty Array should fail to be Empty`` ()=
30+
shouldFail (fun () -> [|1|] |> should be Empty)
1931

2032
[<TestMethod>] member test.
2133
``non-empty Array should not be Empty`` ()=
22-
[|1|] |> Array.isEmpty |> should not' (be True)
34+
[|1|] |> should not' (be Empty)
35+
36+
[<TestMethod>] member test.
37+
``empty Array should fail to not be Empty`` ()=
38+
shouldFail (fun () -> [||] |> should not' (be Empty))
2339

2440
[<TestMethod>] member test.
2541
``empty Seq should be Empty`` ()=
26-
Seq.empty |> Seq.isEmpty |> should be True
42+
Seq.empty |> should be Empty
43+
44+
[<TestMethod>] member test.
45+
``non-empty Seq should fail to be Empty`` ()=
46+
shouldFail (fun () -> seq { yield 1 } |> should be Empty)
2747

2848
[<TestMethod>] member test.
2949
``non-empty Seq should not be Empty`` ()=
30-
seq { yield 1 } |> Seq.isEmpty |> should not' (be True)
50+
seq { yield 1 } |> should not' (be Empty)
51+
52+
[<TestMethod>] member test.
53+
``empty Seq should fail to not be Empty`` ()=
54+
shouldFail (fun () -> Seq.empty |> should not' (be Empty))
3155

tests/FsUnit.Xunit.Test/beEmptyTests.fs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,50 @@ open NHamcrest.Core
66
type ``be Empty tests`` ()=
77
[<Fact>] member test.
88
``empty List should be Empty`` ()=
9-
[].IsEmpty |> should be True
9+
[] |> should be Empty
10+
11+
[<Fact>] member test.
12+
``non-empty List should fail to be Empty`` ()=
13+
shouldFail (fun () -> [1] |> should be Empty)
1014

1115
[<Fact>] member test.
1216
``non-empty List should not be Empty`` ()=
13-
[1].IsEmpty |> should not' (be True)
17+
[1] |> should not' (be Empty)
18+
19+
[<Fact>] member test.
20+
``empty List should fail to not be Empty`` ()=
21+
shouldFail (fun () -> [] |> should not' (be Empty))
1422

1523
[<Fact>] member test.
1624
``empty Array should be Empty`` ()=
17-
[||] |> Array.isEmpty |> should be True
25+
[||] |> should be Empty
26+
27+
[<Fact>] member test.
28+
``non-empty Array should fail to be Empty`` ()=
29+
shouldFail (fun () -> [|1|] |> should be Empty)
1830

1931
[<Fact>] member test.
2032
``non-empty Array should not be Empty`` ()=
21-
[|1|] |> Array.isEmpty |> should not' (be True)
33+
[|1|] |> should not' (be Empty)
34+
35+
[<Fact>] member test.
36+
``empty Array should fail to not be Empty`` ()=
37+
shouldFail (fun () -> [||] |> should not' (be Empty))
2238

2339
[<Fact>] member test.
2440
``empty Seq should be Empty`` ()=
25-
Seq.empty |> Seq.isEmpty |> should be True
41+
Seq.empty |> should be Empty
42+
43+
[<Fact>] member test.
44+
``non-empty Seq should fail to be Empty`` ()=
45+
shouldFail (fun () -> seq { yield 1 } |> should be Empty)
2646

2747
[<Fact>] member test.
2848
``non-empty Seq should not be Empty`` ()=
29-
seq { yield 1 } |> Seq.isEmpty |> should not' (be True)
49+
seq { yield 1 } |> should not' (be Empty)
50+
51+
[<Fact>] member test.
52+
``empty Seq should fail to not be Empty`` ()=
53+
shouldFail (fun () -> Seq.empty |> should not' (be Empty))
54+
3055

0 commit comments

Comments
 (0)