mirror of
https://github.com/Smaug123/WoofWare.Expect
synced 2025-10-05 04:28:40 +00:00
Ban multiple instances of snapshot keyword (#2)
This commit is contained in:
@@ -15,6 +15,10 @@ type private SnapshotValue =
|
||||
| BareString of string
|
||||
| Json of string
|
||||
|
||||
/// A dummy type which is here to provide better error messages when you supply
|
||||
/// the `snapshot` keyword multiple times.
|
||||
type YouHaveSuppliedMultipleSnapshots = private | NonConstructible
|
||||
|
||||
/// The state accumulated by the `expect` builder. You should never find yourself interacting with this type.
|
||||
type ExpectState<'T> =
|
||||
private
|
||||
@@ -35,7 +39,10 @@ module private Text =
|
||||
/// <param name="sourceOverride">Override the file path and line numbers reported in snapshots, so that your tests can be fully stable even on failure. (You almost certainly don't want to set this.)</param>
|
||||
type ExpectBuilder (?sourceOverride : string * int) =
|
||||
/// Combine two `ExpectState`s. The first one is the "expected" snapshot; the second is the "actual".
|
||||
member _.Bind (state : ExpectState<unit>, f : unit -> ExpectState<'U>) : ExpectState<'U> =
|
||||
member _.Bind
|
||||
(state : ExpectState<YouHaveSuppliedMultipleSnapshots>, f : unit -> ExpectState<'U>)
|
||||
: ExpectState<'U>
|
||||
=
|
||||
let actual = f ()
|
||||
|
||||
match state.Actual with
|
||||
@@ -56,13 +63,13 @@ type ExpectBuilder (?sourceOverride : string * int) =
|
||||
[<CustomOperation("snapshot", MaintainsVariableSpaceUsingBind = true)>]
|
||||
member _.Snapshot
|
||||
(
|
||||
state : ExpectState<'a>,
|
||||
state : ExpectState<unit>,
|
||||
snapshot : string,
|
||||
[<CallerMemberName>] ?memberName : string,
|
||||
[<CallerLineNumber>] ?callerLine : int,
|
||||
[<CallerFilePath>] ?filePath : string
|
||||
)
|
||||
: ExpectState<'a>
|
||||
: ExpectState<YouHaveSuppliedMultipleSnapshots>
|
||||
=
|
||||
match state.Snapshot with
|
||||
| Some _ -> failwith "snapshot can only be specified once"
|
||||
@@ -78,8 +85,9 @@ type ExpectBuilder (?sourceOverride : string * int) =
|
||||
LineNumber = lineNumber
|
||||
}
|
||||
|
||||
{ state with
|
||||
{
|
||||
Snapshot = Some (SnapshotValue.BareString snapshot, callerInfo)
|
||||
Actual = None
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -92,13 +100,13 @@ type ExpectBuilder (?sourceOverride : string * int) =
|
||||
[<CustomOperation("snapshotJson", MaintainsVariableSpaceUsingBind = true)>]
|
||||
member _.SnapshotJson
|
||||
(
|
||||
state : ExpectState<'a>,
|
||||
state : ExpectState<unit>,
|
||||
snapshot : string,
|
||||
[<CallerMemberName>] ?memberName : string,
|
||||
[<CallerLineNumber>] ?callerLine : int,
|
||||
[<CallerFilePath>] ?filePath : string
|
||||
)
|
||||
: ExpectState<'a>
|
||||
: ExpectState<YouHaveSuppliedMultipleSnapshots>
|
||||
=
|
||||
match state.Snapshot with
|
||||
| Some _ -> failwith "snapshot can only be specified once"
|
||||
@@ -114,8 +122,9 @@ type ExpectBuilder (?sourceOverride : string * int) =
|
||||
LineNumber = lineNumber
|
||||
}
|
||||
|
||||
{ state with
|
||||
{
|
||||
Snapshot = Some (SnapshotValue.Json snapshot, callerInfo)
|
||||
Actual = None
|
||||
}
|
||||
|
||||
/// MaintainsVariableSpaceUsingBind causes this to be used; it's a dummy representing "no snapshot and no assertion".
|
||||
|
@@ -4,12 +4,14 @@ WoofWare.Expect.Builder.expectWithMockedFilePath [static method]: (string, int)
|
||||
WoofWare.Expect.Builder.get_expect [static method]: unit -> WoofWare.Expect.ExpectBuilder
|
||||
WoofWare.Expect.ExpectBuilder inherit obj
|
||||
WoofWare.Expect.ExpectBuilder..ctor [constructor]: (string * int) option
|
||||
WoofWare.Expect.ExpectBuilder.Bind [method]: (unit WoofWare.Expect.ExpectState, unit -> 'U WoofWare.Expect.ExpectState) -> 'U WoofWare.Expect.ExpectState
|
||||
WoofWare.Expect.ExpectBuilder.Bind [method]: (WoofWare.Expect.YouHaveSuppliedMultipleSnapshots WoofWare.Expect.ExpectState, unit -> 'U WoofWare.Expect.ExpectState) -> 'U WoofWare.Expect.ExpectState
|
||||
WoofWare.Expect.ExpectBuilder.Delay [method]: (unit -> 'T WoofWare.Expect.ExpectState) -> (unit -> 'T WoofWare.Expect.ExpectState)
|
||||
WoofWare.Expect.ExpectBuilder.Return [method]: 'T -> 'T WoofWare.Expect.ExpectState
|
||||
WoofWare.Expect.ExpectBuilder.Return [method]: unit -> 'T WoofWare.Expect.ExpectState
|
||||
WoofWare.Expect.ExpectBuilder.Run [method]: (unit -> 'T WoofWare.Expect.ExpectState) -> unit
|
||||
WoofWare.Expect.ExpectBuilder.Snapshot [method]: ('a WoofWare.Expect.ExpectState, string, string option, int option, string option) -> 'a WoofWare.Expect.ExpectState
|
||||
WoofWare.Expect.ExpectBuilder.SnapshotJson [method]: ('a WoofWare.Expect.ExpectState, string, string option, int option, string option) -> 'a WoofWare.Expect.ExpectState
|
||||
WoofWare.Expect.ExpectBuilder.Snapshot [method]: (unit WoofWare.Expect.ExpectState, string, string option, int option, string option) -> WoofWare.Expect.YouHaveSuppliedMultipleSnapshots WoofWare.Expect.ExpectState
|
||||
WoofWare.Expect.ExpectBuilder.SnapshotJson [method]: (unit WoofWare.Expect.ExpectState, string, string option, int option, string option) -> WoofWare.Expect.YouHaveSuppliedMultipleSnapshots WoofWare.Expect.ExpectState
|
||||
WoofWare.Expect.ExpectState`1 inherit obj, implements 'T WoofWare.Expect.ExpectState System.IEquatable, System.Collections.IStructuralEquatable, 'T WoofWare.Expect.ExpectState System.IComparable, System.IComparable, System.Collections.IStructuralComparable
|
||||
WoofWare.Expect.ExpectState`1.Equals [method]: ('T WoofWare.Expect.ExpectState, System.Collections.IEqualityComparer) -> bool
|
||||
WoofWare.Expect.ExpectState`1.Equals [method]: ('T WoofWare.Expect.ExpectState, System.Collections.IEqualityComparer) -> bool
|
||||
WoofWare.Expect.YouHaveSuppliedMultipleSnapshots inherit obj, implements WoofWare.Expect.YouHaveSuppliedMultipleSnapshots System.IEquatable, System.Collections.IStructuralEquatable, WoofWare.Expect.YouHaveSuppliedMultipleSnapshots System.IComparable, System.IComparable, System.Collections.IStructuralComparable
|
||||
WoofWare.Expect.YouHaveSuppliedMultipleSnapshots.Equals [method]: (WoofWare.Expect.YouHaveSuppliedMultipleSnapshots, System.Collections.IEqualityComparer) -> bool
|
Reference in New Issue
Block a user