Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
dharmaturtle committed Jul 4, 2023
1 parent aecd795 commit 19a8b7b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
}
}

Expand Down
16 changes: 10 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ 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`.

### 🔖 `[<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).

```f#
type ``class with a test`` (output: Xunit.Abstractions.ITestOutputHelper) =
Expand Down Expand Up @@ -285,20 +285,24 @@ module __ =
Consider extending `PropertyAttribute` or `PropertiesAttribute` to hardcode commonly used arguments.

```f#
type Int5() =
inherit GenAttribute<int>()
override _.Generator = Gen.constant 5
type Int13 = static member __ = GenX.defaults |> AutoGenConfig.addGenerator (Gen.constant 13)
type PropertyInt13Attribute() = inherit PropertyAttribute(typeof<Int13>)
module __ =
[<PropertyInt13>]
let ``this passes`` (i: int) =
i = 13
let ``this passes`` (thirteen: int) ([<Int5>] five: int) =
thirteen = 13 && five = 5
type PropertiesInt13Attribute() = inherit PropertiesAttribute(typeof<Int13>)
[<PropertiesInt13>]
module ___ =
[<Property>]
let ``this also passes`` (i: int) =
i = 13
let ``this also passes`` (thirteen: int) ([<Int5>] five: int) =
thirteen = 13 && five = 5
```

<details>
Expand Down
26 changes: 16 additions & 10 deletions readmeCSharp.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -92,8 +94,8 @@ public class DocumentationSamples
_output.WriteLine($"Test input: {i}");
}
}
=== Output ===
```
```
Test input: 0
Test input: -1
Test input: 1
Expand All @@ -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<T>`] or `Task<T>`, 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<T>`](https://fsharp.github.io/fsharp-core-docs/reference/fsharp-control-fsharpasync.html) or `Task<T>`, then `Async.RunSynchronously` is called, _which blocks the thread._ This may have significant performance implications as tests run 100 times by default.

```C#
[Property]
Expand Down Expand Up @@ -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<int>
{
public override Gen<int> Generator => Gen.Int32(Range.FromValue(5));
}

public class Int13
{
public static AutoGenConfig _ =>
Expand All @@ -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
{
Expand All @@ -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;
}
```

Expand Down

0 comments on commit 19a8b7b

Please sign in to comment.