Skip to content

Commit 21ab9a1

Browse files
authored
Merge pull request #222 from CaptnCodr/feature/equalSeq
Add equalSeq as operator
2 parents 379da2b + 832e83d commit 21ab9a1

File tree

19 files changed

+125
-17
lines changed

19 files changed

+125
-17
lines changed

.config/dotnet-tools.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
]
1010
},
1111
"fake-cli": {
12-
"version": "5.23.0",
12+
"version": "5.23.1",
1313
"commands": [
1414
"fake"
1515
]
@@ -21,7 +21,7 @@
2121
]
2222
},
2323
"fantomas": {
24-
"version": "5.0.0",
24+
"version": "5.0.6",
2525
"commands": [
2626
"fantomas"
2727
]

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ jobs:
1919
runs-on: ${{ matrix.os }}
2020

2121
steps:
22-
- uses: actions/checkout@v1
22+
- uses: actions/checkout@v3
2323

2424
- name: Setup .NET Core
25-
uses: actions/setup-dotnet@v1
25+
uses: actions/setup-dotnet@v3
2626
with:
2727
dotnet-version: ${{ matrix.dotnet }}
2828

docs/MsTest.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// This block of code is omitted in the generated HTML documentation. Use
33
// it to define helpers that you do not want to show in the documentation.
44
#r "../packages/MSTest.TestFramework/lib/netstandard1.0/Microsoft.VisualStudio.TestPlatform.TestFramework.dll"
5-
#r "../packages/NHamcrest/lib/netstandard1.5/NHamcrest.dll"
5+
#r "../packages/NHamcrest/lib/netstandard2.0/NHamcrest.dll"
66
#r "../bin/FsUnit.MsTest/netstandard2.0/FsUnit.MsTest.dll"
77

88
(**

docs/index.fsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ One object equals or does not equal another:
4646
1 |> should equal 1
4747
1 |> should not' (equal 2)
4848

49+
(**
50+
One sequence equals or does not equal another:
51+
*)
52+
seq { 1; 2; 3 } |> should equalSeq (seq { 1; 2; 3 })
53+
seq { 1 } |> should not' (equalSeq (seq { 1; 2}))
54+
4955
(**
5056
One collection is equivalent or is not equivalent to another (order doesn't matter):
5157
*)

docs/operators.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Operators comparison across frameworks
1313
| `unique` ||||
1414
| `should` ||||
1515
| `equal` ||||
16+
| `equalSeq` ||||
1617
| `equivalent` ||||
1718
| `equalWithin` ||||
1819
| `contain` ||||

docs/xUnit.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// This block of code is omitted in the generated HTML documentation. Use
33
// it to define helpers that you do not want to show in the documentation.
44
#r "../packages/xunit.extensibility.core/lib/netstandard1.1/xunit.core.dll"
5-
#r "../packages/NHamcrest/lib/netstandard1.5/NHamcrest.dll"
5+
#r "../packages/NHamcrest/lib/netstandard2.0/NHamcrest.dll"
66
#r "../bin/FsUnit.Xunit/netstandard2.0/FsUnit.Xunit.dll"
77

88
(**

paket.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ RESTRICTION: || (== net6.0) (== netstandard2.0)
22
NUGET
33
remote: https://api.nuget.org/v3/index.json
44
FSharp.Core (5.0.2)
5-
Microsoft.CodeCoverage (17.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= net45)) (&& (== netstandard2.0) (>= netcoreapp1.0))
6-
Microsoft.NET.Test.Sdk (17.3.1)
7-
Microsoft.CodeCoverage (>= 17.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= net45)) (&& (== netstandard2.0) (>= netcoreapp1.0))
8-
Microsoft.TestPlatform.TestHost (>= 17.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0))
9-
Microsoft.NETCore.Platforms (6.0.5)
5+
Microsoft.CodeCoverage (17.3.2) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= net45)) (&& (== netstandard2.0) (>= netcoreapp1.0))
6+
Microsoft.NET.Test.Sdk (17.3.2)
7+
Microsoft.CodeCoverage (>= 17.3.2) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= net45)) (&& (== netstandard2.0) (>= netcoreapp1.0))
8+
Microsoft.TestPlatform.TestHost (>= 17.3.2) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0))
9+
Microsoft.NETCore.Platforms (6.0.6)
1010
Microsoft.NETCore.Targets (5.0)
11-
Microsoft.TestPlatform.ObjectModel (17.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0))
11+
Microsoft.TestPlatform.ObjectModel (17.3.2) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0))
1212
NuGet.Frameworks (>= 5.11)
1313
System.Reflection.Metadata (>= 1.6)
14-
Microsoft.TestPlatform.TestHost (17.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0))
15-
Microsoft.TestPlatform.ObjectModel (>= 17.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) (&& (== netstandard2.0) (>= uap10.0))
14+
Microsoft.TestPlatform.TestHost (17.3.2) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0))
15+
Microsoft.TestPlatform.ObjectModel (>= 17.3.2) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) (&& (== netstandard2.0) (>= uap10.0))
1616
Newtonsoft.Json (>= 9.0.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) (&& (== netstandard2.0) (>= uap10.0))
1717
MSTest.TestAdapter (2.1.2)
1818
NETStandard.Library (>= 1.6.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0))
@@ -24,7 +24,7 @@ NUGET
2424
Microsoft.NETCore.Platforms (>= 1.1)
2525
Newtonsoft.Json (13.0.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0))
2626
NHamcrest (3.0.1)
27-
NuGet.Frameworks (6.3) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) (&& (== netstandard2.0) (>= netcoreapp2.1))
27+
NuGet.Frameworks (6.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) (&& (== netstandard2.0) (>= netcoreapp2.1))
2828
NUnit (3.13.3)
2929
NETStandard.Library (>= 2.0)
3030
NUnit3TestAdapter (4.2.1)

src/FsUnit.MsTestUnit/FsUnit.MsTest.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
44
<AssemblyName>FsUnit.MsTest</AssemblyName>

src/FsUnit.MsTestUnit/FsUnit.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ let inline shouldFail(f: unit -> unit) =
5555
let equal expected =
5656
CustomMatchers.equal expected
5757

58+
let equalSeq expected =
59+
CustomMatchers.equalSeq (fun (e: seq<'a>) (a: seq<'a>) -> Assert.IsTrue(Linq.Enumerable.SequenceEqual(e, a))) expected
60+
5861
let equivalent expected =
5962
CustomMatchers.equivalent (fun e a -> CollectionAssert.AreEquivalent(e, a)) expected
6063

src/FsUnit.NUnit/FsUnit.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ module TopLevelOperators =
4646
let equal expected =
4747
Equality.IsEqualTo(expected)
4848

49+
let equalSeq(expected: seq<'a>) =
50+
EqualConstraint(expected)
51+
4952
let equivalent expected =
5053
CollectionEquivalentConstraint(expected)
5154

src/FsUnit.Xunit/CustomMatchers.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ open System.Reflection
1010
let equal expected =
1111
CustomMatcher<obj>($"Equals %A{expected}", (fun actual -> expected = actual))
1212

13+
let equalSeq (func: seq<'a> -> seq<'a> -> unit) (expected: seq<'a>) =
14+
let matches(actual: obj) =
15+
try
16+
func expected (unbox(actual))
17+
true
18+
with _ ->
19+
false
20+
21+
CustomMatcher<obj>($"Equals %A{expected}", Func<_, _> matches)
22+
1323
let equivalent f expected =
1424
let matches(actual: obj) =
1525
try

src/FsUnit.Xunit/FsUnit.Xunit.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
44
<AssemblyName>FsUnit.Xunit</AssemblyName>

src/FsUnit.Xunit/FsUnit.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ let inline shouldFail(f: unit -> unit) =
5353
if not failed then
5454
raise(MatchException("Method should fail", "No exception raised", null))
5555

56+
let equalSeq expected =
57+
CustomMatchers.equalSeq (fun (e: seq<'a>) (a: seq<'a>) -> Assert.Equal<seq<'a>>(e, a)) expected
5658

5759
let equal expected =
5860
CustomMatchers.equal expected

tests/FsUnit.MsTest.Test/FsUnit.MsTest.Test.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<Compile Include="beTrueTests.fs" />
2727
<Compile Include="containTests.fs" />
2828
<Compile Include="equalTests.fs" />
29+
<Compile Include="equalSeqTests.fs" />
2930
<Compile Include="equalWithinTests.fs" />
3031
<Compile Include="haveCountTests.fs" />
3132
<Compile Include="haveLengthTests.fs" />
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace FsUnit.Test
2+
3+
open Microsoft.VisualStudio.TestTools.UnitTesting
4+
open FsUnit.MsTest
5+
6+
[<TestClass>]
7+
type ``equalSeq Tests``() =
8+
9+
[<TestMethod>]
10+
member _.``sequence should equal sequence``() =
11+
Seq.init 3 ((+) 1) |> should equalSeq (Seq.init 3 ((+) 1))
12+
13+
[<TestMethod>]
14+
member _.``sequence should not equal sequence``() =
15+
Seq.init 3 ((+) 1) |> should not' (equalSeq(Seq.init 3 ((-) 3)))
16+
17+
[<TestMethod>]
18+
member _.``filled sequence should not equal empty sequence``() =
19+
Seq.init 3 ((+) 1) |> should not' (equalSeq Seq.empty)
20+
21+
[<TestMethod>]
22+
member _.``empty sequence should equal empty sequence``() =
23+
Seq.empty |> should equalSeq Seq.empty
24+
25+
[<TestMethod>]
26+
member _.``sequence should not equal another sequence``() =
27+
Seq.init 4 ((+) 1) |> should not' (equalSeq(Seq.init 5 ((+) 1)))

tests/FsUnit.NUnit.Test/FsUnit.NUnit.Test.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<Compile Include="beSameAsTests.fs" />
2121
<Compile Include="containTests.fs" />
2222
<Compile Include="equalTests.fs" />
23+
<Compile Include="equalSeqTests.fs" />
2324
<Compile Include="raiseTests.fs" />
2425
<Compile Include="haveLengthTests.fs" />
2526
<Compile Include="haveCountTests.fs" />
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace FsUnit.Test
2+
3+
open System
4+
open NUnit.Framework
5+
open FsUnit
6+
7+
type ``equalSeq Tests``() =
8+
9+
[<Test>]
10+
member _.``sequence should equal sequence``() =
11+
Seq.init 3 ((+) 1) |> should equalSeq (Seq.init 3 ((+) 1))
12+
13+
[<Test>]
14+
member _.``sequence should not equal sequence``() =
15+
Seq.init 3 ((+) 1) |> should not' (equalSeq(Seq.init 3 ((-) 3)))
16+
17+
[<Test>]
18+
member _.``filled sequence should not equal empty sequence``() =
19+
Seq.init 3 ((+) 1) |> should not' (equalSeq Seq.empty)
20+
21+
[<Test>]
22+
member _.``empty sequence should equal empty sequence``() =
23+
Seq.empty |> should equalSeq Seq.empty
24+
25+
[<Test>]
26+
member _.``sequence should not equal another sequence``() =
27+
Seq.init 4 ((+) 1) |> should not' (equalSeq(Seq.init 5 ((+) 1)))

tests/FsUnit.Xunit.Test/FsUnit.Xunit.Test.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<Compile Include="beAscendingTests.fs" />
77
<Compile Include="beDescendingTests.fs" />
88
<Compile Include="equalTests.fs" />
9+
<Compile Include="equalSeqTests.fs" />
910
<Compile Include="containTests.fs" />
1011
<Compile Include="beChoice.fs" />
1112
<Compile Include="beEmptyStringTests.fs" />
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace FsUnit.Test
2+
3+
open Xunit
4+
open FsUnit.Xunit
5+
6+
type ``equalSeq Tests``() =
7+
8+
[<Fact>]
9+
member _.``sequence should equal sequence``() =
10+
Seq.init 3 ((+) 1) |> should equalSeq (Seq.init 3 ((+) 1))
11+
12+
[<Fact>]
13+
member _.``sequence should not equal sequence``() =
14+
Seq.init 3 ((+) 1) |> should not' (equalSeq(Seq.init 3 ((-) 3)))
15+
16+
[<Fact>]
17+
member _.``filled sequence should not equal empty sequence``() =
18+
Seq.init 3 ((+) 1) |> should not' (equalSeq Seq.empty)
19+
20+
[<Fact>]
21+
member _.``empty sequence should equal empty sequence``() =
22+
Seq.empty |> should equalSeq Seq.empty
23+
24+
[<Fact>]
25+
member _.``sequence should not equal another sequence``() =
26+
Seq.init 4 ((+) 1) |> should not' (equalSeq(Seq.init 5 ((+) 1)))

0 commit comments

Comments
 (0)