Skip to content

Commit

Permalink
Add UnicodeChar and UnicodeString. (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtschelfthout authored Apr 15, 2021
1 parent 1e0ad9a commit 633c064
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 13 deletions.
6 changes: 6 additions & 0 deletions FsCheck Release Notes.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/FsCheck.NUnit/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ open System.Reflection
[<assembly: AssemblyTitleAttribute("FsCheck.NUnit")>]
[<assembly: AssemblyProductAttribute("FsCheck.NUnit")>]
[<assembly: AssemblyDescriptionAttribute("Integrates FsCheck with NUnit")>]
[<assembly: AssemblyVersionAttribute("2.15.1")>]
[<assembly: AssemblyFileVersionAttribute("2.15.1")>]
[<assembly: AssemblyVersionAttribute("2.15.2")>]
[<assembly: AssemblyFileVersionAttribute("2.15.2")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FsCheck.NUnit"
let [<Literal>] AssemblyProduct = "FsCheck.NUnit"
let [<Literal>] AssemblyDescription = "Integrates FsCheck with NUnit"
let [<Literal>] AssemblyVersion = "2.15.1"
let [<Literal>] AssemblyFileVersion = "2.15.1"
let [<Literal>] AssemblyVersion = "2.15.2"
let [<Literal>] AssemblyFileVersion = "2.15.2"
8 changes: 4 additions & 4 deletions src/FsCheck.Xunit/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ open System.Runtime.CompilerServices
[<assembly: AssemblyTitleAttribute("FsCheck.Xunit")>]
[<assembly: AssemblyProductAttribute("FsCheck.Xunit")>]
[<assembly: AssemblyDescriptionAttribute("Integrates FsCheck with xUnit.NET")>]
[<assembly: AssemblyVersionAttribute("2.15.1")>]
[<assembly: AssemblyFileVersionAttribute("2.15.1")>]
[<assembly: AssemblyVersionAttribute("2.15.2")>]
[<assembly: AssemblyFileVersionAttribute("2.15.2")>]
[<assembly: InternalsVisibleToAttribute("FsCheck.Test")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FsCheck.Xunit"
let [<Literal>] AssemblyProduct = "FsCheck.Xunit"
let [<Literal>] AssemblyDescription = "Integrates FsCheck with xUnit.NET"
let [<Literal>] AssemblyVersion = "2.15.1"
let [<Literal>] AssemblyFileVersion = "2.15.1"
let [<Literal>] AssemblyVersion = "2.15.2"
let [<Literal>] AssemblyFileVersion = "2.15.2"
let [<Literal>] InternalsVisibleTo = "FsCheck.Test"
32 changes: 31 additions & 1 deletion src/FsCheck/Arbitrary.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -974,6 +984,26 @@ module Arb =
|> convert XmlEncodedString string
#endif

static member UnicodeChar() :Arbitrary<UnicodeChar> =
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<UnicodeString> =
let generator =
generate<UnicodeChar[]>
|> 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
Expand Down
8 changes: 4 additions & 4 deletions src/FsCheck/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ open System.Runtime.CompilerServices
[<assembly: AssemblyTitleAttribute("FsCheck")>]
[<assembly: AssemblyProductAttribute("FsCheck")>]
[<assembly: AssemblyDescriptionAttribute("FsCheck is a tool for testing .NET programs automatically using randomly generated test cases.")>]
[<assembly: AssemblyVersionAttribute("2.15.1")>]
[<assembly: AssemblyFileVersionAttribute("2.15.1")>]
[<assembly: AssemblyVersionAttribute("2.15.2")>]
[<assembly: AssemblyFileVersionAttribute("2.15.2")>]
[<assembly: InternalsVisibleToAttribute("FsCheck.Test")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FsCheck"
let [<Literal>] AssemblyProduct = "FsCheck"
let [<Literal>] AssemblyDescription = "FsCheck is a tool for testing .NET programs automatically using randomly generated test cases."
let [<Literal>] AssemblyVersion = "2.15.1"
let [<Literal>] AssemblyFileVersion = "2.15.1"
let [<Literal>] AssemblyVersion = "2.15.2"
let [<Literal>] AssemblyFileVersion = "2.15.2"
let [<Literal>] InternalsVisibleTo = "FsCheck.Test"
7 changes: 7 additions & 0 deletions tests/FsCheck.Test/Arbitrary.fs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ module Arbitrary =
doc.LoadXml (sprintf "<Root>%s</Root>" value)
#endif

[<Property>]
let ``Unicode char`` (UnicodeChar s) = true |> Prop.collect s

[<Property>]
let ``Unicode string`` (UnicodeString s) = true |> Prop.collect s


[<Property>]
let ``2-Tuple``((valuei:int,valuec:char) as value) =
( generate<int*char> |> sample 10 |> List.forall (fun _ -> true)
Expand Down

0 comments on commit 633c064

Please sign in to comment.