{-# LANGUAGE Rank2Types, ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE OverloadedStrings #-}
----------------------------------------------------------------------------
-- |
-- Module      :  Codec.Winery.Test
-- Copyright   :  (c) Fumiaki Kinoshita 2019
-- License     :  BSD3
-- Stability   :  Experimental
--
-- Maintainer  :  Fumiaki Kinoshita <fumiexcel@gmail.com>
--
-- A test framework that allows you to test all related Serialise instances
-- with automatically-generated test cases
--
-----------------------------------------------------------------------------
module Codec.Winery.Test
  ( -- * Generating tests
  TestGen(..)
  , printTests
  , buildTestGroups
  -- * Test cases
  , Tested(..)
  , testCase
  -- * Running tests
  , allTests
  , mergeTests
  ) where

import Test.HUnit
import qualified Data.Map as M
import qualified Data.HashMap.Strict as HM
import qualified Data.ByteString as B
import Data.Functor.Identity
import Data.Hashable
import Data.Proxy
import qualified Data.Set as Set
import qualified Data.Sequence as S
import Data.Typeable
import Codec.Winery
import Data.Word
import Data.Void
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import GHC.Generics
import Text.Show
import qualified Data.Text as T

-- | Construct a test case.
testCase :: (Show a, Eq a, Serialise a)
  => Schema -- ^ the schema
  -> B.ByteString -- ^ serialised
  -> a -- ^ expected
  -> Test
testCase :: Schema -> ByteString -> a -> Test
testCase Schema
sch ByteString
bs a
expected = case Schema -> Either WineryException (Decoder a)
forall a.
Serialise a =>
Schema -> Either WineryException (Decoder a)
getDecoder Schema
sch of
  Left WineryException
err -> Assertion -> Test
TestCase (Assertion -> Test) -> Assertion -> Test
forall a b. (a -> b) -> a -> b
$ String -> Assertion
forall a. HasCallStack => String -> IO a
assertFailure (WineryException -> String
forall a. Show a => a -> String
show WineryException
err)
  Right Decoder a
f -> a
expected a -> a -> Test
forall a. (HasCallStack, Eq a, Show a) => a -> a -> Test
~=? Decoder a -> ByteString -> a
forall a. Decoder a -> ByteString -> a
evalDecoder Decoder a
f ByteString
bs

-- | Merge multiple tests into one.
mergeTests :: M.Map TypeRep [Test] -> Test
mergeTests :: Map TypeRep [Test] -> Test
mergeTests = [Test] -> Test
TestList ([Test] -> Test)
-> (Map TypeRep [Test] -> [Test]) -> Map TypeRep [Test] -> Test
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((TypeRep, [Test]) -> [Test]) -> [(TypeRep, [Test])] -> [Test]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\(TypeRep
k, [Test]
v) -> (Test -> Test) -> [Test] -> [Test]
forall a b. (a -> b) -> [a] -> [b]
map (TypeRep -> String
forall a. Show a => a -> String
show TypeRep
k String -> Test -> Test
forall t. (HasCallStack, Testable t) => String -> t -> Test
~:) [Test]
v) ([(TypeRep, [Test])] -> [Test])
-> (Map TypeRep [Test] -> [(TypeRep, [Test])])
-> Map TypeRep [Test]
-> [Test]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map TypeRep [Test] -> [(TypeRep, [Test])]
forall k a. Map k a -> [(k, a)]
M.toList

-- | Gather all test cases involved in the specified type.
allTests :: forall a. (TestGen a, Tested a) => M.Map TypeRep [Test]
allTests :: Map TypeRep [Test]
allTests = ([Test] -> [Test] -> [Test])
-> TypeRep -> [Test] -> Map TypeRep [Test] -> Map TypeRep [Test]
forall k a. Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a
M.insertWith [Test] -> [Test] -> [Test]
forall a. [a] -> [a] -> [a]
(++) (Proxy a -> TypeRep
forall k (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (Proxy a
forall k (t :: k). Proxy t
Proxy @ a)) (Tested a => [Test]
forall a. Tested a => [Test]
testCases @ a) (Proxy a -> Map TypeRep [Test]
forall a. TestGen a => Proxy a -> Map TypeRep [Test]
inheritedTests (Proxy a
forall k (t :: k). Proxy t
Proxy @ a))

-- | Types with concrete test cases.
--
-- /"Doubt is useful, it keeps faith a living thing. After all, you cannot know
-- the strength of your faith until it has been tested."/
class TestGen a => Tested a where
  -- | List of test cases for the type.
  testCases :: [Test]

  default testCases :: (Serialise a, Eq a, Show a) => [Test]
  testCases = [Schema -> ByteString -> a -> Test
forall a.
(Show a, Eq a, Serialise a) =>
Schema -> ByteString -> a -> Test
testCase Schema
sch ByteString
b a
a | (Schema
sch, [(ByteString, a)]
xs) <- Tested a => [(Schema, [(ByteString, a)])]
forall a. Tested a => [(Schema, [(ByteString, a)])]
testGroups @ a, (ByteString
b, a
a) <- [(ByteString, a)]
xs]

  testGroups :: [(Schema, [(B.ByteString, a)])]
  testGroups = []
  {-# MINIMAL testGroups | testCases #-}

-- these are already covered by the QuickCheck tests from winery
instance Tested Void where testCases :: [Test]
testCases = []
instance Tested Bool where testCases :: [Test]
testCases = []
instance Tested Int where testCases :: [Test]
testCases = []
instance Tested Word8 where testCases :: [Test]
testCases = []
instance Tested Word16 where testCases :: [Test]
testCases = []
instance Tested Word32 where testCases :: [Test]
testCases = []
instance Tested Word64 where testCases :: [Test]
testCases = []
instance Tested Float where testCases :: [Test]
testCases = []
instance Tested Double where testCases :: [Test]
testCases = []
instance Tested () where testCases :: [Test]
testCases = []
instance Tested Char where testCases :: [Test]
testCases = []
instance Tested T.Text where testCases :: [Test]
testCases = []
instance Tested B.ByteString where testCases :: [Test]
testCases = []
instance Tested a => Tested (Identity a) where
  testCases :: [Test]
testCases = Tested a => [Test]
forall a. Tested a => [Test]
testCases @ a
instance Tested a => Tested (S.Seq a) where testCases :: [Test]
testCases = []
instance (Ord a, Tested a) => Tested (Set.Set a) where testCases :: [Test]
testCases = []
instance Tested a => Tested [a] where testCases :: [Test]
testCases = []
instance (Tested a, Tested b) => Tested (Either a b) where testCases :: [Test]
testCases = []
instance (Tested a, Tested b) => Tested (a, b) where testCases :: [Test]
testCases = []
instance (Tested a, Tested b, Tested c) => Tested (a, b, c) where testCases :: [Test]
testCases = []
instance (Tested a, Tested b, Tested c, Tested d) => Tested (a, b, c, d) where testCases :: [Test]
testCases = []
instance Tested a => Tested (V.Vector a) where testCases :: [Test]
testCases = []
instance (UV.Unbox a, Tested a) => Tested (UV.Vector a) where testCases :: [Test]
testCases = []
instance (Hashable k, Tested k, Tested a) => Tested (HM.HashMap k a) where testCases :: [Test]
testCases = []
instance (Ord k, Tested k, Tested a) => Tested (M.Map k a) where testCases :: [Test]
testCases = []
instance Tested a => TestGen (Maybe a)
instance Tested a => Tested (Maybe a) where testCases :: [Test]
testCases = []

-- | Generate test cases and print them to the standard output.
printTests :: forall a. (TestGen a, Serialise a, Show a) => IO ()
printTests :: Assertion
printTests = String -> Assertion
putStrLn (String -> Assertion) -> String -> Assertion
forall a b. (a -> b) -> a -> b
$ [a] -> String
forall a. (Serialise a, Show a) => [a] -> String
showTests ([a]
forall a. TestGen a => [a]
genTestCases :: [a])

buildTestGroups :: forall a. (TestGen a, Serialise a) => [(Schema, [(B.ByteString, a)])]
buildTestGroups :: [(Schema, [(ByteString, a)])]
buildTestGroups = [(Proxy a -> Schema
forall (proxy :: * -> *) a. Serialise a => proxy a -> Schema
schema (Proxy a
forall k (t :: k). Proxy t
Proxy @ a), [(a -> ByteString
forall a. Serialise a => a -> ByteString
serialiseOnly a
a, a
a) | a
a <- [a]
forall a. TestGen a => [a]
genTestCases :: [a]])]

showTests :: (Serialise a, Show a) => [a] -> String
showTests :: [a] -> String
showTests [a]
xs = (a -> ShowS) -> [a] -> ShowS
forall a. (a -> ShowS) -> [a] -> ShowS
showListWith a -> ShowS
forall a. (Serialise a, Show a) => a -> ShowS
ppTest [a]
xs String
""

ppTest :: (Serialise a, Show a) => a -> ShowS
ppTest :: a -> ShowS
ppTest a
a = String -> ShowS
showString String
"testCase "
  ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Schema -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 ([a] -> Schema
forall (proxy :: * -> *) a. Serialise a => proxy a -> Schema
schema [a
a])
  ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
  ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ByteString -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 (a -> ByteString
forall a. Serialise a => a -> ByteString
serialiseOnly a
a)
  ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
  ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 a
a

-- | A class to provide test values and gather tests for its components.
-- It is recommended to use the generic default methods.
class Typeable a => TestGen a where
  -- | A list of values that can be used as test cases.
  -- It should contain at least one value as long as there is a non-bottom value
  -- in the type.
  genTestCases :: [a]

  -- | Inherited set of test cases for each type it involves.
  inheritedTests :: Proxy a -> M.Map TypeRep [Test]

  default genTestCases :: (Generic a, GTestGen (Rep a)) => [a]
  genTestCases = (Rep a Any -> a) -> [Rep a Any] -> [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Rep a Any -> a
forall a x. Generic a => Rep a x -> a
to [Rep a Any]
forall (f :: * -> *) x. GTestGen f => [f x]
ggenTestCases

  default inheritedTests :: (GTestGen (Rep a)) => Proxy a -> M.Map TypeRep [Test]
  inheritedTests Proxy a
_ = Proxy (Rep a) -> Map TypeRep [Test]
forall (f :: * -> *) (proxy :: (* -> *) -> *).
GTestGen f =>
proxy f -> Map TypeRep [Test]
ginheritedTests (Proxy (Rep a)
forall k (t :: k). Proxy t
Proxy @ (Rep a))

class GTestGen f where
  ggenTestCases :: [f x]
  ginheritedTests :: proxy f -> M.Map TypeRep [Test]

instance GTestGen V1 where
  ggenTestCases :: [V1 x]
ggenTestCases = [V1 x]
forall a. Monoid a => a
mempty
  ginheritedTests :: proxy V1 -> Map TypeRep [Test]
ginheritedTests proxy V1
_ = Map TypeRep [Test]
forall a. Monoid a => a
mempty

instance GTestGen U1 where
  ggenTestCases :: [U1 x]
ggenTestCases = [U1 x
forall k (p :: k). U1 p
U1]
  ginheritedTests :: proxy U1 -> Map TypeRep [Test]
ginheritedTests proxy U1
_ = Map TypeRep [Test]
forall a. Monoid a => a
mempty

instance GTestGen f => GTestGen (Rec1 f) where
  ggenTestCases :: [Rec1 f x]
ggenTestCases = (f x -> Rec1 f x) -> [f x] -> [Rec1 f x]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap f x -> Rec1 f x
forall k (f :: k -> *) (p :: k). f p -> Rec1 f p
Rec1 [f x]
forall (f :: * -> *) x. GTestGen f => [f x]
ggenTestCases
  ginheritedTests :: proxy (Rec1 f) -> Map TypeRep [Test]
ginheritedTests proxy (Rec1 f)
_ = Proxy f -> Map TypeRep [Test]
forall (f :: * -> *) (proxy :: (* -> *) -> *).
GTestGen f =>
proxy f -> Map TypeRep [Test]
ginheritedTests (Proxy f
forall k (t :: k). Proxy t
Proxy @ f)

instance (Tested c, TestGen c) => GTestGen (K1 i c) where
  ggenTestCases :: [K1 i c x]
ggenTestCases = (c -> K1 i c x) -> [c] -> [K1 i c x]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap c -> K1 i c x
forall k i c (p :: k). c -> K1 i c p
K1 [c]
forall a. TestGen a => [a]
genTestCases
  ginheritedTests :: proxy (K1 i c) -> Map TypeRep [Test]
ginheritedTests proxy (K1 i c)
_ = (TestGen c, Tested c) => Map TypeRep [Test]
forall a. (TestGen a, Tested a) => Map TypeRep [Test]
allTests @ c

instance GTestGen f => GTestGen (M1 i c f) where
  ggenTestCases :: [M1 i c f x]
ggenTestCases = (f x -> M1 i c f x) -> [f x] -> [M1 i c f x]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap f x -> M1 i c f x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 [f x]
forall (f :: * -> *) x. GTestGen f => [f x]
ggenTestCases
  ginheritedTests :: proxy (M1 i c f) -> Map TypeRep [Test]
ginheritedTests proxy (M1 i c f)
_ = Proxy f -> Map TypeRep [Test]
forall (f :: * -> *) (proxy :: (* -> *) -> *).
GTestGen f =>
proxy f -> Map TypeRep [Test]
ginheritedTests (Proxy f
forall k (t :: k). Proxy t
Proxy @ f)

instance (GTestGen f, GTestGen g) => GTestGen (f :+: g) where
  ggenTestCases :: [(:+:) f g x]
ggenTestCases = (f x -> (:+:) f g x) -> [f x] -> [(:+:) f g x]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap f x -> (:+:) f g x
forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 [f x]
forall (f :: * -> *) x. GTestGen f => [f x]
ggenTestCases [(:+:) f g x] -> [(:+:) f g x] -> [(:+:) f g x]
forall a. [a] -> [a] -> [a]
++ (g x -> (:+:) f g x) -> [g x] -> [(:+:) f g x]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap g x -> (:+:) f g x
forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 [g x]
forall (f :: * -> *) x. GTestGen f => [f x]
ggenTestCases
  ginheritedTests :: proxy (f :+: g) -> Map TypeRep [Test]
ginheritedTests proxy (f :+: g)
_ = Proxy f -> Map TypeRep [Test]
forall (f :: * -> *) (proxy :: (* -> *) -> *).
GTestGen f =>
proxy f -> Map TypeRep [Test]
ginheritedTests (Proxy f
forall k (t :: k). Proxy t
Proxy @ f)
    Map TypeRep [Test] -> Map TypeRep [Test] -> Map TypeRep [Test]
forall a. Monoid a => a -> a -> a
`mappend` Proxy g -> Map TypeRep [Test]
forall (f :: * -> *) (proxy :: (* -> *) -> *).
GTestGen f =>
proxy f -> Map TypeRep [Test]
ginheritedTests (Proxy g
forall k (t :: k). Proxy t
Proxy @ g)

instance (GTestGen f, GTestGen g) => GTestGen (f :*: g) where
  ggenTestCases :: [(:*:) f g x]
ggenTestCases = (f x -> g x -> (:*:) f g x
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
(:*:) (f x -> g x -> (:*:) f g x) -> [f x] -> [g x -> (:*:) f g x]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [f x]
forall (f :: * -> *) x. GTestGen f => [f x]
ggenTestCases [g x -> (:*:) f g x] -> [g x] -> [(:*:) f g x]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [g x]
forall x. [g x]
xs)
    [(:*:) f g x] -> [(:*:) f g x] -> [(:*:) f g x]
forall a. [a] -> [a] -> [a]
++ (f x -> g x -> (:*:) f g x
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
(:*:) (f x -> g x -> (:*:) f g x) -> [f x] -> [g x -> (:*:) f g x]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> [f x] -> [f x]
forall a. Int -> [a] -> [a]
take Int
1 [f x]
forall (f :: * -> *) x. GTestGen f => [f x]
ggenTestCases [g x -> (:*:) f g x] -> [g x] -> [(:*:) f g x]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [g x]
forall x. [g x]
ys)
    where
      ([g x]
xs, [g x]
ys) = Int -> [g x] -> ([g x], [g x])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
1 [g x]
forall (f :: * -> *) x. GTestGen f => [f x]
ggenTestCases
  ginheritedTests :: proxy (f :*: g) -> Map TypeRep [Test]
ginheritedTests proxy (f :*: g)
_ = Proxy f -> Map TypeRep [Test]
forall (f :: * -> *) (proxy :: (* -> *) -> *).
GTestGen f =>
proxy f -> Map TypeRep [Test]
ginheritedTests (Proxy f
forall k (t :: k). Proxy t
Proxy @ f)
    Map TypeRep [Test] -> Map TypeRep [Test] -> Map TypeRep [Test]
forall a. Monoid a => a -> a -> a
`mappend` Proxy g -> Map TypeRep [Test]
forall (f :: * -> *) (proxy :: (* -> *) -> *).
GTestGen f =>
proxy f -> Map TypeRep [Test]
ginheritedTests (Proxy g
forall k (t :: k). Proxy t
Proxy @ g)

deriving instance TestGen a => TestGen (Identity a)
instance TestGen ()
instance TestGen Bool
instance (Tested a, Tested b) => TestGen (a, b)
instance (Tested a, Tested b, Tested c) => TestGen (a, b, c)
instance (Tested a, Tested b, Tested c, Tested d) => TestGen (a, b, c, d)
instance (Tested a, Tested b) => TestGen (Either a b)

instance Tested a => TestGen [a] where
  genTestCases :: [[a]]
genTestCases = [[]]
  inheritedTests :: Proxy [a] -> Map TypeRep [Test]
inheritedTests Proxy [a]
_ = (TestGen a, Tested a) => Map TypeRep [Test]
forall a. (TestGen a, Tested a) => Map TypeRep [Test]
allTests @ a

instance (Ord a, Tested a) => TestGen (Set.Set a) where
  genTestCases :: [Set a]
genTestCases = [Set a
forall a. Monoid a => a
mempty]
  inheritedTests :: Proxy (Set a) -> Map TypeRep [Test]
inheritedTests Proxy (Set a)
_ = (TestGen a, Tested a) => Map TypeRep [Test]
forall a. (TestGen a, Tested a) => Map TypeRep [Test]
allTests @ a

instance Tested a => TestGen (S.Seq a) where
  genTestCases :: [Seq a]
genTestCases = [Seq a
forall a. Monoid a => a
mempty]
  inheritedTests :: Proxy (Seq a) -> Map TypeRep [Test]
inheritedTests Proxy (Seq a)
_ = (TestGen a, Tested a) => Map TypeRep [Test]
forall a. (TestGen a, Tested a) => Map TypeRep [Test]
allTests @ a

instance Tested a => TestGen (V.Vector a) where
  genTestCases :: [Vector a]
genTestCases = [Vector a
forall a. Vector a
V.empty]
  inheritedTests :: Proxy (Vector a) -> Map TypeRep [Test]
inheritedTests Proxy (Vector a)
_ = (TestGen a, Tested a) => Map TypeRep [Test]
forall a. (TestGen a, Tested a) => Map TypeRep [Test]
allTests @ a

instance (UV.Unbox a, Tested a) => TestGen (UV.Vector a) where
  genTestCases :: [Vector a]
genTestCases = [Vector a
forall a. Unbox a => Vector a
UV.empty]
  inheritedTests :: Proxy (Vector a) -> Map TypeRep [Test]
inheritedTests Proxy (Vector a)
_ = (TestGen a, Tested a) => Map TypeRep [Test]
forall a. (TestGen a, Tested a) => Map TypeRep [Test]
allTests @ a

instance (Hashable k, Tested k, Tested a) => TestGen (HM.HashMap k a) where
  genTestCases :: [HashMap k a]
genTestCases = k -> a -> HashMap k a
forall k v. Hashable k => k -> v -> HashMap k v
HM.singleton (k -> a -> HashMap k a) -> [k] -> [a -> HashMap k a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [k]
forall a. TestGen a => [a]
genTestCases [a -> HashMap k a] -> [a] -> [HashMap k a]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [a]
forall a. TestGen a => [a]
genTestCases
  inheritedTests :: Proxy (HashMap k a) -> Map TypeRep [Test]
inheritedTests Proxy (HashMap k a)
_ = (TestGen k, Tested k) => Map TypeRep [Test]
forall a. (TestGen a, Tested a) => Map TypeRep [Test]
allTests @ k Map TypeRep [Test] -> Map TypeRep [Test] -> Map TypeRep [Test]
forall a. Monoid a => a -> a -> a
`mappend` (TestGen a, Tested a) => Map TypeRep [Test]
forall a. (TestGen a, Tested a) => Map TypeRep [Test]
allTests @ a

instance (Ord k, Tested k, Tested a) => TestGen (M.Map k a) where
  genTestCases :: [Map k a]
genTestCases = [Map k a
forall k a. Map k a
M.empty]
  inheritedTests :: Proxy (Map k a) -> Map TypeRep [Test]
inheritedTests Proxy (Map k a)
_ = (TestGen k, Tested k) => Map TypeRep [Test]
forall a. (TestGen a, Tested a) => Map TypeRep [Test]
allTests @ k Map TypeRep [Test] -> Map TypeRep [Test] -> Map TypeRep [Test]
forall a. Monoid a => a -> a -> a
`mappend` (TestGen a, Tested a) => Map TypeRep [Test]
forall a. (TestGen a, Tested a) => Map TypeRep [Test]
allTests @ a

instance TestGen Void where
  genTestCases :: [Void]
genTestCases = []
  inheritedTests :: Proxy Void -> Map TypeRep [Test]
inheritedTests = Proxy Void -> Map TypeRep [Test]
forall a. Monoid a => a
mempty

instance TestGen Int where
  genTestCases :: [Int]
genTestCases = [Int
42]
  inheritedTests :: Proxy Int -> Map TypeRep [Test]
inheritedTests = Proxy Int -> Map TypeRep [Test]
forall a. Monoid a => a
mempty

instance TestGen Word8 where
  genTestCases :: [Word8]
genTestCases = [Word8
8]
  inheritedTests :: Proxy Word8 -> Map TypeRep [Test]
inheritedTests = Proxy Word8 -> Map TypeRep [Test]
forall a. Monoid a => a
mempty

instance TestGen Word16 where
  genTestCases :: [Word16]
genTestCases = [Word16
16]
  inheritedTests :: Proxy Word16 -> Map TypeRep [Test]
inheritedTests = Proxy Word16 -> Map TypeRep [Test]
forall a. Monoid a => a
mempty

instance TestGen Word32 where
  genTestCases :: [Word32]
genTestCases = [Word32
32]
  inheritedTests :: Proxy Word32 -> Map TypeRep [Test]
inheritedTests = Proxy Word32 -> Map TypeRep [Test]
forall a. Monoid a => a
mempty

instance TestGen Word64 where
  genTestCases :: [Word64]
genTestCases = [Word64
64]
  inheritedTests :: Proxy Word64 -> Map TypeRep [Test]
inheritedTests = Proxy Word64 -> Map TypeRep [Test]
forall a. Monoid a => a
mempty

instance TestGen Float where
  genTestCases :: [Float]
genTestCases = [Float
0.1]

  inheritedTests :: Proxy Float -> Map TypeRep [Test]
inheritedTests = Proxy Float -> Map TypeRep [Test]
forall a. Monoid a => a
mempty
instance TestGen Double where
  genTestCases :: [Double]
genTestCases = [Double
0.2]
  inheritedTests :: Proxy Double -> Map TypeRep [Test]
inheritedTests = Proxy Double -> Map TypeRep [Test]
forall a. Monoid a => a
mempty

instance TestGen Char where
  genTestCases :: String
genTestCases = [Char
'X']
  inheritedTests :: Proxy Char -> Map TypeRep [Test]
inheritedTests = Proxy Char -> Map TypeRep [Test]
forall a. Monoid a => a
mempty

instance TestGen T.Text where
  genTestCases :: [Text]
genTestCases = [Text
"葡"]
  inheritedTests :: Proxy Text -> Map TypeRep [Test]
inheritedTests = Proxy Text -> Map TypeRep [Test]
forall a. Monoid a => a
mempty

instance TestGen B.ByteString where
  genTestCases :: [ByteString]
genTestCases = [ByteString
"B"]
  inheritedTests :: Proxy ByteString -> Map TypeRep [Test]
inheritedTests = Proxy ByteString -> Map TypeRep [Test]
forall a. Monoid a => a
mempty