Skip to content

Commit 633c064

Browse files
Add UnicodeChar and UnicodeString. (#562)
1 parent 1e0ad9a commit 633c064

File tree

6 files changed

+56
-13
lines changed

6 files changed

+56
-13
lines changed

FsCheck Release Notes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
### 2.15.2 - To be released
2+
3+
* Enabled FsCheck.Xunit's `PropertiesAttribute` to work at assembly level. (by Laurence King)
4+
5+
* Added `UnicodeString` and `UnicodeChar` generators.
6+
17
### 2.15.1 - 27 February 2021
28

39
* Fixed a bug in FsCheck.Xunit: using ITestOutputHelper did not show output in `Property`-attributed tests.

src/FsCheck.NUnit/AssemblyInfo.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ open System.Reflection
55
[<assembly: AssemblyTitleAttribute("FsCheck.NUnit")>]
66
[<assembly: AssemblyProductAttribute("FsCheck.NUnit")>]
77
[<assembly: AssemblyDescriptionAttribute("Integrates FsCheck with NUnit")>]
8-
[<assembly: AssemblyVersionAttribute("2.15.1")>]
9-
[<assembly: AssemblyFileVersionAttribute("2.15.1")>]
8+
[<assembly: AssemblyVersionAttribute("2.15.2")>]
9+
[<assembly: AssemblyFileVersionAttribute("2.15.2")>]
1010
do ()
1111

1212
module internal AssemblyVersionInformation =
1313
let [<Literal>] AssemblyTitle = "FsCheck.NUnit"
1414
let [<Literal>] AssemblyProduct = "FsCheck.NUnit"
1515
let [<Literal>] AssemblyDescription = "Integrates FsCheck with NUnit"
16-
let [<Literal>] AssemblyVersion = "2.15.1"
17-
let [<Literal>] AssemblyFileVersion = "2.15.1"
16+
let [<Literal>] AssemblyVersion = "2.15.2"
17+
let [<Literal>] AssemblyFileVersion = "2.15.2"

src/FsCheck.Xunit/AssemblyInfo.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ open System.Runtime.CompilerServices
66
[<assembly: AssemblyTitleAttribute("FsCheck.Xunit")>]
77
[<assembly: AssemblyProductAttribute("FsCheck.Xunit")>]
88
[<assembly: AssemblyDescriptionAttribute("Integrates FsCheck with xUnit.NET")>]
9-
[<assembly: AssemblyVersionAttribute("2.15.1")>]
10-
[<assembly: AssemblyFileVersionAttribute("2.15.1")>]
9+
[<assembly: AssemblyVersionAttribute("2.15.2")>]
10+
[<assembly: AssemblyFileVersionAttribute("2.15.2")>]
1111
[<assembly: InternalsVisibleToAttribute("FsCheck.Test")>]
1212
do ()
1313

1414
module internal AssemblyVersionInformation =
1515
let [<Literal>] AssemblyTitle = "FsCheck.Xunit"
1616
let [<Literal>] AssemblyProduct = "FsCheck.Xunit"
1717
let [<Literal>] AssemblyDescription = "Integrates FsCheck with xUnit.NET"
18-
let [<Literal>] AssemblyVersion = "2.15.1"
19-
let [<Literal>] AssemblyFileVersion = "2.15.1"
18+
let [<Literal>] AssemblyVersion = "2.15.2"
19+
let [<Literal>] AssemblyFileVersion = "2.15.2"
2020
let [<Literal>] InternalsVisibleTo = "FsCheck.Test"

src/FsCheck/Arbitrary.fs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type StringNoNulls = StringNoNulls of string with
5454
member x.Get = match x with StringNoNulls r -> r
5555
override x.ToString() = x.Get
5656

57-
// Represents a string that is not null, empty or consists only of white-space characters and does not contain any null characters ('\000')
57+
/// Represents a string that is not null, empty or consists only of white-space characters and does not contain any null characters ('\000')
5858
type NonWhiteSpaceString = NonWhiteSpaceString of string with
5959
member x.Get = match x with NonWhiteSpaceString s -> s
6060
override x.ToString() = x.Get
@@ -64,6 +64,16 @@ type XmlEncodedString = XmlEncodedString of string with
6464
member x.Get = match x with XmlEncodedString v -> v
6565
override x.ToString() = x.Get
6666

67+
///Represents a unicode char.
68+
type UnicodeChar = UnicodeChar of char with
69+
member x.Get = match x with UnicodeChar c -> c
70+
override x.ToString() = string x.Get
71+
72+
///Represents a string that can contain unicode characters.
73+
type UnicodeString = UnicodeString of string with
74+
member x.Get = match x with UnicodeString v -> v
75+
override x.ToString() = x.Get
76+
6777
///Represents an integer interval.
6878
type Interval = Interval of int * int with
6979
member x.Left = match x with Interval (l,_) -> l
@@ -974,6 +984,26 @@ module Arb =
974984
|> convert XmlEncodedString string
975985
#endif
976986

987+
static member UnicodeChar() :Arbitrary<UnicodeChar> =
988+
let generator =
989+
Gen.choose (int Char.MinValue, int Char.MaxValue)
990+
|> Gen.map (char >> UnicodeChar)
991+
992+
let shrinker (UnicodeChar c) = seq { for c' in ['a';'b';'c'] do if c' < c || not (Char.IsLower c) then yield UnicodeChar c' }
993+
fromGenShrink (generator, shrinker)
994+
995+
996+
static member UnicodeString() :Arbitrary<UnicodeString> =
997+
let generator =
998+
generate<UnicodeChar[]>
999+
|> Gen.map (fun chars -> String(chars |> Array.map (fun c -> c.Get)) |> UnicodeString)
1000+
let shrinker (UnicodeString s) =
1001+
match s with
1002+
| null -> Seq.empty
1003+
| _ -> s.ToCharArray() |> shrink |> Seq.map (String >> UnicodeString)
1004+
fromGenShrink (generator,shrinker)
1005+
1006+
9771007
static member Set() =
9781008
Default.FsList()
9791009
|> convert Set.ofList Set.toList

src/FsCheck/AssemblyInfo.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ open System.Runtime.CompilerServices
66
[<assembly: AssemblyTitleAttribute("FsCheck")>]
77
[<assembly: AssemblyProductAttribute("FsCheck")>]
88
[<assembly: AssemblyDescriptionAttribute("FsCheck is a tool for testing .NET programs automatically using randomly generated test cases.")>]
9-
[<assembly: AssemblyVersionAttribute("2.15.1")>]
10-
[<assembly: AssemblyFileVersionAttribute("2.15.1")>]
9+
[<assembly: AssemblyVersionAttribute("2.15.2")>]
10+
[<assembly: AssemblyFileVersionAttribute("2.15.2")>]
1111
[<assembly: InternalsVisibleToAttribute("FsCheck.Test")>]
1212
do ()
1313

1414
module internal AssemblyVersionInformation =
1515
let [<Literal>] AssemblyTitle = "FsCheck"
1616
let [<Literal>] AssemblyProduct = "FsCheck"
1717
let [<Literal>] AssemblyDescription = "FsCheck is a tool for testing .NET programs automatically using randomly generated test cases."
18-
let [<Literal>] AssemblyVersion = "2.15.1"
19-
let [<Literal>] AssemblyFileVersion = "2.15.1"
18+
let [<Literal>] AssemblyVersion = "2.15.2"
19+
let [<Literal>] AssemblyFileVersion = "2.15.2"
2020
let [<Literal>] InternalsVisibleTo = "FsCheck.Test"

tests/FsCheck.Test/Arbitrary.fs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ module Arbitrary =
154154
doc.LoadXml (sprintf "<Root>%s</Root>" value)
155155
#endif
156156

157+
[<Property>]
158+
let ``Unicode char`` (UnicodeChar s) = true |> Prop.collect s
159+
160+
[<Property>]
161+
let ``Unicode string`` (UnicodeString s) = true |> Prop.collect s
162+
163+
157164
[<Property>]
158165
let ``2-Tuple``((valuei:int,valuec:char) as value) =
159166
( generate<int*char> |> sample 10 |> List.forall (fun _ -> true)

0 commit comments

Comments
 (0)