Skip to content

Commit

Permalink
Merge pull request #90 from wpetrowski/match-empty-obj-lists
Browse files Browse the repository at this point in the history
matchList can match empty obj lists
  • Loading branch information
sergey-tihon committed May 26, 2016
2 parents 00c2602 + 65fb003 commit 89d3bf6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/FsUnit.Xunit/CustomMatchers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ let containf f = CustomMatcher<obj>(sprintf "Contains %s" (f.ToString()),
let matchList xs = CustomMatcher<obj>(sprintf "All elements from list %s" (xs.ToString()),
fun ys -> match ys with
| :? list<_> as ys' -> List.sort xs = List.sort ys'
| :? System.Collections.IEnumerable as e -> e |> Seq.cast |> Seq.isEmpty && xs |> Seq.isEmpty
| :? _ -> false)

let private makeOrderedMatcher description comparer =
Expand Down
16 changes: 16 additions & 0 deletions tests/FsUnit.MbUnit.Test/matchListTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ type ``match List tests`` ()=
``Empty list should match itself`` () =
([] : List<int>) |> should matchList ([] : List<int>)

[<Test>] member test.
``Empty obj list should match itself`` () =
[] |> should matchList []

[<Test>] member test.
``List with elements should not match empty list`` () =
[1] |> should not' (matchList [])

[<Test>] member test.
``Empty list should not match list with elements`` () =
[] |> should not' (matchList ["abc"])

[<Test>] member test.
``Single element list should match itself`` () =
[1] |> should matchList [1]
Expand All @@ -24,3 +36,7 @@ type ``match List tests`` ()=
[<Test>] member test.
``Lists with different lengths doesn't match`` () =
["something","is","missed"] |> should not' (matchList ["something", "is", "missed", "here"])

[<Test>] member test.
``Comparing scalar to list should not match`` () =
47 |> should not' (matchList [47])
16 changes: 16 additions & 0 deletions tests/FsUnit.MsTest.Test/matchListTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ type ``match List tests`` ()=
``Empty list should match itself`` () =
([] : List<int>) |> should matchList ([] : List<int>)

[<TestMethod>] member test.
``Empty obj list should match itself`` () =
[] |> should matchList []

[<TestMethod>] member test.
``List with elements should not match empty list`` () =
[1] |> should not' (matchList [])

[<TestMethod>] member test.
``Empty list should not match list with elements`` () =
[] |> should not' (matchList ["abc"])

[<TestMethod>] member test.
``Single element list should match itself`` () =
[1] |> should matchList [1]
Expand All @@ -24,3 +36,7 @@ type ``match List tests`` ()=
[<TestMethod>] member test.
``Lists with different lengths doesn't match`` () =
["something","is","missed"] |> should not' (matchList ["something", "is", "missed", "here"])

[<TestMethod>] member test.
``Comparing scalar to list should not match`` () =
47 |> should not' (matchList [47])
16 changes: 16 additions & 0 deletions tests/FsUnit.Xunit.Test/matchListTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ type ``match List tests`` ()=
``Empty list should match itself`` () =
([] : List<int>) |> should matchList ([] : List<int>)

[<Fact>] member test.
``Empty obj list should match itself`` () =
[] |> should matchList []

[<Fact>] member test.
``List with elements should not match empty list`` () =
[1] |> should not' (matchList [])

[<Fact>] member test.
``Empty list should not match list with elements`` () =
[] |> should not' (matchList ["abc"])

[<Fact>] member test.
``Single element list should match itself`` () =
[1] |> should matchList [1]
Expand All @@ -23,3 +35,7 @@ type ``match List tests`` ()=
[<Fact>] member test.
``Lists with different lengths doesn't match`` () =
["something","is","missed"] |> should not' (matchList ["something", "is", "missed", "here"])

[<Fact>] member test.
``Comparing scalar to list should not match`` () =
47 |> should not' (matchList [47])

0 comments on commit 89d3bf6

Please sign in to comment.