diff --git a/tests/FsUnit.Xunit.Test/typed.beEmptyTests.fs b/tests/FsUnit.Xunit.Test/typed.beEmptyTests.fs new file mode 100644 index 00000000..3ea80fa4 --- /dev/null +++ b/tests/FsUnit.Xunit.Test/typed.beEmptyTests.fs @@ -0,0 +1,29 @@ +namespace FsUnit.Typed.Test + +open Xunit +open FsUnitTyped + +type ``shouldBeEmpty tests``() = + [] + member __.``empty List should be Empty``() = + [] |> shouldBeEmpty + + [] + member __.``non-empty List should fail to be Empty``() = + shouldFail(fun () -> [ 1 ] |> shouldBeEmpty) + + [] + member __.``empty Array should be Empty``() = + [||] |> shouldBeEmpty + + [] + member __.``non-empty Array should fail to be Empty``() = + shouldFail(fun () -> [| 1 |] |> shouldBeEmpty) + + [] + member __.``empty Seq should be Empty``() = + Seq.empty |> shouldBeEmpty + + [] + member __.``non-empty Seq should fail to be Empty``() = + shouldFail(fun () -> seq { 1 } |> shouldBeEmpty) diff --git a/tests/FsUnit.Xunit.Test/typed.haveLengthTests.fs b/tests/FsUnit.Xunit.Test/typed.haveLengthTests.fs new file mode 100644 index 00000000..1e8228b2 --- /dev/null +++ b/tests/FsUnit.Xunit.Test/typed.haveLengthTests.fs @@ -0,0 +1,23 @@ +namespace FsUnit.Typed.Test + +open Xunit +open FsUnitTyped + +type ``haveLength tests``() = + // F# List + [] + member __.``List with 1 item should have Length 1``() = + [ 1 ] |> shouldHaveLength 1 + + [] + member __.``empty List should fail to have Length 1``() = + shouldFail(fun () -> [] |> shouldHaveLength 1) + + // Array + [] + member __.``Array with 1 item should have Length 1``() = + [| 1 |] |> shouldHaveLength 1 + + [] + member __.``empty Array should fail to have Length 1``() = + shouldFail(fun () -> [||] |> shouldHaveLength 1) diff --git a/tests/FsUnit.Xunit.Test/typed.shouldBeGreaterThanTests.fs b/tests/FsUnit.Xunit.Test/typed.shouldBeGreaterThanTests.fs new file mode 100644 index 00000000..7f1a742a --- /dev/null +++ b/tests/FsUnit.Xunit.Test/typed.shouldBeGreaterThanTests.fs @@ -0,0 +1,13 @@ +namespace FsUnit.Typed.Test + +open Xunit +open FsUnitTyped + +type ``shouldBeGreaterThan tests``() = + [] + member __.``11 should be greater than 10``() = + 11 |> shouldBeGreaterThan 10 + + [] + member __.``11[dot]1 should be greater than 11[dot]0``() = + 11.1 |> shouldBeGreaterThan 11.0 diff --git a/tests/FsUnit.Xunit.Test/typed.shouldBeSmallerThanTests.fs b/tests/FsUnit.Xunit.Test/typed.shouldBeSmallerThanTests.fs new file mode 100644 index 00000000..fc11b696 --- /dev/null +++ b/tests/FsUnit.Xunit.Test/typed.shouldBeSmallerThanTests.fs @@ -0,0 +1,23 @@ +namespace FsUnit.Typed.Test + +open Xunit +open FsUnitTyped + +type ``shouldBeSmallerThan tests``() = + [] + member __.``10 should be less than 11``() = + 10 |> shouldBeSmallerThan 11 + + [] + member __.``10 should not be less than 10``() = + (fun () -> 10 |> shouldBeSmallerThan 10) + |> shouldFail + + [] + member __.``10[dot]0 should be less than 10[dot]1``() = + 10.0 |> shouldBeSmallerThan 10.1 + + [] + member __.``10[dot]0 should not be less than 10[dot]0``() = + (fun () -> 10.0 |> shouldBeSmallerThan 10.0) + |> shouldFail diff --git a/tests/FsUnit.Xunit.Test/typed.shouldContainTests.fs b/tests/FsUnit.Xunit.Test/typed.shouldContainTests.fs new file mode 100644 index 00000000..baa4b442 --- /dev/null +++ b/tests/FsUnit.Xunit.Test/typed.shouldContainTests.fs @@ -0,0 +1,53 @@ +namespace FsUnit.Typed.Test + +open Xunit +open FsUnitTyped + +type ``shouldContain tests``() = + [] + member __.``List with item should contain item``() = + [ 1 ] |> shouldContain 1 + + [] + member __.``empty List should fail to contain item``() = + shouldFail(fun () -> [] |> shouldContain 1) + + [] + member __.``empty List should not contain item``() = + [] |> shouldNotContain 1 + + [] + member __.``List with item should fail to not contain item``() = + shouldFail(fun () -> [ 1 ] |> shouldNotContain 1) + + [] + member __.``Array with item should contain item``() = + [| 1 |] |> shouldContain 1 + + [] + member __.``empty Array should fail to contain item``() = + shouldFail(fun () -> [||] |> shouldContain 1) + + [] + member __.``empty Array should not contain item``() = + [||] |> shouldNotContain 1 + + [] + member __.``Array with item should fail to not contain item``() = + shouldFail(fun () -> [| 1 |] |> shouldNotContain 1) + + [] + member __.``Seq with item should contain item``() = + seq { 1 } |> shouldContain 1 + + [] + member __.``empty Seq should fail to contain item``() = + shouldFail(fun () -> Seq.empty |> shouldContain 1) + + [] + member __.``empty Seq should not contain item``() = + Seq.empty |> shouldNotContain 1 + + [] + member __.``Seq with item should fail to not contain item``() = + shouldFail(fun () -> seq { 1 } |> shouldNotContain 1) diff --git a/tests/FsUnit.Xunit.Test/typed.shouldContainText.fs b/tests/FsUnit.Xunit.Test/typed.shouldContainText.fs new file mode 100644 index 00000000..5e377602 --- /dev/null +++ b/tests/FsUnit.Xunit.Test/typed.shouldContainText.fs @@ -0,0 +1,13 @@ +namespace FsUnit.Typed.Test + +open Xunit +open FsUnitTyped + +type ``shouldContainText tests``() = + [] + member __.``empty string should contain ""``() = + "" |> shouldContainText "" + + [] + member __.``ships should contain hip``() = + "ships" |> shouldContainText "hip" diff --git a/tests/FsUnit.Xunit.Test/typed.shouldEqualNullTests.fs b/tests/FsUnit.Xunit.Test/typed.shouldEqualNullTests.fs new file mode 100644 index 00000000..4c294380 --- /dev/null +++ b/tests/FsUnit.Xunit.Test/typed.shouldEqualNullTests.fs @@ -0,0 +1,13 @@ +namespace FsUnit.Typed.Test + +open Xunit +open FsUnitTyped + +type ``Typed: shouldEqual null tests``() = + [] + member __.``null should be null``() = + null |> shouldEqual null + + [] + member __.``null should fail to not be null``() = + shouldFail(fun () -> null |> shouldNotEqual null) diff --git a/tests/FsUnit.Xunit.Test/typed.shouldEqualTests.fs b/tests/FsUnit.Xunit.Test/typed.shouldEqualTests.fs new file mode 100644 index 00000000..2f7e866e --- /dev/null +++ b/tests/FsUnit.Xunit.Test/typed.shouldEqualTests.fs @@ -0,0 +1,133 @@ +namespace FsUnit.Typed.Test + +open System.Collections.Immutable + +open Xunit +open FsUnitTyped +open FsUnit +open System + +type AlwaysEqual() = + override __.Equals(other) = true + override __.GetHashCode() = 1 + +type NeverEqual() = + override __.Equals(other) = false + override __.GetHashCode() = 1 + +type ``shouldEqual Tests``() = + let anObj = new obj() + let otherObj = new obj() + let anImmutableArray = ImmutableArray.Create(1, 2, 3) + let equivalentImmutableArray = ImmutableArray.Create(1, 2, 3) + let otherImmutableArray = ImmutableArray.Create(1, 2, 4) + + [] + member __.``value type should equal equivalent value``() = + 1 |> shouldEqual 1 + + [] + member __.``value type should fail to equal nonequivalent value``() = + shouldFail(fun () -> 1 |> shouldEqual 2) + + [] + member __.``value type should not equal nonequivalent value``() = + 1 |> shouldNotEqual 2 + + [] + member __.``value type should fail to not equal equivalent value``() = + shouldFail(fun () -> 1 |> shouldNotEqual 1) + + [] + member __.``reference type should equal itself``() = + anObj |> shouldEqual anObj + + [] + member __.``reference type should fail to equal other``() = + shouldFail(fun () -> anObj |> shouldEqual otherObj) + + [] + member __.``reference type should not equal other``() = + anObj |> shouldNotEqual otherObj + + [] + member __.``reference type should fail to not equal itself``() = + shouldFail(fun () -> anObj |> shouldNotEqual anObj) + + [] + member __.``should pass when Equals returns true``() = + anObj |> shouldEqual(box(new AlwaysEqual())) + + [] + member __.``should fail when Equals returns false``() = + shouldFail(fun () -> anObj |> shouldEqual(box(new NeverEqual()))) + + [] + member __.``should pass when negated and Equals returns false``() = + anObj |> shouldNotEqual(box(new NeverEqual())) + + [] + member __.``should fail when negated and Equals returns true``() = + shouldFail(fun () -> anObj |> shouldNotEqual(box(new AlwaysEqual()))) + + [] + member __.``None should equal None``() = + None |> shouldEqual None + + [] + member __.``Error "Foo" should equal Error "Foo"``() = + Error "Foo" |> shouldEqual(Error "Foo") + + [] + member __.``Error "Foo" should equal fails and have same message``() = + (fun () -> Error "Foo" |> shouldEqual(Error "Bar")) + |> Assert.Throws + |> fun e -> + e.Message + |> should + equal + (sprintf " Expected: Error \"Bar\" or Error \"Bar\"%s But was: Error \"Foo\"%s" Environment.NewLine Environment.NewLine) + + [] + member __.``Error "Foo" should not equal Error "Bar"``() = + Error "Foo" |> shouldNotEqual(Error "Bar") + + [] + member __.``Error "Foo" should not equal Error "Bar" fails and have same message``() = + (fun () -> Error "Foo" |> shouldNotEqual(Error "Foo")) + |> Assert.Throws + |> fun e -> + e.Message + |> should + equal + (sprintf " Expected: not Error \"Foo\" or Error \"Foo\"%s But was: Error \"Foo\"%s" Environment.NewLine Environment.NewLine) + + [] + member this.``structural equality``() = + let actualList: char list = [] + [ (actualList, "") ] |> shouldEqual [ ([], "") ] + + [] + member __.``Empty obj list should match itself``() = + [] |> shouldEqual [] + + [] + member __.``List with elements should not match empty list``() = + [ 1 ] |> shouldNotEqual [] + + [] + member __.``structural value type should equal equivalent value``() = + anImmutableArray |> shouldEqual equivalentImmutableArray + + [] + member __.``structural value type should not equal non-equivalent value``() = + anImmutableArray |> shouldNotEqual otherImmutableArray + + [] + member __.``structural comparable type containing non-equivalent structural equatable type fails with correct exception``() = + let array1 = + ImmutableArray.Create(Uri("https://example.com/1")) + + let array2 = + ImmutableArray.Create(Uri("https://example.com/2")) + diff --git a/tests/FsUnit.Xunit.Test/typed.shouldFailTests.fs b/tests/FsUnit.Xunit.Test/typed.shouldFailTests.fs new file mode 100644 index 00000000..7bc9636a --- /dev/null +++ b/tests/FsUnit.Xunit.Test/typed.shouldFailTests.fs @@ -0,0 +1,21 @@ +namespace FsUnit.Typed.Test + +open Xunit +open FsUnitTyped + +type ``shouldFail tests``() = + [] + member __.``empty List should fail to contain item``() = + shouldFail(fun () -> [] |> shouldContain 1) + + [] + member __.``non-null should fail to be Null``() = + shouldFail(fun () -> "something" |> shouldEqual null) + + [] + member __.``shouldFail should fail when everything is OK``() = + shouldFail(fun () -> shouldFail id) + + [] + member __.``Simplify "should throw"``() = + (fun () -> failwith "BOOM!") |> shouldFail