From 633c064ca96337a3689559b56ae8cb93cf1d7589 Mon Sep 17 00:00:00 2001 From: Kurt Schelfthout Date: Thu, 15 Apr 2021 09:02:50 +0100 Subject: [PATCH] Add UnicodeChar and UnicodeString. (#562) --- FsCheck Release Notes.md | 6 ++++++ src/FsCheck.NUnit/AssemblyInfo.fs | 8 ++++---- src/FsCheck.Xunit/AssemblyInfo.fs | 8 ++++---- src/FsCheck/Arbitrary.fs | 32 ++++++++++++++++++++++++++++++- src/FsCheck/AssemblyInfo.fs | 8 ++++---- tests/FsCheck.Test/Arbitrary.fs | 7 +++++++ 6 files changed, 56 insertions(+), 13 deletions(-) diff --git a/FsCheck Release Notes.md b/FsCheck Release Notes.md index 75186134..161f7e73 100644 --- a/FsCheck Release Notes.md +++ b/FsCheck Release Notes.md @@ -1,3 +1,9 @@ +### 2.15.2 - To be released + +* Enabled FsCheck.Xunit's `PropertiesAttribute` to work at assembly level. (by Laurence King) + +* Added `UnicodeString` and `UnicodeChar` generators. + ### 2.15.1 - 27 February 2021 * Fixed a bug in FsCheck.Xunit: using ITestOutputHelper did not show output in `Property`-attributed tests. diff --git a/src/FsCheck.NUnit/AssemblyInfo.fs b/src/FsCheck.NUnit/AssemblyInfo.fs index 1f908016..2e020d1c 100644 --- a/src/FsCheck.NUnit/AssemblyInfo.fs +++ b/src/FsCheck.NUnit/AssemblyInfo.fs @@ -5,13 +5,13 @@ open System.Reflection [] [] [] -[] -[] +[] +[] do () module internal AssemblyVersionInformation = let [] AssemblyTitle = "FsCheck.NUnit" let [] AssemblyProduct = "FsCheck.NUnit" let [] AssemblyDescription = "Integrates FsCheck with NUnit" - let [] AssemblyVersion = "2.15.1" - let [] AssemblyFileVersion = "2.15.1" + let [] AssemblyVersion = "2.15.2" + let [] AssemblyFileVersion = "2.15.2" diff --git a/src/FsCheck.Xunit/AssemblyInfo.fs b/src/FsCheck.Xunit/AssemblyInfo.fs index f419e366..3c858925 100644 --- a/src/FsCheck.Xunit/AssemblyInfo.fs +++ b/src/FsCheck.Xunit/AssemblyInfo.fs @@ -6,8 +6,8 @@ open System.Runtime.CompilerServices [] [] [] -[] -[] +[] +[] [] do () @@ -15,6 +15,6 @@ module internal AssemblyVersionInformation = let [] AssemblyTitle = "FsCheck.Xunit" let [] AssemblyProduct = "FsCheck.Xunit" let [] AssemblyDescription = "Integrates FsCheck with xUnit.NET" - let [] AssemblyVersion = "2.15.1" - let [] AssemblyFileVersion = "2.15.1" + let [] AssemblyVersion = "2.15.2" + let [] AssemblyFileVersion = "2.15.2" let [] InternalsVisibleTo = "FsCheck.Test" diff --git a/src/FsCheck/Arbitrary.fs b/src/FsCheck/Arbitrary.fs index 71d2c2eb..5c4a11f9 100644 --- a/src/FsCheck/Arbitrary.fs +++ b/src/FsCheck/Arbitrary.fs @@ -54,7 +54,7 @@ type StringNoNulls = StringNoNulls of string with member x.Get = match x with StringNoNulls r -> r override x.ToString() = x.Get -// Represents a string that is not null, empty or consists only of white-space characters and does not contain any null characters ('\000') +/// Represents a string that is not null, empty or consists only of white-space characters and does not contain any null characters ('\000') type NonWhiteSpaceString = NonWhiteSpaceString of string with member x.Get = match x with NonWhiteSpaceString s -> s override x.ToString() = x.Get @@ -64,6 +64,16 @@ type XmlEncodedString = XmlEncodedString of string with member x.Get = match x with XmlEncodedString v -> v override x.ToString() = x.Get +///Represents a unicode char. +type UnicodeChar = UnicodeChar of char with + member x.Get = match x with UnicodeChar c -> c + override x.ToString() = string x.Get + +///Represents a string that can contain unicode characters. +type UnicodeString = UnicodeString of string with + member x.Get = match x with UnicodeString v -> v + override x.ToString() = x.Get + ///Represents an integer interval. type Interval = Interval of int * int with member x.Left = match x with Interval (l,_) -> l @@ -974,6 +984,26 @@ module Arb = |> convert XmlEncodedString string #endif + static member UnicodeChar() :Arbitrary = + let generator = + Gen.choose (int Char.MinValue, int Char.MaxValue) + |> Gen.map (char >> UnicodeChar) + + let shrinker (UnicodeChar c) = seq { for c' in ['a';'b';'c'] do if c' < c || not (Char.IsLower c) then yield UnicodeChar c' } + fromGenShrink (generator, shrinker) + + + static member UnicodeString() :Arbitrary = + let generator = + generate + |> Gen.map (fun chars -> String(chars |> Array.map (fun c -> c.Get)) |> UnicodeString) + let shrinker (UnicodeString s) = + match s with + | null -> Seq.empty + | _ -> s.ToCharArray() |> shrink |> Seq.map (String >> UnicodeString) + fromGenShrink (generator,shrinker) + + static member Set() = Default.FsList() |> convert Set.ofList Set.toList diff --git a/src/FsCheck/AssemblyInfo.fs b/src/FsCheck/AssemblyInfo.fs index 50b644f9..18abe642 100644 --- a/src/FsCheck/AssemblyInfo.fs +++ b/src/FsCheck/AssemblyInfo.fs @@ -6,8 +6,8 @@ open System.Runtime.CompilerServices [] [] [] -[] -[] +[] +[] [] do () @@ -15,6 +15,6 @@ module internal AssemblyVersionInformation = let [] AssemblyTitle = "FsCheck" let [] AssemblyProduct = "FsCheck" let [] AssemblyDescription = "FsCheck is a tool for testing .NET programs automatically using randomly generated test cases." - let [] AssemblyVersion = "2.15.1" - let [] AssemblyFileVersion = "2.15.1" + let [] AssemblyVersion = "2.15.2" + let [] AssemblyFileVersion = "2.15.2" let [] InternalsVisibleTo = "FsCheck.Test" diff --git a/tests/FsCheck.Test/Arbitrary.fs b/tests/FsCheck.Test/Arbitrary.fs index db9f15ca..83bba1df 100644 --- a/tests/FsCheck.Test/Arbitrary.fs +++ b/tests/FsCheck.Test/Arbitrary.fs @@ -154,6 +154,13 @@ module Arbitrary = doc.LoadXml (sprintf "%s" value) #endif + [] + let ``Unicode char`` (UnicodeChar s) = true |> Prop.collect s + + [] + let ``Unicode string`` (UnicodeString s) = true |> Prop.collect s + + [] let ``2-Tuple``((valuei:int,valuec:char) as value) = ( generate |> sample 10 |> List.forall (fun _ -> true)