Skip to content

Commit

Permalink
Use Property.failOnFalse everywhere possible
Browse files Browse the repository at this point in the history
  • Loading branch information
TysonMN committed Nov 16, 2021
1 parent 4f3bced commit 44bfe70
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
30 changes: 14 additions & 16 deletions src/Hedgehog/Linq/Property.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@ open System
open System.Runtime.CompilerServices
open Hedgehog


type Property = private Property of Property<unit> with

static member Failure : Property =
Property.failure
|> Property
Property.failure |> Property

static member Discard : Property =
Property.discard
|> Property
Property.discard |> Property

static member Success (value : 'T) : Property<'T> =
Property.success value

static member FromBool (value : bool) : Property =
Property.ofBool value
|> Property
value |> Property.ofBool |> Property

static member FromGen (gen : Gen<Journal * Outcome<'T>>) : Property<'T> =
Property.ofGen gen
Expand Down Expand Up @@ -74,11 +72,11 @@ type PropertyExtensions private () =

[<Extension>]
static member Report (property : Property<bool>) : Report =
Property.reportBool property
property |> Property.failOnFalse |> Property.report

[<Extension>]
static member Report (property : Property<bool>, config : Hedgehog.PropertyConfig) : Report =
Property.reportBoolWith config property
property |> Property.failOnFalse |> Property.reportWith config

[<Extension>]
static member Check (property : Property) : unit =
Expand All @@ -92,11 +90,11 @@ type PropertyExtensions private () =

[<Extension>]
static member Check (property : Property<bool>) : unit =
Property.checkBool property
property |> Property.failOnFalse |> Property.check

[<Extension>]
static member Check (property : Property<bool>, config : Hedgehog.PropertyConfig) : unit =
Property.checkBoolWith config property
property |> Property.failOnFalse |> Property.checkWith config

[<Extension>]
static member Recheck (property : Property, size : Size, seed : Seed) : unit =
Expand All @@ -110,11 +108,11 @@ type PropertyExtensions private () =

[<Extension>]
static member Recheck (property : Property<bool>, size : Size, seed : Seed) : unit =
Property.recheckBool size seed property
property |> Property.failOnFalse |> Property.recheck size seed

[<Extension>]
static member Recheck (property : Property<bool>, size : Size, seed : Seed, config : Hedgehog.PropertyConfig) : unit =
Property.recheckBoolWith size seed config property
property |> Property.failOnFalse |> Property.recheckWith size seed config

[<Extension>]
static member ReportRecheck (property : Property, size : Size, seed : Seed) : Report =
Expand All @@ -128,11 +126,11 @@ type PropertyExtensions private () =

[<Extension>]
static member ReportRecheck (property : Property<bool>, size : Size, seed : Seed) : Report =
Property.reportRecheckBool size seed property
property |> Property.failOnFalse |> Property.reportRecheck size seed

[<Extension>]
static member ReportRecheck (property : Property<bool>, size : Size, seed : Seed, config : Hedgehog.PropertyConfig) : Report =
Property.reportRecheckBoolWith size seed config property
property |> Property.failOnFalse |> Property.reportRecheckWith size seed config

[<Extension>]
static member Render (property : Property) : string =
Expand All @@ -146,11 +144,11 @@ type PropertyExtensions private () =

[<Extension>]
static member Render (property : Property<bool>) : string =
Property.renderBool property
property |> Property.failOnFalse |> Property.render

[<Extension>]
static member Render (property : Property<bool>, config : Hedgehog.PropertyConfig) : string =
Property.renderBoolWith config property
property |> Property.failOnFalse |> Property.renderWith config

[<Extension>]
static member Where (property : Property<'T>, filter : Func<'T, bool>) : Property<'T> =
Expand Down
20 changes: 10 additions & 10 deletions src/Hedgehog/Property.fs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ module Property =
p |> reportWith PropertyConfig.defaultConfig

let reportBoolWith (config : PropertyConfig) (p : Property<bool>) : Report =
p |> bind ofBool |> reportWith config
p |> failOnFalse |> reportWith config

let reportBool (p : Property<bool>) : Report =
p |> bind ofBool |> report
p |> failOnFalse |> report

let checkWith (config : PropertyConfig) (p : Property<unit>) : unit =
p |> reportWith config |> Report.tryRaise
Expand All @@ -214,10 +214,10 @@ module Property =
p |> report |> Report.tryRaise

let checkBool (g : Property<bool>) : unit =
g |> bind ofBool |> check
g |> failOnFalse |> check

let checkBoolWith (config : PropertyConfig) (g : Property<bool>) : unit =
g |> bind ofBool |> checkWith config
g |> failOnFalse |> checkWith config

let reportRecheckWith (size : Size) (seed : Seed) (config : PropertyConfig) (p : Property<unit>) : Report =
let args = {
Expand All @@ -232,10 +232,10 @@ module Property =
p |> reportRecheckWith size seed PropertyConfig.defaultConfig

let reportRecheckBoolWith (size : Size) (seed : Seed) (config : PropertyConfig) (p : Property<bool>) : Report =
p |> bind ofBool |> reportRecheckWith size seed config
p |> failOnFalse |> reportRecheckWith size seed config

let reportRecheckBool (size : Size) (seed : Seed) (p : Property<bool>) : Report =
p |> bind ofBool |> reportRecheck size seed
p |> failOnFalse |> reportRecheck size seed

let recheckWith (size : Size) (seed : Seed) (config : PropertyConfig) (p : Property<unit>) : unit =
p |> reportRecheckWith size seed config |> Report.tryRaise
Expand All @@ -244,10 +244,10 @@ module Property =
p |> reportRecheck size seed |> Report.tryRaise

let recheckBoolWith (size : Size) (seed : Seed) (config : PropertyConfig) (g : Property<bool>) : unit =
g |> bind ofBool |> recheckWith size seed config
g |> failOnFalse |> recheckWith size seed config

let recheckBool (size : Size) (seed : Seed) (g : Property<bool>) : unit =
g |> bind ofBool |> recheck size seed
g |> failOnFalse |> recheck size seed

let renderWith (n : PropertyConfig) (p : Property<unit>) : string =
p |> reportWith n |> Report.render
Expand All @@ -256,10 +256,10 @@ module Property =
p |> report |> Report.render

let renderBool (property : Property<bool>) : string =
property |> bind ofBool |> render
property |> failOnFalse |> render

let renderBoolWith (config : PropertyConfig) (p : Property<bool>) : string =
p |> bind ofBool |> renderWith config
p |> failOnFalse |> renderWith config


[<AutoOpen>]
Expand Down

0 comments on commit 44bfe70

Please sign in to comment.