Skip to content

Commit

Permalink
Simple arbitrary instances
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspervdj committed Dec 4, 2010
1 parent 803c943 commit f90fdbc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions .ghci
@@ -0,0 +1 @@
:set -itests
36 changes: 36 additions & 0 deletions tests/Text/Digestive/Tests/Util.hs
@@ -0,0 +1,36 @@
module Text.Digestive.Tests.Util
( Id (..)
) where

import Control.Applicative (Applicative (..), (<$>))
import Test.QuickCheck (Arbitrary (..))

import Text.Digestive.Result
import Text.Digestive.Types

-- | An ID Monad
--
newtype Id a = Id {unId :: a}

instance Functor Id where
fmap f (Id x) = Id $ f x

instance Applicative Id where
pure = Id
(Id f) <*> (Id x) = Id $ f x

instance Monad Id where
return = Id
(Id x) >>= f = f x

instance Arbitrary a => Arbitrary (Result e a) where
arbitrary = Ok <$> arbitrary

instance Arbitrary v => Arbitrary (View e v) where
arbitrary = View . const <$> arbitrary

instance (Monad m, Arbitrary v, Arbitrary a) => Arbitrary (Form m i e v a) where
arbitrary = do
v <- arbitrary
r <- arbitrary
return $ Form $ return (v, r)

0 comments on commit f90fdbc

Please sign in to comment.