diff --git a/Expecto.Tests/Tests.fs b/Expecto.Tests/Tests.fs index 09d60a54..8a0be140 100644 --- a/Expecto.Tests/Tests.fs +++ b/Expecto.Tests/Tests.fs @@ -449,7 +449,7 @@ let expecto = ] ] - testList "string isempty" [ + testList "string isnotempty" [ testCase "when string is not empty" <| fun _ -> Expect.isNotEmpty "dede" "should pass because string is not empty" @@ -458,6 +458,19 @@ let expecto = ) |> assertTestFails ] + testList "string isnotwhitespace" [ + testCase "when string is not whitespace" <| fun _ -> + Expect.isNotEmpty " dede " "should pass because string is not whitespace" + + testCase "when string is empty" (fun _ -> + Expect.isNotEmpty "" "should fail because string is empty" + ) |> assertTestFails + + testCase "when string is whitespace" (fun _ -> + Expect.isNotEmpty " " "should fail because string is whitespace" + ) |> assertTestFails + ] + testList "string contain" [ testCase "pass" <| fun _ -> Expect.stringContains "hello world" "hello" "String actually contains" diff --git a/Expecto/Expect.fs b/Expecto/Expect.fs index 0a9088f6..2d19ff2d 100644 --- a/Expecto/Expect.fs +++ b/Expecto/Expect.fs @@ -161,6 +161,15 @@ let isNotEmpty (actual : string) format = isNotNull actual format if String.IsNullOrWhiteSpace actual then Tests.failtestf "%s. Should not be empty." format +/// Expect the passed string is not whitespace +let isNotWhitespace (actual : string) format = + isNotEmpty actual format + let rec checkWhitespace index = + if Char.IsWhiteSpace actual.[index] then + if index < (actual.Length - 1) then checkWhitespace (index + 1) + else Tests.failtestf "%s. Should not be whitespace." format + checkWhitespace 0 + /// Expects the two values to equal each other. let inline equal (actual : 'a) (expected : 'a) format = match box actual, box expected with