Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add equalSeq as operator #222

Merged
merged 6 commits into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
]
},
"fake-cli": {
"version": "5.23.0",
"version": "5.23.1",
"commands": [
"fake"
]
Expand All @@ -21,7 +21,7 @@
]
},
"fantomas": {
"version": "5.0.0",
"version": "5.0.6",
"commands": [
"fantomas"
]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet }}

Expand Down
2 changes: 1 addition & 1 deletion docs/MsTest.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This block of code is omitted in the generated HTML documentation. Use
// it to define helpers that you do not want to show in the documentation.
#r "../packages/MSTest.TestFramework/lib/netstandard1.0/Microsoft.VisualStudio.TestPlatform.TestFramework.dll"
#r "../packages/NHamcrest/lib/netstandard1.5/NHamcrest.dll"
#r "../packages/NHamcrest/lib/netstandard2.0/NHamcrest.dll"
#r "../bin/FsUnit.MsTest/netstandard2.0/FsUnit.MsTest.dll"

(**
Expand Down
6 changes: 6 additions & 0 deletions docs/index.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ One object equals or does not equal another:
1 |> should equal 1
1 |> should not' (equal 2)

(**
One sequence equals or does not equal another:
*)
seq { 1; 2; 3 } |> should equalSeq (seq { 1; 2; 3 })
seq { 1 } |> should not' (equalSeq (seq { 1; 2}))

(**
One collection is equivalent or is not equivalent to another (order doesn't matter):
*)
Expand Down
1 change: 1 addition & 0 deletions docs/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Operators comparison across frameworks
| `unique` | ✔ | ✔ | ✔ |
| `should` | ✔ | ✔ | ✔ |
| `equal` | ✔ | ✔ | ✔ |
| `equalSeq` | ✔ | ✔ | ✔ |
| `equivalent` | ✔ | ❌ | ✔ |
| `equalWithin` | ✔ | ✔ | ✔ |
| `contain` | ✔ | ✔ | ✔ |
Expand Down
2 changes: 1 addition & 1 deletion docs/xUnit.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This block of code is omitted in the generated HTML documentation. Use
// it to define helpers that you do not want to show in the documentation.
#r "../packages/xunit.extensibility.core/lib/netstandard1.1/xunit.core.dll"
#r "../packages/NHamcrest/lib/netstandard1.5/NHamcrest.dll"
#r "../packages/NHamcrest/lib/netstandard2.0/NHamcrest.dll"
#r "../bin/FsUnit.Xunit/netstandard2.0/FsUnit.Xunit.dll"

(**
Expand Down
18 changes: 9 additions & 9 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ RESTRICTION: || (== net6.0) (== netstandard2.0)
NUGET
remote: https://api.nuget.org/v3/index.json
FSharp.Core (5.0.2)
Microsoft.CodeCoverage (17.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= net45)) (&& (== netstandard2.0) (>= netcoreapp1.0))
Microsoft.NET.Test.Sdk (17.3.1)
Microsoft.CodeCoverage (>= 17.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= net45)) (&& (== netstandard2.0) (>= netcoreapp1.0))
Microsoft.TestPlatform.TestHost (>= 17.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0))
Microsoft.NETCore.Platforms (6.0.5)
Microsoft.CodeCoverage (17.3.2) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= net45)) (&& (== netstandard2.0) (>= netcoreapp1.0))
Microsoft.NET.Test.Sdk (17.3.2)
Microsoft.CodeCoverage (>= 17.3.2) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= net45)) (&& (== netstandard2.0) (>= netcoreapp1.0))
Microsoft.TestPlatform.TestHost (>= 17.3.2) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0))
Microsoft.NETCore.Platforms (6.0.6)
Microsoft.NETCore.Targets (5.0)
Microsoft.TestPlatform.ObjectModel (17.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0))
Microsoft.TestPlatform.ObjectModel (17.3.2) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0))
NuGet.Frameworks (>= 5.11)
System.Reflection.Metadata (>= 1.6)
Microsoft.TestPlatform.TestHost (17.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0))
Microsoft.TestPlatform.ObjectModel (>= 17.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) (&& (== netstandard2.0) (>= uap10.0))
Microsoft.TestPlatform.TestHost (17.3.2) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0))
Microsoft.TestPlatform.ObjectModel (>= 17.3.2) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) (&& (== netstandard2.0) (>= uap10.0))
Newtonsoft.Json (>= 9.0.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) (&& (== netstandard2.0) (>= uap10.0))
MSTest.TestAdapter (2.1.2)
NETStandard.Library (>= 1.6.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0))
Expand All @@ -24,7 +24,7 @@ NUGET
Microsoft.NETCore.Platforms (>= 1.1)
Newtonsoft.Json (13.0.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0))
NHamcrest (3.0.1)
NuGet.Frameworks (6.3) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) (&& (== netstandard2.0) (>= netcoreapp2.1))
NuGet.Frameworks (6.3.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp1.0)) (&& (== netstandard2.0) (>= netcoreapp2.1))
NUnit (3.13.3)
NETStandard.Library (>= 2.0)
NUnit3TestAdapter (4.2.1)
Expand Down
2 changes: 1 addition & 1 deletion src/FsUnit.MsTestUnit/FsUnit.MsTest.fsproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
<AssemblyName>FsUnit.MsTest</AssemblyName>
Expand Down
3 changes: 3 additions & 0 deletions src/FsUnit.MsTestUnit/FsUnit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ let inline shouldFail(f: unit -> unit) =
let equal expected =
CustomMatchers.equal expected

let equalSeq expected =
CustomMatchers.equalSeq (fun (e: seq<'a>) (a: seq<'a>) -> Assert.IsTrue(Linq.Enumerable.SequenceEqual(e, a))) expected

let equivalent expected =
CustomMatchers.equivalent (fun e a -> CollectionAssert.AreEquivalent(e, a)) expected

Expand Down
3 changes: 3 additions & 0 deletions src/FsUnit.NUnit/FsUnit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ module TopLevelOperators =
let equal expected =
Equality.IsEqualTo(expected)

let equalSeq(expected: seq<'a>) =
EqualConstraint(expected)

let equivalent expected =
CollectionEquivalentConstraint(expected)

Expand Down
10 changes: 10 additions & 0 deletions src/FsUnit.Xunit/CustomMatchers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ open System.Reflection
let equal expected =
CustomMatcher<obj>($"Equals %A{expected}", (fun actual -> expected = actual))

let equalSeq (func: seq<'a> -> seq<'a> -> unit) (expected: seq<'a>) =
let matches(actual: obj) =
try
func expected (unbox(actual))
true
with _ ->
false

CustomMatcher<obj>($"Equals %A{expected}", Func<_, _> matches)

let equivalent f expected =
let matches(actual: obj) =
try
Expand Down
2 changes: 1 addition & 1 deletion src/FsUnit.Xunit/FsUnit.Xunit.fsproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
<AssemblyName>FsUnit.Xunit</AssemblyName>
Expand Down
2 changes: 2 additions & 0 deletions src/FsUnit.Xunit/FsUnit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ let inline shouldFail(f: unit -> unit) =
if not failed then
raise(MatchException("Method should fail", "No exception raised", null))

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

let equal expected =
CustomMatchers.equal expected
Expand Down
1 change: 1 addition & 0 deletions tests/FsUnit.MsTest.Test/FsUnit.MsTest.Test.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<Compile Include="beTrueTests.fs" />
<Compile Include="containTests.fs" />
<Compile Include="equalTests.fs" />
<Compile Include="equalSeqTests.fs" />
<Compile Include="equalWithinTests.fs" />
<Compile Include="haveCountTests.fs" />
<Compile Include="haveLengthTests.fs" />
Expand Down
27 changes: 27 additions & 0 deletions tests/FsUnit.MsTest.Test/equalSeqTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace FsUnit.Test

open Microsoft.VisualStudio.TestTools.UnitTesting
open FsUnit.MsTest

[<TestClass>]
type ``equalSeq Tests``() =

[<TestMethod>]
member _.``sequence should equal sequence``() =
Seq.init 3 ((+) 1) |> should equalSeq (Seq.init 3 ((+) 1))

[<TestMethod>]
member _.``sequence should not equal sequence``() =
Seq.init 3 ((+) 1) |> should not' (equalSeq(Seq.init 3 ((-) 3)))

[<TestMethod>]
member _.``filled sequence should not equal empty sequence``() =
Seq.init 3 ((+) 1) |> should not' (equalSeq Seq.empty)

[<TestMethod>]
member _.``empty sequence should equal empty sequence``() =
Seq.empty |> should equalSeq Seq.empty

[<TestMethod>]
member _.``sequence should not equal another sequence``() =
Seq.init 4 ((+) 1) |> should not' (equalSeq(Seq.init 5 ((+) 1)))
1 change: 1 addition & 0 deletions tests/FsUnit.NUnit.Test/FsUnit.NUnit.Test.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<Compile Include="beSameAsTests.fs" />
<Compile Include="containTests.fs" />
<Compile Include="equalTests.fs" />
<Compile Include="equalSeqTests.fs" />
<Compile Include="raiseTests.fs" />
<Compile Include="haveLengthTests.fs" />
<Compile Include="haveCountTests.fs" />
Expand Down
27 changes: 27 additions & 0 deletions tests/FsUnit.NUnit.Test/equalSeqTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace FsUnit.Test

open System
open NUnit.Framework
open FsUnit

type ``equalSeq Tests``() =

[<Test>]
member _.``sequence should equal sequence``() =
Seq.init 3 ((+) 1) |> should equalSeq (Seq.init 3 ((+) 1))

[<Test>]
member _.``sequence should not equal sequence``() =
Seq.init 3 ((+) 1) |> should not' (equalSeq(Seq.init 3 ((-) 3)))

[<Test>]
member _.``filled sequence should not equal empty sequence``() =
Seq.init 3 ((+) 1) |> should not' (equalSeq Seq.empty)

[<Test>]
member _.``empty sequence should equal empty sequence``() =
Seq.empty |> should equalSeq Seq.empty

[<Test>]
member _.``sequence should not equal another sequence``() =
Seq.init 4 ((+) 1) |> should not' (equalSeq(Seq.init 5 ((+) 1)))
1 change: 1 addition & 0 deletions tests/FsUnit.Xunit.Test/FsUnit.Xunit.Test.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<Compile Include="beAscendingTests.fs" />
<Compile Include="beDescendingTests.fs" />
<Compile Include="equalTests.fs" />
<Compile Include="equalSeqTests.fs" />
<Compile Include="containTests.fs" />
<Compile Include="beChoice.fs" />
<Compile Include="beEmptyStringTests.fs" />
Expand Down
26 changes: 26 additions & 0 deletions tests/FsUnit.Xunit.Test/equalSeqTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace FsUnit.Test

open Xunit
open FsUnit.Xunit

type ``equalSeq Tests``() =

[<Fact>]
member _.``sequence should equal sequence``() =
Seq.init 3 ((+) 1) |> should equalSeq (Seq.init 3 ((+) 1))

[<Fact>]
member _.``sequence should not equal sequence``() =
Seq.init 3 ((+) 1) |> should not' (equalSeq(Seq.init 3 ((-) 3)))

[<Fact>]
member _.``filled sequence should not equal empty sequence``() =
Seq.init 3 ((+) 1) |> should not' (equalSeq Seq.empty)

[<Fact>]
member _.``empty sequence should equal empty sequence``() =
Seq.empty |> should equalSeq Seq.empty

[<Fact>]
member _.``sequence should not equal another sequence``() =
Seq.init 4 ((+) 1) |> should not' (equalSeq(Seq.init 5 ((+) 1)))