diff --git a/examples/Hedgehog.Xunit.Examples.CSharp/DocumentationSamples.cs b/examples/Hedgehog.Xunit.Examples.CSharp/DocumentationSamples.cs index 092b1c0..e8b43f7 100644 --- a/examples/Hedgehog.Xunit.Examples.CSharp/DocumentationSamples.cs +++ b/examples/Hedgehog.Xunit.Examples.CSharp/DocumentationSamples.cs @@ -153,7 +153,7 @@ public PropertyInt13Attribute() : base(typeof(Int13)) { } } [PropertyInt13] - public bool This_passes(int i) => i == 13; + public bool This_passes(int thirteen, [Five] int five) => thirteen == 13 && five == 5; public class PropertiesInt13Attribute : PropertiesAttribute { @@ -164,7 +164,7 @@ public PropertiesInt13Attribute() : base(typeof(Int13)) { } public class ___ { [Property] - public bool This_also_passes(int i) => i == 13; + public bool This_also_passes(int thirteen, [Five] int five) => thirteen == 13 && five == 5; } } diff --git a/readme.md b/readme.md index ccba702..7554fda 100644 --- a/readme.md +++ b/readme.md @@ -54,13 +54,13 @@ Extends xUnit's `Fact` to call Hedgehog's `property`. * [`[]`](#-properties) Configures all [`Property`](#-property) tagged tests in a module or class. * [`GenAttribute`](#-genattribute) -Set a parameter's generator. +Extend this attribute to set a parameter's generator. * [`[]`](#-recheck) Run a test with a specific `Size` and `Seed`. ### 🔖 `[]` -Methods with `[]` have their arguments generated by [`GenX.auto`](https://github.com/hedgehogqa/fsharp-hedgehog-experimental/#auto-generation), unless the argument is decorated with a subclass of [`GenAttribute`](#-genattribute). +Methods with `[]` have their arguments generated by [`GenX.auto`](https://github.com/hedgehogqa/fsharp-hedgehog-experimental/#auto-generation). ```f# type ``class with a test`` (output: Xunit.Abstractions.ITestOutputHelper) = @@ -285,20 +285,24 @@ module __ = Consider extending `PropertyAttribute` or `PropertiesAttribute` to hardcode commonly used arguments. ```f# +type Int5() = + inherit GenAttribute() + override _.Generator = Gen.constant 5 + type Int13 = static member __ = GenX.defaults |> AutoGenConfig.addGenerator (Gen.constant 13) type PropertyInt13Attribute() = inherit PropertyAttribute(typeof) module __ = [] - let ``this passes`` (i: int) = - i = 13 + let ``this passes`` (thirteen: int) ([] five: int) = + thirteen = 13 && five = 5 type PropertiesInt13Attribute() = inherit PropertiesAttribute(typeof) [] module ___ = [] - let ``this also passes`` (i: int) = - i = 13 + let ``this also passes`` (thirteen: int) ([] five: int) = + thirteen = 13 && five = 5 ```
diff --git a/readmeCSharp.md b/readmeCSharp.md index 34d17e2..585ae9d 100644 --- a/readmeCSharp.md +++ b/readmeCSharp.md @@ -65,17 +65,19 @@ Extends xUnit's `Fact` to call Hedgehog's `property`. * [`[Properties]`](#-properties) Configures all [`Property`](#-property) tagged tests in a module or class. * [`GenAttribute`](#-genattribute) -Set a parameter's generator. +Extend this attribute to set a parameter's generator. * [`[Recheck]`](#-recheck) Run a test with a specific `Size` and `Seed`. -> All code in the below is available [here](/examples/Hedgehog.Xunit.Examples.CSharp/DocumentationSamples.cs) +👉 All code in this document is available [here.](/examples/Hedgehog.Xunit.Examples.CSharp/DocumentationSamples.cs) ### 🔖 `[Property]` -Methods with `[Property]` have their arguments generated by [`GenX.auto`](https://github.com/hedgehogqa/fsharp-hedgehog-experimental/#auto-generation), unless the argument is decorated with a subclass of [`GenAttribute`](#-genattribute). +Methods with `[Property]` have their arguments generated by [`GenX.auto`](https://github.com/hedgehogqa/fsharp-hedgehog-experimental/#auto-generation). ```C# +using global::Xunit.Abstractions; + public class DocumentationSamples { private readonly ITestOutputHelper _output; @@ -92,8 +94,8 @@ public class DocumentationSamples _output.WriteLine($"Test input: {i}"); } } - -=== Output === +``` +``` Test input: 0 Test input: -1 Test input: 1 @@ -113,10 +115,9 @@ public bool Will_fail(bool value) => value; System.Exception: *** Failed! Falsifiable (after 5 tests): [false] Hedgehog.Xunit.TestReturnedFalseException: Test returned `false`. -... ``` -If the test returns [`FSharp.Control.Async`] or `Task`, then `Async.RunSynchronously` is called, _which blocks the thread._ This may have significant performance implications as tests run 100 times by default. +If the test returns [`FSharp.Control.Async`](https://fsharp.github.io/fsharp-core-docs/reference/fsharp-control-fsharpasync.html) or `Task`, then `Async.RunSynchronously` is called, _which blocks the thread._ This may have significant performance implications as tests run 100 times by default. ```C# [Property] @@ -343,9 +344,14 @@ public class __ } ``` -Consider extending `PropertyAttribute` or `PropertiesAttribute` to hardcode commonly used arguments. +Consider extending `PropertyAttribute` or `PropertiesAttribute` to hardcode commonly used arguments. It also works with `GenAttribute`. ```C# +public class Five : GenAttribute +{ + public override Gen Generator => Gen.Int32(Range.FromValue(5)); +} + public class Int13 { public static AutoGenConfig _ => @@ -358,7 +364,7 @@ public class PropertyInt13Attribute : PropertyAttribute } [PropertyInt13] -public bool This_passes(int i) => i == 13; +public bool This_passes(int thirteen, [Five] int five) => thirteen == 13 && five == 5; public class PropertiesInt13Attribute : PropertiesAttribute { @@ -369,7 +375,7 @@ public class PropertiesInt13Attribute : PropertiesAttribute public class ___ { [Property] - public bool This_also_passes(int i) => i == 13; + public bool This_also_passes(int thirteen, [Five] int five) => thirteen == 13 && five == 5; } ```