### CoverPercentage Construction Example Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Property Demonstrates how to construct a CoverPercentage value using numeric literals. This is a common way to define a specific percentage for test coverage thresholds. ```haskell 30 :: CoverPercentage ``` -------------------------------- ### Example of Recursive AST Generation (Haskell) Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Gen Demonstrates using `Gen.recursive` and `Gen.choice` to generate recursive data structures like Abstract Syntax Trees, preventing non-termination issues common with naive recursive generators. ```Haskell data Expr = Var String | Lam String Expr | App Expr Expr -- Assuming we have a name generator genName :: MonadGen m => m String -- We can write a generator for expressions genExpr :: MonadGen m => m Expr genExpr = Gen.recursive Gen.choice [ -- non-recursive generators Var <$> genName ] [ -- recursive generators Gen.subtermM genExpr (x -> Lam <$> genName <*> pure x) , Gen.subterm2 genExpr genExpr App ] ``` -------------------------------- ### Haskell TH: Discover Properties Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-TH The 'discover' function in Hedgehog's TH module retrieves all properties within a module. Properties are identified by function names starting with 'prop_'. ```Haskell discover :: TExpQ Group ``` -------------------------------- ### Span Data Type Definition and Instances Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Source Defines the 'Span' data type, which represents a source code location with start and end line and column numbers, along with its file path. It includes instances for Show, Eq, and Ord, enabling serialization, equality checks, and ordering. These instances are defined in Hedgehog.Internal.Source. ```Haskell data Span Source # * spanFile :: !FilePath * spanStartLine :: !LineNo * spanStartColumn :: !ColumnNo * spanEndLine :: !LineNo * spanEndColumn :: !ColumnNo Instance detailsShow Span Source #| showsPrec :: Int -> Span -> ShowS # show :: Span -> String # showList :: [Span] -> ShowS # Instance detailsEq Span Source #| (==) :: Span -> Span -> Bool # (/=) :: Span -> Span -> Bool # Instance detailsOrd Span Source #| compare :: Span -> Span -> Ordering # (<) :: Span -> Span -> Bool # (<=) :: Span -> Span -> Bool # (>) :: Span -> Span -> Bool # (>=) :: Span -> Span -> Bool # max :: Span -> Span -> Span # min :: Span -> Span -> Span # ``` -------------------------------- ### Example of using Opaque in Haskell Data Type Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Opaque Demonstrates how to use the Opaque newtype within a Haskell data type definition. In this example, Opaque is used to wrap an IORef Int within a list of state references, allowing the overall State data type to derive Show. ```haskell data State v = State { stateRefs :: [Var (Opaque (IORef Int)) v] } deriving (Eq, Show) ``` -------------------------------- ### Haskell: Show instance for PrintPrefixIcons Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Report Provides functions to convert PrintPrefixIcons to a human-readable string representation. This instance is defined in Hedgehog.Internal.Report and includes methods for showing with prefix, showing directly, and showing lists. ```Haskell showsPrec :: Int -> PrintPrefixIcons -> ShowS show :: PrintPrefixIcons -> String showList :: [PrintPrefixIcons] -> ShowS ``` -------------------------------- ### Haskell: Define Span type for source code locations Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Source Defines a data type 'Span' to represent a range of source code, including the file path, start and end line numbers, and start and end column numbers. This is useful for pinpointing exact locations in source files. ```haskell data Span = Span { spanFile :: !FilePath, spanStartLine :: !LineNo, spanStartColumn :: !ColumnNo, spanEndLine :: !LineNo, spanEndColumn :: !ColumnNo } ``` -------------------------------- ### CallStack Instances: Show (Haskell) Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Source Provides the Show instance for CallStack, enabling CallStacks to be converted to strings for display. Includes methods for showing the CallStack with different precedence levels and in a list context. ```haskell showPrec :: Int -> CallStack -> ShowS show :: CallStack -> String showList :: [CallStack] -> ShowS ``` -------------------------------- ### Haskell Show Instance for ShrinkLimit Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Property This snippet details the Show instance for ShrinkLimit, enabling the conversion of ShrinkLimit values to human-readable strings. It includes showsPrec, show, and showList functions for formatted output. ```haskell showsPrec :: Int -> ShrinkLimit -> ShowS show :: ShrinkLimit -> String showList :: [ShrinkLimit] -> ShowS ``` -------------------------------- ### Haskell: Get caller span from CallStack Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Source Provides a function 'getCaller' that attempts to extract a 'Span' from a 'CallStack'. This can be useful for debugging and understanding the origin of function calls. ```haskell getCaller :: CallStack -> Maybe Span ``` -------------------------------- ### Haskell Context Data Type Instances (Show, Eq) Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Report Outlines the Show and Eq instances for the Context data type. These instances enable the string representation of Context values (show, showsPrec) and allow for direct comparison of Context equality (==, /=). ```haskell instance Show Context where showsPrec :: Int -> Context -> ShowS show :: Context -> String showList :: [Context] -> ShowS instance Eq Context where (==) :: Context -> Context -> Bool (/=) :: Context -> Context -> Bool ``` -------------------------------- ### Range Utility Functions Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Range Provides functions to extract information from a `Range` data type. These include getting the origin, calculating the bounds for a given size, and determining the lower and upper bounds. ```haskell origin :: Range a -> a bounds :: Size -> Range a -> (a, a) lowerBound :: Ord a => Size -> Range a -> a upperBound :: Ord a => Size -> Range a -> a ``` -------------------------------- ### Execute Sequential and Parallel Actions (Haskell) Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-State Functions to execute generated sequential or parallel actions, verifying post-conditions and exception handling. These are the entry points for running tests defined with Hedgehog. ```Haskell executeSequential :: (MonadTest m, MonadCatch m, HasCallStack) => (forall (v :: Type -> Type). state v) -> Sequential m state -> m () Source # Executes a list of actions sequentially, verifying that all post-conditions are met and no exceptions are thrown. executeParallel :: (MonadTest m, MonadCatch m, MonadBaseControl IO m, HasCallStack) => (forall (v :: Type -> Type). state v) -> Parallel m state -> m () Source # Executes the prefix actions sequentially, then executes the two branches in parallel, verifying that no exceptions are thrown and that there is at least one sequential interleaving where all the post-conditions are met. ``` -------------------------------- ### Show Instance for Var Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-State Provides the Show instance for the Var type, requiring 'a' and 'v' to also be instances of Show and Show1 respectively. Defined in Hedgehog.Internal.State. ```Haskell showsPrec :: Int -> Var a v -> ShowS show :: Var a v -> String showList :: [Var a v] -> ShowS ``` -------------------------------- ### GroupName Construction Example (Haskell) Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Property The `GroupName` type represents the name of a group of property tests. It can be constructed using `OverloadedStrings`, allowing string literals to be automatically converted to `GroupName`. ```Haskell "fruit" :: GroupName ``` -------------------------------- ### Haskell: Show Instance for ShrinkPath Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Property Demonstrates the `show` and `showsPrec` functions for the ShrinkPath type, allowing it to be converted to a string representation. This instance is defined in Hedgehog.Internal.Property. ```Haskell show :: ShrinkPath -> String showsPrec :: Int -> ShrinkPath -> ShowS ``` -------------------------------- ### Generate Random Subsequence of a List Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Gen Generates a random subsequence from a given list. This function is useful for testing scenarios involving partial lists. The example demonstrates its usage and potential output with shrinking. ```haskell subsequence :: MonadGen m => [a] -> m [a] ``` -------------------------------- ### Show and Eq Instances for Label Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Property Label instances for Show and Eq are provided, enabling string representation and equality comparisons for Label values. These are part of Hedgehog.Internal.Property. ```haskell show :: Label a -> String (==) :: Label a -> Label a -> Bool (/=) :: Label a -> Label a -> Bool ``` -------------------------------- ### Haskell Hedgehog: Creating and Running Tests Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Property Functions for constructing and executing tests within the Hedgehog framework. 'mkTest' creates a Test from a result and journal, while 'mkTestT' does the same within a monadic context. 'runTest' and 'runTestT' execute the tests and return their outcomes. ```haskell mkTest :: (Either Failure a, Journal) -> Test a Source # mkTestT :: m (Either Failure a, Journal) -> TestT m a Source # runTest :: Test a -> (Either Failure a, Journal) Source # runTestT :: TestT m a -> m (Either Failure a, Journal) Source # ``` -------------------------------- ### Get Caller Information in Haskell Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/src/Hedgehog.Internal Provides the 'getCaller' function, which retrieves detailed call stack information. This function relies on the 'HasCallStack' constraint and the 'getCallStack' function from 'GHC.Stack' to capture the execution context. ```Haskell getCaller :: HasCallStack => SrcLoc getCaller = head (getCallStack callStack) ``` -------------------------------- ### Haskell Skip Show Instance for Representation Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Config Provides methods for displaying Skip values as strings. This includes functions like `show` for basic string representation and `showList` for representing lists of Skip values. It also defines `showsPrec` for controlled, context-aware rendering. ```haskell show :: Skip -> String showsPrec :: Int -> Skip -> ShowS showList :: [Skip] -> ShowS ``` -------------------------------- ### Hedgehog Sequential Property Execution with Template Haskell Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Runner Demonstrates using Template Haskell with `discover` to automatically find and run properties sequentially. This requires the `Group` type and a `MonadIO` context. ```haskell {-# LANGUAGE TemplateHaskell #-} import Hedgehog import Hedgehog.Internal.Runner tests :: IO Bool tests = checkSequential $discover ``` -------------------------------- ### Define Source Span Type in Haskell Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/src/Hedgehog.Internal Defines a data type 'Span' to represent a contiguous range of source code, including start and end line and column numbers. This is useful for highlighting or referring to specific sections of code. ```Haskell data Span = Span !LineNo !ColumnNo !LineNo !ColumnNo deriving (Eq, Show) ``` -------------------------------- ### Run Tests with defaultMain - Haskell Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Main The `defaultMain` function serves as an entry point for running tests within the Hedgehog framework. It accepts a list of IO actions that produce boolean results, indicating test success or failure. This function is typically used as the main function in a test suite. ```haskell defaultMain :: [IO Bool] -> IO () ``` -------------------------------- ### Progressive Halving of Integral Numbers (Haskell) Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Shrink The `halves` function generates a list containing the progressive halving of an integral number, starting from the number itself and repeatedly dividing by two. This is a common technique for generating a range of values around a given number for testing purposes. ```haskell halves :: Integral a => a -> [a] -- Example usage: halves 15 -- Expected output: [15,7,3,1] halves 100 -- Expected output: [100,50,25,12,6,3,1] halves (-26) -- Expected output: [-26,-13,-6,-3,-1] ``` -------------------------------- ### Haskell - Generate Integral Number in Range with Shrinking Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Gen Generates a random integral number within a specified inclusive range `[inclusive, inclusive]`. When shrinking, it targets the `origin` of the `Range`. Example shows generation of Int between 1970 and 2100, shrinking towards 2000. ```haskell integral :: (MonadGen m, Integral a) => Range a -> m a -- Example Usage: -- integral (Range.constantFrom 2000 1970 2100) :: Gen Int ``` -------------------------------- ### Haskell Config Data Type Instances (Show, Eq) Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Report Presents the Show and Eq instances for the Config data type. These instances facilitate the display of Config values as strings (show, showsPrec) and enable equality checks between two Config values (==, /=). ```haskell instance Show Config where showsPrec :: Int -> Config -> ShowS show :: Config -> String showList :: [Config] -> ShowS instance Eq Config where (==) :: Config -> Config -> Bool (/=) :: Config -> Config -> Bool ``` -------------------------------- ### Haskell Show Instance for PropertyCount Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Property Defines how PropertyCount values can be converted to strings for display or logging purposes. It includes functions for showing with precedence and showing lists of PropertyCount. ```haskell showsPrec :: Int -> PropertyCount -> ShowS show :: PropertyCount -> String showList :: [PropertyCount] -> ShowS ``` -------------------------------- ### Haskell: Constructing a Linear Range Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Range Builds a range where the upper bound scales relative to the size parameter. It requires the type to be Integral. The function takes two arguments: the lower bound and the upper bound. Examples show how the bounds change with different size parameters. ```haskell linear :: Integral a => a -> a -> Range a Source # -- Construct a range which scales the second bound relative to the size parameter. -- >>> **bounds 0 $ linear 0 10 -- **(0,0) -- -- >>> **bounds 50 $ linear 0 10 -- **(0,5) -- -- >>> **bounds 99 $ linear 0 10 -- **(0,10) ``` -------------------------------- ### Haskell Imports for Hedgehog Property Testing Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/package/hedgehog Sets up the necessary imports for using the Hedgehog library, including qualified imports for generators and ranges. Requires Template Haskell to be enabled. ```haskell {-# LANGUAGE TemplateHaskell #} import Hedgehog import qualified Hedgehog.Gen as Gen import qualified Hedgehog.Range as Range ``` -------------------------------- ### Haskell: Constructing a Full-Range Scaled Linear Range Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Range Generates a linear range that utilizes the entire representable range of a data type (e.g., Int8) and scales relative to the size parameter. This function requires the type to be Bounded and Integral. Examples show the scaling behavior with different size parameters for Int8. ```haskell linearBounded :: (Bounded a, Integral a) => Range a Source # -- Construct a range which is scaled relative to the size parameter and uses the full range of a data type. -- >>> **bounds 0 (linearBounded :: Range Int8) -- **(0,0) -- -- >>> **bounds 50 (linearBounded :: Range Int8) -- **(-64,64) -- -- >>> **bounds 99 (linearBounded :: Range Int8) -- **(-128,127) ``` -------------------------------- ### Haskell: Constructing a Linear Range with a Defined Origin Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Range Constructs a range where the bounds scale relative to the size parameter, and an origin point can be specified. This function requires the type to be Integral. It takes three arguments: the origin, the lower bound, and the upper bound. Examples demonstrate scaling with different size parameters. ```haskell linearFrom :: Integral a => a -> a -> a -> Range a Source # -- Arguments -- :: Integral a| -- ---|--- -- => a| Origin (the value produced when the size parameter is 0). -- -> a| Lower bound (the bottom of the range when the size parameter is 99). -- -> a| Upper bound (the top of the range when the size parameter is 99). -- -> Range a| -- Construct a range which scales the bounds relative to the size parameter. -- >>> **bounds 0 $ linearFrom 0 (-10) 10 -- **(0,0) -- -- >>> **bounds 50 $ linearFrom 0 (-10) 20 -- **(-5,10) -- -- >>> **bounds 99 $ linearFrom 0 (-10) 20 -- **(-10,20) ``` -------------------------------- ### Show Instance for LineNo in Haskell Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/src/Hedgehog.Internal Provides a Show instance for the LineNo type, enabling the display of LineNo values. This instance formats the output to be more readable, especially when nested within other showable structures. ```haskell instance Show LineNo where showsPrec p (LineNo x) = showParen (p > 10) $ showString "LineNo " . showsPrec 11 x ``` -------------------------------- ### Haskell Markup Data Type Instances (Show, Eq, Ord) Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Report Details the Show, Eq, and Ord instances for the Markup data type. These instances allow for the conversion of Markup values to strings (show, showsPrec), comparison for equality (==, /=), and ordering (compare, <, <=, >, >=, max, min). ```haskell instance Show Markup where showsPrec :: Int -> Markup -> ShowS show :: Markup -> String showList :: [Markup] -> ShowS instance Eq Markup where (==) :: Markup -> Markup -> Bool (/=) :: Markup -> Markup -> Bool instance Ord Markup where compare :: Markup -> Markup -> Ordering (<) :: Markup -> Markup -> Bool (<=) :: Markup -> Markup -> Bool (>) :: Markup -> Markup -> Bool (>=) :: Markup -> Markup -> Bool max :: Markup -> Markup -> Markup min :: Markup -> Markup -> Markup ``` -------------------------------- ### Span Data Type Definition and Instances in Haskell Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/src/Hedgehog.Internal Defines the Span data type to represent source code locations including file path, start and end line/column numbers. It includes instances for Eq and Ord, allowing for equality and ordering comparisons of spans, and a Show instance for displaying Span values. ```haskell data Span = Span { spanFile :: !FilePath , spanStartLine :: !LineNo , spanStartColumn :: !ColumnNo , spanEndLine :: !LineNo , spanEndColumn :: !ColumnNo } deriving (Eq, Ord) instance Show Span where showsPrec p (Span file sl sc el ec) = showParen (p > 10) $ showString "Span " . showsPrec 11 file . showChar ' ' . showsPrec 11 sl . showChar ' ' . showsPrec 11 sc . showChar ' ' . showsPrec 11 el . showChar ' ' . showsPrec 11 ec ``` -------------------------------- ### Haskell Integral Instance for ShrinkLimit Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Property This snippet shows the Integral instance for ShrinkLimit, providing functions for integer division, remainder, modulo operations, and conversion to Integer. It includes quot, rem, div, mod, quotRem, divMod, and toInteger. ```haskell quot :: ShrinkLimit -> ShrinkLimit -> ShrinkLimit rem :: ShrinkLimit -> ShrinkLimit -> ShrinkLimit div :: ShrinkLimit -> ShrinkLimit -> ShrinkLimit mod :: ShrinkLimit -> ShrinkLimit -> ShrinkLimit quotRem :: ShrinkLimit -> ShrinkLimit -> (ShrinkLimit, ShrinkLimit) divMod :: ShrinkLimit -> ShrinkLimit -> (ShrinkLimit, ShrinkLimit) toInteger :: ShrinkLimit -> Integer ``` -------------------------------- ### MonadIO Instance for GenT Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Gen Provides the MonadIO instance for GenT, allowing IO actions to be performed within the GenT context. This instance is defined in Hedgehog.Internal.Gen. ```haskell instance MonadIO m => MonadIO (GenT m) where liftIO :: IO a -> GenT m a ``` -------------------------------- ### Run a generator with specific size and seed (Haskell) Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Gen Functions like `printWith`, `printTreeWith`, `renderTree`, `runGenT`, `evalGen`, and `evalGenT` allow for precise control over generator execution by specifying the `Size` and `Seed`. These are useful for reproducible testing and detailed analysis of generator behavior. ```haskell printWith :: (MonadIO m, Show a) => Size -> Seed -> Gen a -> m () printTreeWith :: (MonadIO m, Show a) => Size -> Seed -> Gen a -> m () renderTree :: Show a => Size -> Seed -> Gen a -> String runGenT :: forall (m :: Type -> Type) a. Size -> Seed -> GenT m a -> TreeT (MaybeT m) a Source evalGen :: Size -> Seed -> Gen a -> Maybe (Tree a) Source evalGenT :: forall (m :: Type -> Type) a. Monad m => Size -> Seed -> GenT m a -> TreeT m (Maybe a) Source ``` -------------------------------- ### MonadResource Instance for GenT Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Gen Provides the MonadResource instance for GenT, allowing resource management within the GenT context. This instance is found in Hedgehog.Internal.Gen. ```haskell instance MonadResource m => MonadResource (GenT m) where liftResourceT :: ResourceT IO a -> GenT m a ``` -------------------------------- ### Haskell Callback Data Type for Command Configuration Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-State Defines the `Callback` data type for optional command configuration in state machine tests. It includes constructors for preconditions (`Require`), state updates (`Update`), and postconditions (`Ensure`), allowing for fine-grained control over command execution and verification. ```haskell data Callback (input :: (Type -> Type) -> Type) output (state :: (Type -> Type) -> Type) Source # -- Optional command configuration. Constructors Require (state Symbolic -> input Symbolic -> Bool)| -- A pre-condition for a command that must be verified before the command can be executed. This is mainly used during shrinking to ensure that it is still OK to run a command despite the fact that some previously executed commands may have been removed from the sequence. --|--- Update (forall (v :: Type -> Type). Ord1 v => state v -> input v -> Var output v -> state v)| -- Updates the model state, given the input and output of the command. Note that this function is polymorphic in the type of values. This is because it must work over `Symbolic` values when we are generating actions, and `Concrete` values when we are executing them. Ensure (state Concrete -> state Concrete -> input Concrete -> output -> Test ())| -- A post-condition for a command that must be verified for the command to be considered a success.This callback receives the state prior to execution as the first argument, and the state after execution as the second argument. ``` -------------------------------- ### Hedgehog Runner Configuration Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Runner Defines the configuration options for running Hedgehog property tests. It allows customization of worker count, color output, seed, and verbosity. Instances for Show, Eq, Ord, and Lift are provided. ```haskell data RunnerConfig = RunnerConfig { runnerWorkers :: !(Maybe WorkerCount), runnerColor :: !(Maybe UseColor), runnerSeed :: !(Maybe Seed), runnerVerbosity :: !(Maybe Verbosity) } -- Instances: -- Show RunnerConfig -- Eq RunnerConfig -- Ord RunnerConfig -- Lift RunnerConfig ``` -------------------------------- ### Haskell: Generating and Executing Actions Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-State Provides functions for generating sequential and parallel actions from commands, and for executing these actions within a test monad. This includes functions for managing state and handling potential errors. ```Haskell takeVariables :: TraversableB t => t Symbolic -> Map Name TypeRep variablesOK :: TraversableB t => t Symbolic -> Map Name TypeRep -> Bool dropInvalid :: forall (m :: Type -> Type) (state :: (Type -> Type) -> Type). [Action m state] -> State (Context state) [Action m state] action :: forall (gen :: Type -> Type) (m :: Type -> Type) (state :: (Type -> Type) -> Type). (MonadGen gen, MonadTest m) => [Command gen m state] -> GenT (StateT (Context state) (GenBase gen)) (Action m state) sequential :: forall gen (m :: Type -> Type) state. (MonadGen gen, MonadTest m) => Range Int -> (forall (v :: Type -> Type). state v) -> [Command gen m state] -> gen (Sequential m state) parallel :: forall gen (m :: Type -> Type) state. (MonadGen gen, MonadTest m) => Range Int -> Range Int -> (forall (v :: Type -> Type). state v) -> [Command gen m state] -> gen (Parallel m state) executeSequential :: (MonadTest m, MonadCatch m, HasCallStack) => (forall (v :: Type -> Type). state v) -> Sequential m state -> m () executeParallel :: (MonadTest m, MonadCatch m, MonadBaseControl IO m, HasCallStack) => (forall (v :: Type -> Type). state v) -> Parallel m state -> m () ``` -------------------------------- ### Show Instance for TestCount in Haskell Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Property Implements the Show type class instance for TestCount, enabling the conversion of TestCount values to their string representations. It includes showsPrec, show, and showList functions for flexible string formatting. ```Haskell showsPrec :: Int -> TestCount -> ShowS show :: TestCount -> String showList :: [TestCount] -> ShowS ``` -------------------------------- ### Applicative Instance for GenT Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Gen Provides the Applicative instance for GenT, enabling the application of functions within the GenT context. This instance is defined in Hedgehog.Internal.Gen. ```haskell instance Monad m => Applicative (GenT m) where pure :: a -> GenT m a (<*>) :: GenT m (a -> b) -> GenT m a -> GenT m b liftA2 :: (a -> b -> c) -> GenT m a -> GenT m b -> GenT m c (*>) :: GenT m a -> GenT m b -> GenT m b (<*) :: GenT m a -> GenT m b -> GenT m a ``` -------------------------------- ### TestT Instance for MonadResource Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Property Provides the MonadResource instance for TestT. This allows managing resources (like file handles or network connections) within the TestT monad transformer, typically by lifting from a `ResourceT IO` context. ```Haskell instance MonadResource m => MonadResource (TestT m) where liftResourceT = TestT . liftResourceT ``` -------------------------------- ### Action Generation and Execution Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-State Functions for generating and executing sequences of actions, both sequentially and in parallel. ```APIDOC ## Action Generation and Execution ### Description Provides functions for generating and executing sequences of actions. This includes generating single actions, sequences, and parallel actions, as well as executing them with verification. ### Functions - **`dropInvalid`** - **Description:** Drops invalid actions from a list of actions. - **Type:** `[Action m state] -> State (Context state) [Action m state]` - **`action`** - **Description:** Generates a single action from a set of possible commands. - **Type:** `(MonadGen gen, MonadTest m) => [Command gen m state] -> GenT (StateT (Context state) (GenBase gen)) (Action m state)` - **`sequential`** - **Description:** Generates a sequence of actions from an initial model state and a set of commands. - **Type:** `forall gen (m :: Type -> Type) state. (MonadGen gen, MonadTest m) => Range Int -> (forall (v :: Type -> Type). state v) -> [Command gen m state] -> gen (Sequential m state)` - **`parallel`** - **Description:** Generates prefix actions to be run sequentially, followed by two branches to be run in parallel. - **Type:** `forall gen (m :: Type -> Type) state. (MonadGen gen, MonadTest m) => Range Int -> Range Int -> (forall (v :: Type -> Type). state v) -> [Command gen m state] -> gen (Parallel m state)` - **`executeSequential`** - **Description:** Executes a list of actions sequentially, verifying post-conditions and exception handling. - **Type:** `(MonadTest m, MonadCatch m, HasCallStack) => (forall (v :: Type -> Type). state v) -> Sequential m state -> m ()` - **`executeParallel`** - **Description:** Executes prefix actions sequentially, then two branches in parallel, verifying exception handling and post-conditions. - **Type:** `(MonadTest m, MonadCatch m, MonadBaseControl IO m, HasCallStack) => (forall (v :: Type -> Type). state v) -> Parallel m state -> m ()` ### Related Concepts - **`takeVariables`**: Collects all symbolic values in a data structure to identify variables. - **`variablesOK`**: Checks if symbolic values in a data structure refer only to specified variables and have correct types. ``` -------------------------------- ### Haskell Test Discovery with Template Haskell Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/package/hedgehog Uses Template Haskell to automatically discover and run properties defined in the module. This is a convenient way to set up the test runner. ```haskell tests :: IO Bool tests = checkParallel $$(discover) ``` -------------------------------- ### Haskell: Verbosity Type Instances Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Config Demonstrates the instances for the `Verbosity` data type in Hedgehog.Internal.Config, showing its support for `Show`, `Eq`, `Ord`, and `Lift`. This allows for displaying, comparing, and lifting verbosity levels in tests. ```haskell instance Show Verbosity where showsPrec :: Int -> Verbosity -> ShowS show :: Verbosity -> String showList :: [Verbosity] -> ShowS instance Eq Verbosity where (==) :: Verbosity -> Verbosity -> Bool (/=) :: Verbosity -> Verbosity -> Bool instance Ord Verbosity where compare :: Verbosity -> Verbosity -> Ordering (<) :: Verbosity -> Verbosity -> Bool (<=) :: Verbosity -> Verbosity -> Bool (>) :: Verbosity -> Verbosity -> Bool (>=) :: Verbosity -> Verbosity -> Bool max :: Verbosity -> Verbosity -> Verbosity min :: Verbosity -> Verbosity -> Verbosity instance Lift Quote Verbosity where lift :: Quote m => Verbosity -> m Exp liftTyped :: forall (m :: Type -> Type). Quote m => Verbosity -> Code m Verbosity ``` -------------------------------- ### Haskell TH: Discover Properties with Prefix Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-TH The 'discoverPrefix' function allows discovering properties in a module that match a given string prefix. This is useful for organizing and selectively loading properties. ```Haskell discoverPrefix :: String -> TExpQ Group ``` -------------------------------- ### Haskell: Check Property Configuration and Report Progress Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Runner This function checks a property with a given configuration, size, seed, and property definition. It takes a function to report progress and returns a final report result. ```haskell checkReport :: (MonadIO m, MonadCatch m) => PropertyConfig -> Size -> Seed -> PropertyT m () -> (Report Progress -> m ()) -> m (Report Result) ``` -------------------------------- ### Haskell: Creating Properties from Tests and Generators Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Property Functions for creating `Property` values from `PropertyT` actions, generators, and `TestT` monads. `property` is the main entry point for defining properties, while `test`, `forAll`, and `forAllT` integrate generators and monadic tests. ```Haskell property :: HasCallStack => PropertyT IO () -> Property test :: forall (m :: Type -> Type) a. Monad m => TestT m a -> PropertyT m a forAll :: forall (m :: Type -> Type) a. (Monad m, Show a, HasCallStack) => Gen a -> PropertyT m a forAllT :: forall (m :: Type -> Type) a. (Monad m, Show a, HasCallStack) => GenT m a -> PropertyT m a forAllWith :: forall (m :: Type -> Type) a. (Monad m, HasCallStack) => (a -> String) -> Gen a -> PropertyT m a forAllWithT :: forall (m :: Type -> Type) a. (Monad m, HasCallStack) => (a -> String) -> GenT m a -> PropertyT m a ``` -------------------------------- ### Haskell: Environment Management for State Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-State Introduces the `Environment` type for managing state during test execution, including functions to create an empty environment, insert concrete values, and reify values from a dynamic representation. ```Haskell newtype Name = Name Int newtype Environment = Environment { unEnvironment :: Map Name Dynamic } data EnvironmentError = EnvironmentValueNotFound !Name | EnvironmentTypeError !TypeRep !TypeRep emptyEnvironment :: Environment insertConcrete :: Symbolic a -> Concrete a -> Environment -> Environment reifyDynamic :: Typeable a => Dynamic -> Either EnvironmentError (Concrete a) reifyEnvironment :: Environment -> forall a. Symbolic a -> Either EnvironmentError (Concrete a) reify :: TraversableB t => Environment -> t Symbolic -> Either EnvironmentError (t Concrete) ``` -------------------------------- ### Manage and Generate Actions (Haskell) Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-State Utilities for managing sequences of actions, including dropping invalid ones and generating single actions or sequences. These are core components for defining test scenarios. ```Haskell dropInvalid :: forall (m :: Type -> Type) (state :: (Type -> Type) -> Type). [Action m state] -> State (Context state) [Action m state] Source # Drops invalid actions from the sequence. action :: forall (gen :: Type -> Type) (m :: Type -> Type) (state :: (Type -> Type) -> Type). (MonadGen gen, MonadTest m) => [Command gen m state] -> GenT (StateT (Context state) (GenBase gen)) (Action m state) Source # Generates a single action from a set of possible commands. ``` -------------------------------- ### ShowS Instance for FilePath in Haskell Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/src/Hedgehog.Internal Demonstrates the 'ShowS' instance for the 'FilePath' type. 'ShowS' is used for efficient string concatenation in Haskell. This snippet defines how a 'FilePath' should be shown. ```haskell showString FilePath "LineNo " ShowS -> ShowS -> ShowS forall b c a. (b -> c) -> (a -> b) -> a -> c . Int -> Int -> ShowS forall a. Show a => Int -> a -> ShowS showsPrec Int 11 Int x ``` -------------------------------- ### Show and Eq Instances for Coverage Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Property The Coverage type has instances for Show and Eq, allowing Coverage values to be converted to strings for display and compared for equality. These instances are part of Hedgehog.Internal.Property. ```haskell show :: Coverage a -> String (==) :: Coverage a -> Coverage a -> Bool (/=) :: Coverage a -> Coverage a -> Bool ``` -------------------------------- ### Haskell: Show Instance for DiscardCount Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Property Details the Show instance for DiscardCount, enabling the conversion of DiscardCount values to String representations. ```Haskell showsPrec :: Int -> DiscardCount -> ShowS show :: DiscardCount -> String showList :: [DiscardCount] -> ShowS ``` -------------------------------- ### Haskell Environment Data Type and Instances Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-State Defines the `Environment` data type in Haskell, representing a mapping from symbolic values to concrete values. It includes the `Show` instance for displaying environments and related functions. ```Haskell newtype Environment Source # A mapping of symbolic values to concrete values. Constructors Environment| --- --- Fields * unEnvironment :: Map Name Dynamic Instances details Show Environment Source #| Instance detailsDefined in Hedgehog.Internal.State Methods showsPrec :: Int -> Environment -> ShowS #show :: Environment -> String #showList :: [Environment] -> ShowS # ``` -------------------------------- ### Haskell Lines Data Type Instances (Num, Show, Eq) Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Report Illustrates the Num, Show, and Eq instances for the Lines data type. These instances provide arithmetic operations (+, -, *, negate, abs, signum, fromInteger), string conversion (show, showsPrec), and equality checks (==, /=), treating Lines as a numerical type. ```haskell instance Num Lines where (+) :: Lines -> Lines -> Lines (-) :: Lines -> Lines -> Lines (*) :: Lines -> Lines -> Lines negate :: Lines -> Lines abs :: Lines -> Lines signum :: Lines -> Lines fromInteger :: Integer -> Lines instance Show Lines where showsPrec :: Int -> Lines -> ShowS show :: Lines -> String showList :: [Lines] -> ShowS instance Eq Lines where (==) :: Lines -> Lines -> Bool (/=) :: Lines -> Lines -> Bool ``` -------------------------------- ### Haskell Progress Type: Show and Eq Instances Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Report Defines the Show and Eq instances for the Progress data type in Haskell. These instances allow for the display and comparison of the status of a running property test. ```haskell data Progress Source # The status of a running property test. Constructors Running| --- Shrinking !FailureReport| #### Instances Instances details Show Progress Source #| --- Instance detailsDefined in Hedgehog.Internal.Report MethodsshowsPrec :: Int -> Progress -> ShowS #show :: Progress -> String #showList :: [Progress] -> ShowS # Eq Progress Source #| Instance detailsDefined in Hedgehog.Internal.Report Methods(==) :: Progress -> Progress -> Bool #(/=) :: Progress -> Progress -> Bool # ``` -------------------------------- ### Haskell Functions for Detecting Configuration Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Config A collection of `MonadIO` functions designed to detect various runtime configuration settings. These functions allow the application to determine parameters like Skip, Mark, Color, Seed, Verbosity, and WorkerCount from the environment or other sources. ```haskell resolveSkip :: MonadIO m => Maybe Skip -> m Skip detectMark :: MonadIO m => m Bool detectColor :: MonadIO m => m UseColor detectSeed :: MonadIO m => m Seed detectVerbosity :: MonadIO m => m Verbosity detectWorkers :: MonadIO m => m WorkerCount detectSkip :: MonadIO m => m Skip ``` -------------------------------- ### Eq Instance for Var Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-State Provides the Eq instance for the Var type, requiring 'a' and 'v' to also be instances of Eq and Eq1 respectively. Defined in Hedgehog.Internal.State. ```Haskell (==) :: Var a v -> Var a v -> Bool (/=) :: Var a v -> Var a v -> Bool ``` -------------------------------- ### Generate Sequential Commands for State Machine Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Gen Generates a sequence of commands to be executed against a model state. This is part of building abstract state machines and requires a generator, a monad for testing, a range for sequence length, an initial state definition, and a list of commands. ```haskell sequential :: forall gen (m :: Type -> Type) state. (MonadGen gen, MonadTest m) => Range Int -> (forall (v :: Type -> Type). state v) -> [Command gen m state] -> gen (Sequential m state) ``` -------------------------------- ### Haskell Instances for Name Type Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-State Details the instances for the Name type in Haskell, including Num, Show, Eq, and Ord. These instances define how Name values can be treated numerically, displayed as strings, compared for equality, and ordered. ```Haskell Instance detailsDefined in Hedgehog.Internal.State Methods(+) :: Name -> Name -> Name #(-) :: Name -> Name -> Name #(*) :: Name -> Name -> Name #negate :: Name -> Name #abs :: Name -> Name #signum :: Name -> Name #fromInteger :: Integer -> Name # Show Name Source #| Instance detailsDefined in Hedgehog.Internal.State Methods showsPrec :: Int -> Name -> ShowS #show :: Name -> String #showList :: [Name] -> ShowS # Eq Name Source #| Instance detailsDefined in Hedgehog.Internal.State Methods (==) :: Name -> Name -> Bool #(/=) :: Name -> Name -> Bool # Ord Name Source #| Instance detailsDefined in Hedgehog.Internal.State Methods compare :: Name -> Name -> Ordering #(<) :: Name -> Name -> Bool #(<=) :: Name -> Name -> Bool #(>) :: Name -> Name -> Bool #(>=) :: Name -> Name -> Bool #max :: Name -> Name -> Name #min :: Name -> Name -> Name # ``` -------------------------------- ### Haskell: Sampling and Printing Generated Values Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Gen Utilities for sampling values from a generator and printing them for inspection. `sample` produces a single value, while `print`, `printTree`, `printWith`, and `printTreeWith` offer various ways to display generated values and their internal structure, aiding in debugging and understanding. These require `MonadIO`. ```haskell sample :: (HasCallStack, MonadIO m) => Gen a -> m a print :: (MonadIO m, Show a) => Gen a -> m () printTree :: (MonadIO m, Show a) => Gen a -> m () printWith :: (MonadIO m, Show a) => Size -> Seed -> Gen a -> m () printTreeWith :: (MonadIO m, Show a) => Size -> Seed -> Gen a -> m () ``` -------------------------------- ### Haskell Environment Management Functions Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-State Provides core functions for managing environments in Haskell, including creating an empty environment, inserting symbolic-concrete pairings, and reifying values from dynamic types or environments. ```Haskell emptyEnvironment :: Environment Source # Create an empty environment. insertConcrete :: Symbolic a -> Concrete a -> Environment -> Environment Source # Insert a symbolic / concrete pairing in to the environment. reifyDynamic :: Typeable a => Dynamic -> Either EnvironmentError (Concrete a) Source # Cast a `Dynamic` in to a concrete value. reifyEnvironment :: Environment -> forall a. Symbolic a -> Either EnvironmentError (Concrete a) Source # Turns an environment in to a function for looking up a concrete value from a symbolic one. reify :: TraversableB t => Environment -> t Symbolic -> Either EnvironmentError (t Concrete) Source # Convert a symbolic structure to a concrete one, using the provided environment. ``` -------------------------------- ### Monad Instance for GenT Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Gen Defines the Monad instance for GenT, allowing sequential execution of monadic actions. This instance is found in Hedgehog.Internal.Gen. ```haskell instance Monad m => Monad (GenT m) where (>>=) :: GenT m a -> (a -> GenT m b) -> GenT m b (>>) :: GenT m a -> GenT m b -> GenT m b return :: a -> GenT m a ``` -------------------------------- ### Haskell: Configuring Property Test Limits (withTests, withDiscards, withShrinks) Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Property These functions allow configuration of property test limits in Haskell using the Hedgehog library. `withTests` sets the number of times a property must execute successfully. `withDiscards` limits the number of allowed discards before the test runner gives up. `withShrinks` limits the shrinking process before a counterexample is printed. ```haskell withTests :: TestLimit -> Property -> Property -- Sets the number of times a property should be executed before it is considered successful. withDiscards :: DiscardLimit -> Property -> Property -- Sets the number of times a property is allowed to discard before the test runner gives up. withShrinks :: ShrinkLimit -> Property -> Property -- Sets the number of times a property is allowed to shrink before the test runner gives up and prints the counterexample. ``` -------------------------------- ### Haskell: Integral Instance for DiscardCount Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Property Details the Integral instance for DiscardCount, providing functions for integer division, remainder, and conversion to Integer. ```Haskell quot :: DiscardCount -> DiscardCount -> DiscardCount rem :: DiscardCount -> DiscardCount -> DiscardCount div :: DiscardCount -> DiscardCount -> DiscardCount mod :: DiscardCount -> DiscardCount -> DiscardCount quotRem :: DiscardCount -> DiscardCount -> (DiscardCount, DiscardCount) divMod :: DiscardCount -> DiscardCount -> (DiscardCount, DiscardCount) toInteger :: DiscardCount -> Integer ``` -------------------------------- ### Show Instance for DiscardLimit Source: https://hackage-content.haskell.org/package/hedgehog-1.7/docs/Hedgehog-Internal-Property Enables the conversion of DiscardLimit values to String representations. This is useful for debugging and logging. Defined in Hedgehog.Internal.Property. ```Haskell showsPrec :: Int -> DiscardLimit -> ShowS show :: DiscardLimit -> String showList :: [DiscardLimit] -> ShowS ```