diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index f1f00149..a5717c4b 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -4,7 +4,8 @@ * Enable substring checks https://github.com/fsprojects/FsUnit/pull/45 * Fixed assertion message for NUnit equal constraint - https://github.com/fsprojects/FsUnit/pull/60 * Added support of `shouldFail` operator for xUnit, MsTest and MbUnit - https://github.com/fsprojects/FsUnit/pull/64 -* Added support of `instanceOfType` operator for xUnit, MsTest and MbUnit - +* Added support of `instanceOfType` operator for xUnit, MsTest and MbUnit - https://github.com/fsprojects/FsUnit/pull/65 +* Added support of `Empty` operator for xUnit, MsTest and MbUnit - ### 1.3.1.0 - 26 July 2015 * Bump NUnit version up to 2.6.4 diff --git a/docs/content/operators.md b/docs/content/operators.md index 6d828a5a..f20961b6 100644 --- a/docs/content/operators.md +++ b/docs/content/operators.md @@ -4,7 +4,7 @@ Operators comparison across frameworks | Operator | NUnit | xUnit | MSTest | MbUnit | |------------------------|:-----:|:-----:|:------:|:------:| | `Null` | + | + | + | + | -| `Empty` | + | | | | +| `Empty` | + | + | + | + | | `EmptyString` | + | + | + | + | | `NullOrEmptyString` | + | + | + | + | | `True` | + | + | + | + | diff --git a/src/FsUnit.MbUnit/FsUnit.fs b/src/FsUnit.MbUnit/FsUnit.fs index 7cfcd097..251e2fa3 100644 --- a/src/FsUnit.MbUnit/FsUnit.fs +++ b/src/FsUnit.MbUnit/FsUnit.fs @@ -37,6 +37,8 @@ let be = CustomMatchers.be let Null = CustomMatchers.Null +let Empty = CustomMatchers.Empty + let EmptyString = CustomMatchers.EmptyString let NullOrEmptyString = CustomMatchers.NullOrEmptyString diff --git a/src/FsUnit.MsTestUnit/FsUnit.fs b/src/FsUnit.MsTestUnit/FsUnit.fs index 4bb4846d..99ff3bbd 100644 --- a/src/FsUnit.MsTestUnit/FsUnit.fs +++ b/src/FsUnit.MsTestUnit/FsUnit.fs @@ -47,6 +47,8 @@ let be = CustomMatchers.be let Null = CustomMatchers.Null +let Empty = CustomMatchers.Empty + let EmptyString = CustomMatchers.EmptyString let NullOrEmptyString = CustomMatchers.NullOrEmptyString diff --git a/src/FsUnit.Xunit/CustomMatchers.fs b/src/FsUnit.Xunit/CustomMatchers.fs index e2f1fc65..afab7747 100644 --- a/src/FsUnit.Xunit/CustomMatchers.fs +++ b/src/FsUnit.Xunit/CustomMatchers.fs @@ -44,6 +44,15 @@ let be = id let Null = Is.Null() +let Empty = CustomMatcher("A non empty", fun o -> + match o with + | :? string as s -> s.Trim() = "" + | :? list<_> as l -> List.isEmpty l + | :? array<_> as a -> Array.isEmpty a + | :? seq<_> as s -> Seq.isEmpty s + | :? System.Collections.IEnumerable as e -> e |> Seq.cast |> Seq.isEmpty + | _ -> false) + let EmptyString = CustomMatcher("A non empty string", fun s -> (string s).Trim() = "") let NullOrEmptyString = CustomMatcher("A not empty or not null string", fun s -> String.IsNullOrEmpty(unbox s)) diff --git a/src/FsUnit.Xunit/FsUnit.fs b/src/FsUnit.Xunit/FsUnit.fs index bbd3c711..0c4acb97 100644 --- a/src/FsUnit.Xunit/FsUnit.fs +++ b/src/FsUnit.Xunit/FsUnit.fs @@ -51,6 +51,8 @@ let be = CustomMatchers.be let Null = CustomMatchers.Null +let Empty = CustomMatchers.Empty + let EmptyString = CustomMatchers.EmptyString let NullOrEmptyString = CustomMatchers.NullOrEmptyString diff --git a/tests/FsUnit.MbUnit.Test/beEmptyTests.fs b/tests/FsUnit.MbUnit.Test/beEmptyTests.fs index ac9ad160..a2dc2b3e 100644 --- a/tests/FsUnit.MbUnit.Test/beEmptyTests.fs +++ b/tests/FsUnit.MbUnit.Test/beEmptyTests.fs @@ -7,25 +7,50 @@ open NHamcrest.Core type ``be Empty tests`` ()= [] member test. ``empty List should be Empty`` ()= - [].IsEmpty |> should be True + [] |> should be Empty + + [] member test. + ``non-empty List should fail to be Empty`` ()= + shouldFail (fun () -> [1] |> should be Empty) [] member test. ``non-empty List should not be Empty`` ()= - [1].IsEmpty |> should not' (be True) + [1] |> should not' (be Empty) + + [] member test. + ``empty List should fail to not be Empty`` ()= + shouldFail (fun () -> [] |> should not' (be Empty)) [] member test. ``empty Array should be Empty`` ()= - [||] |> Array.isEmpty |> should be True + [||] |> should be Empty + + [] member test. + ``non-empty Array should fail to be Empty`` ()= + shouldFail (fun () -> [|1|] |> should be Empty) [] member test. ``non-empty Array should not be Empty`` ()= - [|1|] |> Array.isEmpty |> should not' (be True) + [|1|] |> should not' (be Empty) + + [] member test. + ``empty Array should fail to not be Empty`` ()= + shouldFail (fun () -> [||] |> should not' (be Empty)) [] member test. ``empty Seq should be Empty`` ()= - Seq.empty |> Seq.isEmpty |> should be True + Seq.empty |> should be Empty + + [] member test. + ``non-empty Seq should fail to be Empty`` ()= + shouldFail (fun () -> seq { yield 1 } |> should be Empty) [] member test. ``non-empty Seq should not be Empty`` ()= - seq { yield 1 } |> Seq.isEmpty |> should not' (be True) + seq { yield 1 } |> should not' (be Empty) + + [] member test. + ``empty Seq should fail to not be Empty`` ()= + shouldFail (fun () -> Seq.empty |> should not' (be Empty)) + diff --git a/tests/FsUnit.MsTest.Test/beEmptyTests.fs b/tests/FsUnit.MsTest.Test/beEmptyTests.fs index a136aeec..8ea6ea51 100644 --- a/tests/FsUnit.MsTest.Test/beEmptyTests.fs +++ b/tests/FsUnit.MsTest.Test/beEmptyTests.fs @@ -7,25 +7,49 @@ open NHamcrest.Core type ``be Empty tests`` ()= [] member test. ``empty List should be Empty`` ()= - [].IsEmpty |> should be True + [] |> should be Empty + + [] member test. + ``non-empty List should fail to be Empty`` ()= + shouldFail (fun () -> [1] |> should be Empty) [] member test. ``non-empty List should not be Empty`` ()= - [1].IsEmpty |> should not' (be True) + [1] |> should not' (be Empty) + + [] member test. + ``empty List should fail to not be Empty`` ()= + shouldFail (fun () -> [] |> should not' (be Empty)) [] member test. ``empty Array should be Empty`` ()= - [||] |> Array.isEmpty |> should be True + [||] |> should be Empty + + [] member test. + ``non-empty Array should fail to be Empty`` ()= + shouldFail (fun () -> [|1|] |> should be Empty) [] member test. ``non-empty Array should not be Empty`` ()= - [|1|] |> Array.isEmpty |> should not' (be True) + [|1|] |> should not' (be Empty) + + [] member test. + ``empty Array should fail to not be Empty`` ()= + shouldFail (fun () -> [||] |> should not' (be Empty)) [] member test. ``empty Seq should be Empty`` ()= - Seq.empty |> Seq.isEmpty |> should be True + Seq.empty |> should be Empty + + [] member test. + ``non-empty Seq should fail to be Empty`` ()= + shouldFail (fun () -> seq { yield 1 } |> should be Empty) [] member test. ``non-empty Seq should not be Empty`` ()= - seq { yield 1 } |> Seq.isEmpty |> should not' (be True) + seq { yield 1 } |> should not' (be Empty) + + [] member test. + ``empty Seq should fail to not be Empty`` ()= + shouldFail (fun () -> Seq.empty |> should not' (be Empty)) diff --git a/tests/FsUnit.Xunit.Test/beEmptyTests.fs b/tests/FsUnit.Xunit.Test/beEmptyTests.fs index e344b53e..0c5b404e 100644 --- a/tests/FsUnit.Xunit.Test/beEmptyTests.fs +++ b/tests/FsUnit.Xunit.Test/beEmptyTests.fs @@ -6,25 +6,50 @@ open NHamcrest.Core type ``be Empty tests`` ()= [] member test. ``empty List should be Empty`` ()= - [].IsEmpty |> should be True + [] |> should be Empty + + [] member test. + ``non-empty List should fail to be Empty`` ()= + shouldFail (fun () -> [1] |> should be Empty) [] member test. ``non-empty List should not be Empty`` ()= - [1].IsEmpty |> should not' (be True) + [1] |> should not' (be Empty) + + [] member test. + ``empty List should fail to not be Empty`` ()= + shouldFail (fun () -> [] |> should not' (be Empty)) [] member test. ``empty Array should be Empty`` ()= - [||] |> Array.isEmpty |> should be True + [||] |> should be Empty + + [] member test. + ``non-empty Array should fail to be Empty`` ()= + shouldFail (fun () -> [|1|] |> should be Empty) [] member test. ``non-empty Array should not be Empty`` ()= - [|1|] |> Array.isEmpty |> should not' (be True) + [|1|] |> should not' (be Empty) + + [] member test. + ``empty Array should fail to not be Empty`` ()= + shouldFail (fun () -> [||] |> should not' (be Empty)) [] member test. ``empty Seq should be Empty`` ()= - Seq.empty |> Seq.isEmpty |> should be True + Seq.empty |> should be Empty + + [] member test. + ``non-empty Seq should fail to be Empty`` ()= + shouldFail (fun () -> seq { yield 1 } |> should be Empty) [] member test. ``non-empty Seq should not be Empty`` ()= - seq { yield 1 } |> Seq.isEmpty |> should not' (be True) + seq { yield 1 } |> should not' (be Empty) + + [] member test. + ``empty Seq should fail to not be Empty`` ()= + shouldFail (fun () -> Seq.empty |> should not' (be Empty)) +