From 3d6bbe0952c4b69502084d11071d8cfeb5b950bd Mon Sep 17 00:00:00 2001 From: omaus Date: Sun, 26 Mar 2023 23:32:17 +0200 Subject: [PATCH 1/2] Add `String.endsWith` function to the roster --- src/FSharpAux/String.fs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/FSharpAux/String.fs b/src/FSharpAux/String.fs index 61d9867..fc2b2c8 100644 --- a/src/FSharpAux/String.fs +++ b/src/FSharpAux/String.fs @@ -9,10 +9,17 @@ open System open System.Globalization module String = - - /// Checks whether the given text starts with the given prefix + + /// + /// Checks whether the given text starts with the given prefix. + /// let inline startsWith (prefix:string) (text:string) = text.StartsWith prefix + /// + /// Checks whether the given text ends with the given suffix. + /// + let inline endsWith (suffix : string) (str : string) = str.EndsWith suffix + /// Replaces the given "replacement" for every occurence of the pattern in the given text let inline replace (pattern:string) replacement (text:string) = text.Replace(pattern,replacement) From a5afc837b27b9a323b8f1507471c0da723730d1d Mon Sep 17 00:00:00 2001 From: omaus Date: Sun, 26 Mar 2023 23:32:25 +0200 Subject: [PATCH 2/2] Add unit test for `String.endsWith` --- tests/FSharpAux.Tests/StringTests.fs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/FSharpAux.Tests/StringTests.fs b/tests/FSharpAux.Tests/StringTests.fs index f57b99d..4f7d3be 100644 --- a/tests/FSharpAux.Tests/StringTests.fs +++ b/tests/FSharpAux.Tests/StringTests.fs @@ -6,6 +6,10 @@ open Expecto [] let stringTests = testList "StringTests" [ + testList "String.endsWith" [ + testCase "Returns correct bool" <| fun _ -> + Expect.isTrue (String.endsWith "World" "Hello World") "Returned incorrect bool" + ] testList "String.trim" [ testCase "trims input correctly" <| fun _ -> Expect.equal (String.trim " \tHi there!\n ") "Hi there!" "String.trim did not trim correctly"