{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE FlexibleInstances, ScopedTypeVariables, OverloadedStrings #-}
-- provides Arbitrary instance for Pandoc types
module Text.Pandoc.Arbitrary ()
where
import Test.QuickCheck
import Control.Applicative (Applicative ((<*>), pure), (<$>))
import Control.Monad (forM)
import Data.Text (Text)
import qualified Data.Text as T
import Text.Pandoc.Definition
import Text.Pandoc.Builder

realString :: Gen Text
realString :: Gen Text
realString = (String -> Text) -> Gen String -> Gen Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Text
T.pack (Gen String -> Gen Text) -> Gen String -> Gen Text
forall a b. (a -> b) -> a -> b
$ Int -> Gen String -> Gen String
forall a. Int -> Gen a -> Gen a
resize Int
8 (Gen String -> Gen String) -> Gen String -> Gen String
forall a b. (a -> b) -> a -> b
$ Gen Char -> Gen String
forall a. Gen a -> Gen [a]
listOf (Gen Char -> Gen String) -> Gen Char -> Gen String
forall a b. (a -> b) -> a -> b
$ [(Int, Gen Char)] -> Gen Char
forall a. [(Int, Gen a)] -> Gen a
frequency [ (Int
9, String -> Gen Char
forall a. [a] -> Gen a
elements [Char
' '..Char
'\127'])
                                                         , (Int
1, String -> Gen Char
forall a. [a] -> Gen a
elements [Char
'\128'..Char
'\9999']) ]

shrinkText :: Text -> [Text]
shrinkText :: Text -> [Text]
shrinkText Text
xs = String -> Text
T.pack (String -> Text) -> [String] -> [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> [String]
forall a. Arbitrary a => a -> [a]
shrink (Text -> String
T.unpack Text
xs)

shrinkText2 :: (Text, Text) -> [(Text, Text)]
shrinkText2 :: (Text, Text) -> [(Text, Text)]
shrinkText2 = (Text -> [Text])
-> (Text -> [Text]) -> (Text, Text) -> [(Text, Text)]
forall (f :: * -> * -> *) a b.
Arbitrary2 f =>
(a -> [a]) -> (b -> [b]) -> f a b -> [f a b]
liftShrink2 Text -> [Text]
shrinkText Text -> [Text]
shrinkText

arbAttr :: Gen Attr
arbAttr :: Gen Attr
arbAttr = do
  Text
id' <- [Text] -> Gen Text
forall a. [a] -> Gen a
elements [Text
"",Text
"loc"]
  [Text]
classes' <- [[Text]] -> Gen [Text]
forall a. [a] -> Gen a
elements [[],[Text
"haskell"],[Text
"c",Text
"numberLines"]]
  [(Text, Text)]
keyvals <- [[(Text, Text)]] -> Gen [(Text, Text)]
forall a. [a] -> Gen a
elements [[],[(Text
"start",Text
"22")],[(Text
"a",Text
"11"),(Text
"b_2",Text
"a b c")]]
  Attr -> Gen Attr
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
id',[Text]
classes',[(Text, Text)]
keyvals)

shrinkAttr :: Attr -> [Attr]
shrinkAttr :: Attr -> [Attr]
shrinkAttr (Text
a, [Text]
b, [(Text, Text)]
c)
  = [ (Text
a', [Text]
b', [(Text, Text)]
c') | Text
a' <- Text -> [Text]
shrinkText Text
a,
                     [Text]
b' <- (Text -> [Text]) -> [Text] -> [[Text]]
forall (f :: * -> *) a. Arbitrary1 f => (a -> [a]) -> f a -> [f a]
liftShrink Text -> [Text]
shrinkText [Text]
b,
                     [(Text, Text)]
c' <- ((Text, Text) -> [(Text, Text)])
-> [(Text, Text)] -> [[(Text, Text)]]
forall (f :: * -> *) a. Arbitrary1 f => (a -> [a]) -> f a -> [f a]
liftShrink (Text, Text) -> [(Text, Text)]
shrinkText2 [(Text, Text)]
c ]

instance Arbitrary Inlines where
  arbitrary :: Gen Inlines
arbitrary = ([Inline] -> Inlines
forall a. [a] -> Many a
fromList :: [Inline] -> Inlines) ([Inline] -> Inlines) -> Gen [Inline] -> Gen Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [Inline]
forall a. Arbitrary a => Gen a
arbitrary
  shrink :: Inlines -> [Inlines]
shrink = ([Inline] -> Inlines) -> [[Inline]] -> [Inlines]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Inline] -> Inlines
forall a. [a] -> Many a
fromList ([[Inline]] -> [Inlines])
-> (Inlines -> [[Inline]]) -> Inlines -> [Inlines]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([[Inline]] -> [[Inline]] -> [[Inline]]
forall a. [a] -> [a] -> [a]
(++) ([[Inline]] -> [[Inline]] -> [[Inline]])
-> ([Inline] -> [[Inline]]) -> [Inline] -> [[Inline]] -> [[Inline]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Inline] -> [[Inline]]
forall a. Arbitrary a => a -> [a]
shrink ([Inline] -> [[Inline]] -> [[Inline]])
-> ([Inline] -> [[Inline]]) -> [Inline] -> [[Inline]]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Inline] -> [[Inline]]
flattenShrinkInlines) ([Inline] -> [[Inline]])
-> (Inlines -> [Inline]) -> Inlines -> [[Inline]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> [Inline]
forall a. Many a -> [a]
toList
    where flattenShrinkInlines :: [Inline] -> [[Inline]]
flattenShrinkInlines (Inline
x:[Inline]
xs) =
            let x' :: [Inline]
x' = Inline -> [Inline]
flattenInline Inline
x
            in (if [Inline] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Inline]
x' then [] else [[Inline]
x' [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ [Inline]
xs]) [[Inline]] -> [[Inline]] -> [[Inline]]
forall a. [a] -> [a] -> [a]
++ [Inline
xInline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
:[Inline]
xs' | [Inline]
xs' <- [Inline] -> [[Inline]]
flattenShrinkInlines [Inline]
xs]
          flattenShrinkInlines [] = []
          flattenInline :: Inline -> [Inline]
          flattenInline :: Inline -> [Inline]
flattenInline (Str Text
_) = []
          flattenInline (Emph [Inline]
ils) = [Inline]
ils
          flattenInline (Underline [Inline]
ils) = [Inline]
ils
          flattenInline (Strong [Inline]
ils) = [Inline]
ils
          flattenInline (Strikeout [Inline]
ils) = [Inline]
ils
          flattenInline (Superscript [Inline]
ils) = [Inline]
ils
          flattenInline (Subscript [Inline]
ils) = [Inline]
ils
          flattenInline (SmallCaps [Inline]
ils) = [Inline]
ils
          flattenInline (Quoted QuoteType
_ [Inline]
ils) = [Inline]
ils
          flattenInline (Cite [Citation]
_ [Inline]
ils) = [Inline]
ils
          flattenInline Code{} = []
          flattenInline Inline
Space = []
          flattenInline Inline
SoftBreak = []
          flattenInline Inline
LineBreak = []
          flattenInline Math{} = []
          flattenInline RawInline{} = []
          flattenInline (Link Attr
_ [Inline]
ils (Text, Text)
_) = [Inline]
ils
          flattenInline (Image Attr
_ [Inline]
ils (Text, Text)
_) = [Inline]
ils
          flattenInline Note{} = []
          flattenInline (Span Attr
_ [Inline]
ils) = [Inline]
ils

instance Arbitrary Blocks where
  arbitrary :: Gen Blocks
arbitrary = ([Block] -> Blocks
forall a. [a] -> Many a
fromList :: [Block] -> Blocks) ([Block] -> Blocks) -> Gen [Block] -> Gen Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [Block]
forall a. Arbitrary a => Gen a
arbitrary
  shrink :: Blocks -> [Blocks]
shrink = ([Block] -> Blocks) -> [[Block]] -> [Blocks]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Block] -> Blocks
forall a. [a] -> Many a
fromList ([[Block]] -> [Blocks])
-> (Blocks -> [[Block]]) -> Blocks -> [Blocks]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([[Block]] -> [[Block]] -> [[Block]]
forall a. [a] -> [a] -> [a]
(++) ([[Block]] -> [[Block]] -> [[Block]])
-> ([Block] -> [[Block]]) -> [Block] -> [[Block]] -> [[Block]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Block] -> [[Block]]
forall a. Arbitrary a => a -> [a]
shrink ([Block] -> [[Block]] -> [[Block]])
-> ([Block] -> [[Block]]) -> [Block] -> [[Block]]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Block] -> [[Block]]
flattenShrinkBlocks) ([Block] -> [[Block]])
-> (Blocks -> [Block]) -> Blocks -> [[Block]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Blocks -> [Block]
forall a. Many a -> [a]
toList
    where flattenShrinkBlocks :: [Block] -> [[Block]]
flattenShrinkBlocks (Block
x:[Block]
xs) =
            let x' :: [Block]
x' = Block -> [Block]
flattenBlock Block
x
            in (if [Block] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Block]
x' then [] else [[Block]
x' [Block] -> [Block] -> [Block]
forall a. [a] -> [a] -> [a]
++ [Block]
xs]) [[Block]] -> [[Block]] -> [[Block]]
forall a. [a] -> [a] -> [a]
++ [Block
xBlock -> [Block] -> [Block]
forall a. a -> [a] -> [a]
:[Block]
xs' | [Block]
xs' <- [Block] -> [[Block]]
flattenShrinkBlocks [Block]
xs]
          flattenShrinkBlocks [] = []
          flattenBlock :: Block -> [Block]
          flattenBlock :: Block -> [Block]
flattenBlock Plain{} = []
          flattenBlock Para{} = []
          flattenBlock (LineBlock [[Inline]]
lns) = [[Inline] -> Block
Para [Inline]
x | [Inline]
x <- [[Inline]]
lns]
          flattenBlock CodeBlock{} = []
          flattenBlock RawBlock{} = []
          flattenBlock (BlockQuote [Block]
blks) = [Block]
blks
          flattenBlock (OrderedList ListAttributes
_ [[Block]]
blksList) = [[Block]] -> [Block]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Block]]
blksList
          flattenBlock (BulletList [[Block]]
blksList) = [[Block]] -> [Block]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Block]]
blksList
          flattenBlock (DefinitionList [([Inline], [[Block]])]
defs) = [[Block]] -> [Block]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Inline] -> Block
Para [Inline]
ilsBlock -> [Block] -> [Block]
forall a. a -> [a] -> [a]
:[[Block]] -> [Block]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Block]]
blks | ([Inline]
ils, [[Block]]
blks) <- [([Inline], [[Block]])]
defs]
          flattenBlock (Header Int
_ Attr
_ [Inline]
ils) = [[Inline] -> Block
Para [Inline]
ils]
          flattenBlock Block
HorizontalRule = []
          flattenBlock (Table Attr
_ Caption
capt [ColSpec]
_ TableHead
hd [TableBody]
bd TableFoot
ft) = Caption -> [Block]
flattenCaption Caption
capt [Block] -> [Block] -> [Block]
forall a. Semigroup a => a -> a -> a
<>
                                                   TableHead -> [Block]
flattenTableHead TableHead
hd [Block] -> [Block] -> [Block]
forall a. Semigroup a => a -> a -> a
<>
                                                   (TableBody -> [Block]) -> [TableBody] -> [Block]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap TableBody -> [Block]
flattenTableBody [TableBody]
bd [Block] -> [Block] -> [Block]
forall a. Semigroup a => a -> a -> a
<>
                                                   TableFoot -> [Block]
flattenTableFoot TableFoot
ft
          flattenBlock (Div Attr
_ [Block]
blks) = [Block]
blks
          flattenBlock Block
Null = []

          flattenCaption :: Caption -> [Block]
flattenCaption (Caption Maybe [Inline]
Nothing [Block]
body)    = [Block]
body
          flattenCaption (Caption (Just [Inline]
ils) [Block]
body) = [Inline] -> Block
Para [Inline]
ils Block -> [Block] -> [Block]
forall a. a -> [a] -> [a]
: [Block]
body

          flattenTableHead :: TableHead -> [Block]
flattenTableHead (TableHead Attr
_ [Row]
body) = [Row] -> [Block]
flattenRows [Row]
body
          flattenTableBody :: TableBody -> [Block]
flattenTableBody (TableBody Attr
_ RowHeadColumns
_ [Row]
hd [Row]
bd) = [Row] -> [Block]
flattenRows [Row]
hd [Block] -> [Block] -> [Block]
forall a. Semigroup a => a -> a -> a
<> [Row] -> [Block]
flattenRows [Row]
bd
          flattenTableFoot :: TableFoot -> [Block]
flattenTableFoot (TableFoot Attr
_ [Row]
body) = [Row] -> [Block]
flattenRows [Row]
body

          flattenRows :: [Row] -> [Block]
flattenRows = (Row -> [Block]) -> [Row] -> [Block]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Row -> [Block]
flattenRow
          flattenRow :: Row -> [Block]
flattenRow (Row Attr
_ [Cell]
body) = (Cell -> [Block]) -> [Cell] -> [Block]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Cell -> [Block]
flattenCell [Cell]
body
          flattenCell :: Cell -> [Block]
flattenCell (Cell Attr
_ Alignment
_ RowSpan
_ ColSpan
_ [Block]
blks) = [Block]
blks

shrinkInlineList :: [Inline] -> [[Inline]]
shrinkInlineList :: [Inline] -> [[Inline]]
shrinkInlineList = (Inlines -> [Inline]) -> [Inlines] -> [[Inline]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> [Inline]
forall a. Many a -> [a]
toList ([Inlines] -> [[Inline]])
-> ([Inline] -> [Inlines]) -> [Inline] -> [[Inline]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> [Inlines]
forall a. Arbitrary a => a -> [a]
shrink (Inlines -> [Inlines])
-> ([Inline] -> Inlines) -> [Inline] -> [Inlines]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inline] -> Inlines
forall a. [a] -> Many a
fromList

shrinkInlinesList :: [[Inline]] -> [[[Inline]]]
shrinkInlinesList :: [[Inline]] -> [[[Inline]]]
shrinkInlinesList = ([Inlines] -> [[Inline]]) -> [[Inlines]] -> [[[Inline]]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Inlines -> [Inline]) -> [Inlines] -> [[Inline]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> [Inline]
forall a. Many a -> [a]
toList) ([[Inlines]] -> [[[Inline]]])
-> ([[Inline]] -> [[Inlines]]) -> [[Inline]] -> [[[Inline]]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> [[Inlines]]
forall a. Arbitrary a => a -> [a]
shrink ([Inlines] -> [[Inlines]])
-> ([[Inline]] -> [Inlines]) -> [[Inline]] -> [[Inlines]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Inline] -> Inlines) -> [[Inline]] -> [Inlines]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Inline] -> Inlines
forall a. [a] -> Many a
fromList

shrinkBlockList :: [Block] -> [[Block]]
shrinkBlockList :: [Block] -> [[Block]]
shrinkBlockList = (Blocks -> [Block]) -> [Blocks] -> [[Block]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Blocks -> [Block]
forall a. Many a -> [a]
toList ([Blocks] -> [[Block]])
-> ([Block] -> [Blocks]) -> [Block] -> [[Block]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Blocks -> [Blocks]
forall a. Arbitrary a => a -> [a]
shrink (Blocks -> [Blocks]) -> ([Block] -> Blocks) -> [Block] -> [Blocks]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Block] -> Blocks
forall a. [a] -> Many a
fromList

shrinkBlocksList :: [[Block]] -> [[[Block]]]
shrinkBlocksList :: [[Block]] -> [[[Block]]]
shrinkBlocksList = ([Blocks] -> [[Block]]) -> [[Blocks]] -> [[[Block]]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Blocks -> [Block]) -> [Blocks] -> [[Block]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Blocks -> [Block]
forall a. Many a -> [a]
toList) ([[Blocks]] -> [[[Block]]])
-> ([[Block]] -> [[Blocks]]) -> [[Block]] -> [[[Block]]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Blocks] -> [[Blocks]]
forall a. Arbitrary a => a -> [a]
shrink ([Blocks] -> [[Blocks]])
-> ([[Block]] -> [Blocks]) -> [[Block]] -> [[Blocks]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Block] -> Blocks) -> [[Block]] -> [Blocks]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Block] -> Blocks
forall a. [a] -> Many a
fromList

instance Arbitrary Inline where
  arbitrary :: Gen Inline
arbitrary = Int -> Gen Inline -> Gen Inline
forall a. Int -> Gen a -> Gen a
resize Int
3 (Gen Inline -> Gen Inline) -> Gen Inline -> Gen Inline
forall a b. (a -> b) -> a -> b
$ Int -> Gen Inline
arbInline Int
2
  shrink :: Inline -> [Inline]
shrink (Str Text
s) = Text -> Inline
Str (Text -> Inline) -> [Text] -> [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> [Text]
shrinkText Text
s
  shrink (Emph [Inline]
ils) = [Inline] -> Inline
Emph ([Inline] -> Inline) -> [[Inline]] -> [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Inline] -> [[Inline]]
shrinkInlineList [Inline]
ils
  shrink (Underline [Inline]
ils) = [Inline] -> Inline
Underline ([Inline] -> Inline) -> [[Inline]] -> [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Inline] -> [[Inline]]
shrinkInlineList [Inline]
ils
  shrink (Strong [Inline]
ils) = [Inline] -> Inline
Strong ([Inline] -> Inline) -> [[Inline]] -> [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Inline] -> [[Inline]]
shrinkInlineList [Inline]
ils
  shrink (Strikeout [Inline]
ils) = [Inline] -> Inline
Strikeout ([Inline] -> Inline) -> [[Inline]] -> [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Inline] -> [[Inline]]
shrinkInlineList [Inline]
ils
  shrink (Superscript [Inline]
ils) = [Inline] -> Inline
Superscript ([Inline] -> Inline) -> [[Inline]] -> [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Inline] -> [[Inline]]
shrinkInlineList [Inline]
ils
  shrink (Subscript [Inline]
ils) = [Inline] -> Inline
Subscript ([Inline] -> Inline) -> [[Inline]] -> [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Inline] -> [[Inline]]
shrinkInlineList [Inline]
ils
  shrink (SmallCaps [Inline]
ils) = [Inline] -> Inline
SmallCaps ([Inline] -> Inline) -> [[Inline]] -> [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Inline] -> [[Inline]]
shrinkInlineList [Inline]
ils
  shrink (Quoted QuoteType
qtype [Inline]
ils) = QuoteType -> [Inline] -> Inline
Quoted QuoteType
qtype ([Inline] -> Inline) -> [[Inline]] -> [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Inline] -> [[Inline]]
shrinkInlineList [Inline]
ils
  shrink (Cite [Citation]
cits [Inline]
ils) = ([Citation] -> [Inline] -> Inline
Cite [Citation]
cits ([Inline] -> Inline) -> [[Inline]] -> [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Inline] -> [[Inline]]
shrinkInlineList [Inline]
ils)
                        [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ (([Citation] -> [Inline] -> Inline)
-> [Inline] -> [Citation] -> Inline
forall a b c. (a -> b -> c) -> b -> a -> c
flip [Citation] -> [Inline] -> Inline
Cite [Inline]
ils ([Citation] -> Inline) -> [[Citation]] -> [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Citation] -> [[Citation]]
forall a. Arbitrary a => a -> [a]
shrink [Citation]
cits)
  shrink (Code Attr
attr Text
s) = (Attr -> Text -> Inline
Code Attr
attr (Text -> Inline) -> [Text] -> [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> [Text]
shrinkText Text
s)
                      [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ ((Attr -> Text -> Inline) -> Text -> Attr -> Inline
forall a b c. (a -> b -> c) -> b -> a -> c
flip Attr -> Text -> Inline
Code Text
s (Attr -> Inline) -> [Attr] -> [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Attr -> [Attr]
shrinkAttr Attr
attr)
  shrink Inline
Space = []
  shrink Inline
SoftBreak = []
  shrink Inline
LineBreak = []
  shrink (Math MathType
mtype Text
s) = MathType -> Text -> Inline
Math MathType
mtype (Text -> Inline) -> [Text] -> [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> [Text]
shrinkText Text
s
  shrink (RawInline Format
fmt Text
s) = Format -> Text -> Inline
RawInline Format
fmt (Text -> Inline) -> [Text] -> [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> [Text]
shrinkText Text
s
  shrink (Link Attr
attr [Inline]
ils (Text, Text)
target) = [Attr -> [Inline] -> (Text, Text) -> Inline
Link Attr
attr [Inline]
ils' (Text, Text)
target | [Inline]
ils' <- [Inline] -> [[Inline]]
shrinkInlineList [Inline]
ils]
                               [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ [Attr -> [Inline] -> (Text, Text) -> Inline
Link Attr
attr [Inline]
ils (Text, Text)
target' | (Text, Text)
target' <- (Text, Text) -> [(Text, Text)]
shrinkText2 (Text, Text)
target]
                               [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ [Attr -> [Inline] -> (Text, Text) -> Inline
Link Attr
attr' [Inline]
ils (Text, Text)
target | Attr
attr' <- Attr -> [Attr]
shrinkAttr Attr
attr]
  shrink (Image Attr
attr [Inline]
ils (Text, Text)
target) = [Attr -> [Inline] -> (Text, Text) -> Inline
Image Attr
attr [Inline]
ils' (Text, Text)
target | [Inline]
ils' <- [Inline] -> [[Inline]]
shrinkInlineList [Inline]
ils]
                                [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ [Attr -> [Inline] -> (Text, Text) -> Inline
Image Attr
attr [Inline]
ils (Text, Text)
target' | (Text, Text)
target' <- (Text, Text) -> [(Text, Text)]
shrinkText2 (Text, Text)
target]
                                [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ [Attr -> [Inline] -> (Text, Text) -> Inline
Image Attr
attr' [Inline]
ils (Text, Text)
target | Attr
attr' <- Attr -> [Attr]
shrinkAttr Attr
attr]
  shrink (Note [Block]
blks) = [Block] -> Inline
Note ([Block] -> Inline) -> [[Block]] -> [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Block] -> [[Block]]
shrinkBlockList [Block]
blks
  shrink (Span Attr
attr [Inline]
s) = (Attr -> [Inline] -> Inline
Span Attr
attr ([Inline] -> Inline) -> [[Inline]] -> [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Inline] -> [[Inline]]
forall a. Arbitrary a => a -> [a]
shrink [Inline]
s)
                      [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ ((Attr -> [Inline] -> Inline) -> [Inline] -> Attr -> Inline
forall a b c. (a -> b -> c) -> b -> a -> c
flip Attr -> [Inline] -> Inline
Span [Inline]
s (Attr -> Inline) -> [Attr] -> [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Attr -> [Attr]
shrinkAttr Attr
attr)

arbInlines :: Int -> Gen [Inline]
arbInlines :: Int -> Gen [Inline]
arbInlines Int
n = Gen Inline -> Gen [Inline]
forall a. Gen a -> Gen [a]
listOf1 (Int -> Gen Inline
arbInline Int
n) Gen [Inline] -> ([Inline] -> Bool) -> Gen [Inline]
forall a. Gen a -> (a -> Bool) -> Gen a
`suchThat` (Bool -> Bool
not (Bool -> Bool) -> ([Inline] -> Bool) -> [Inline] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inline] -> Bool
startsWithSpace)
  where startsWithSpace :: [Inline] -> Bool
startsWithSpace (Inline
Space:[Inline]
_)     = Bool
True
        startsWithSpace (Inline
SoftBreak:[Inline]
_) = Bool
True
        -- Note: no LineBreak, similarly to Text.Pandoc.Builder (trimInlines)
        startsWithSpace [Inline]
_             = Bool
False

-- restrict to 3 levels of nesting max; otherwise we get
-- bogged down in indefinitely large structures
arbInline :: Int -> Gen Inline
arbInline :: Int -> Gen Inline
arbInline Int
n = [(Int, Gen Inline)] -> Gen Inline
forall a. [(Int, Gen a)] -> Gen a
frequency ([(Int, Gen Inline)] -> Gen Inline)
-> [(Int, Gen Inline)] -> Gen Inline
forall a b. (a -> b) -> a -> b
$ [ (Int
60, Text -> Inline
Str (Text -> Inline) -> Gen Text -> Gen Inline
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Text
realString)
                          , (Int
40, Inline -> Gen Inline
forall (f :: * -> *) a. Applicative f => a -> f a
pure Inline
Space)
                          , (Int
10, Inline -> Gen Inline
forall (f :: * -> *) a. Applicative f => a -> f a
pure Inline
SoftBreak)
                          , (Int
10, Inline -> Gen Inline
forall (f :: * -> *) a. Applicative f => a -> f a
pure Inline
LineBreak)
                          , (Int
10, Attr -> Text -> Inline
Code (Attr -> Text -> Inline) -> Gen Attr -> Gen (Text -> Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Attr
arbAttr Gen (Text -> Inline) -> Gen Text -> Gen Inline
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Text
realString)
                          , (Int
5,  [Inline] -> Gen Inline
forall a. [a] -> Gen a
elements [ Format -> Text -> Inline
RawInline (Text -> Format
Format Text
"html") Text
"<a id=\"eek\">"
                                          , Format -> Text -> Inline
RawInline (Text -> Format
Format Text
"latex") Text
"\\my{command}" ])
                          ] [(Int, Gen Inline)] -> [(Int, Gen Inline)] -> [(Int, Gen Inline)]
forall a. [a] -> [a] -> [a]
++ [ (Int, Gen Inline)
x | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1, (Int, Gen Inline)
x <- [(Int, Gen Inline)]
nesters]
   where nesters :: [(Int, Gen Inline)]
nesters = [ (Int
10, [Inline] -> Inline
Emph ([Inline] -> Inline) -> Gen [Inline] -> Gen Inline
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen [Inline]
arbInlines (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1))
                   , (Int
10, [Inline] -> Inline
Underline ([Inline] -> Inline) -> Gen [Inline] -> Gen Inline
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen [Inline]
arbInlines (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1))
                   , (Int
10, [Inline] -> Inline
Strong ([Inline] -> Inline) -> Gen [Inline] -> Gen Inline
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen [Inline]
arbInlines (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1))
                   , (Int
10, [Inline] -> Inline
Strikeout ([Inline] -> Inline) -> Gen [Inline] -> Gen Inline
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen [Inline]
arbInlines (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1))
                   , (Int
10, [Inline] -> Inline
Superscript ([Inline] -> Inline) -> Gen [Inline] -> Gen Inline
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen [Inline]
arbInlines (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1))
                   , (Int
10, [Inline] -> Inline
Subscript ([Inline] -> Inline) -> Gen [Inline] -> Gen Inline
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen [Inline]
arbInlines (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1))
                   , (Int
10, [Inline] -> Inline
SmallCaps ([Inline] -> Inline) -> Gen [Inline] -> Gen Inline
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen [Inline]
arbInlines (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1))
                   , (Int
10, Attr -> [Inline] -> Inline
Span (Attr -> [Inline] -> Inline)
-> Gen Attr -> Gen ([Inline] -> Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Attr
arbAttr Gen ([Inline] -> Inline) -> Gen [Inline] -> Gen Inline
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Gen [Inline]
arbInlines (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1))
                   , (Int
10, QuoteType -> [Inline] -> Inline
Quoted (QuoteType -> [Inline] -> Inline)
-> Gen QuoteType -> Gen ([Inline] -> Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen QuoteType
forall a. Arbitrary a => Gen a
arbitrary Gen ([Inline] -> Inline) -> Gen [Inline] -> Gen Inline
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Gen [Inline]
arbInlines (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1))
                   , (Int
10, MathType -> Text -> Inline
Math (MathType -> Text -> Inline)
-> Gen MathType -> Gen (Text -> Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen MathType
forall a. Arbitrary a => Gen a
arbitrary Gen (Text -> Inline) -> Gen Text -> Gen Inline
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Text
realString)
                   , (Int
10, Attr -> [Inline] -> (Text, Text) -> Inline
Link (Attr -> [Inline] -> (Text, Text) -> Inline)
-> Gen Attr -> Gen ([Inline] -> (Text, Text) -> Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Attr
arbAttr Gen ([Inline] -> (Text, Text) -> Inline)
-> Gen [Inline] -> Gen ((Text, Text) -> Inline)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Gen [Inline]
arbInlines (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) Gen ((Text, Text) -> Inline) -> Gen (Text, Text) -> Gen Inline
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((,) (Text -> Text -> (Text, Text))
-> Gen Text -> Gen (Text -> (Text, Text))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Text
realString Gen (Text -> (Text, Text)) -> Gen Text -> Gen (Text, Text)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Text
realString))
                   , (Int
10, Attr -> [Inline] -> (Text, Text) -> Inline
Image (Attr -> [Inline] -> (Text, Text) -> Inline)
-> Gen Attr -> Gen ([Inline] -> (Text, Text) -> Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Attr
arbAttr Gen ([Inline] -> (Text, Text) -> Inline)
-> Gen [Inline] -> Gen ((Text, Text) -> Inline)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Gen [Inline]
arbInlines (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) Gen ((Text, Text) -> Inline) -> Gen (Text, Text) -> Gen Inline
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((,) (Text -> Text -> (Text, Text))
-> Gen Text -> Gen (Text -> (Text, Text))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Text
realString Gen (Text -> (Text, Text)) -> Gen Text -> Gen (Text, Text)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Text
realString))
                   , (Int
2,  [Citation] -> [Inline] -> Inline
Cite ([Citation] -> [Inline] -> Inline)
-> Gen [Citation] -> Gen ([Inline] -> Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [Citation]
forall a. Arbitrary a => Gen a
arbitrary Gen ([Inline] -> Inline) -> Gen [Inline] -> Gen Inline
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Gen [Inline]
arbInlines Int
1)
                   , (Int
2,  [Block] -> Inline
Note ([Block] -> Inline) -> Gen [Block] -> Gen Inline
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen [Block] -> Gen [Block]
forall a. Int -> Gen a -> Gen a
resize Int
3 (Gen Block -> Gen [Block]
forall a. Gen a -> Gen [a]
listOf1 (Gen Block -> Gen [Block]) -> Gen Block -> Gen [Block]
forall a b. (a -> b) -> a -> b
$ Int -> Gen Block
arbBlock (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1)))
                   ]

instance Arbitrary Block where
  arbitrary :: Gen Block
arbitrary = Int -> Gen Block -> Gen Block
forall a. Int -> Gen a -> Gen a
resize Int
3 (Gen Block -> Gen Block) -> Gen Block -> Gen Block
forall a b. (a -> b) -> a -> b
$ Int -> Gen Block
arbBlock Int
2
  shrink :: Block -> [Block]
shrink (Plain [Inline]
ils) = [Inline] -> Block
Plain ([Inline] -> Block) -> [[Inline]] -> [Block]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Inline] -> [[Inline]]
shrinkInlineList [Inline]
ils
  shrink (Para [Inline]
ils) = [Inline] -> Block
Para ([Inline] -> Block) -> [[Inline]] -> [Block]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Inline] -> [[Inline]]
shrinkInlineList [Inline]
ils
  shrink (LineBlock [[Inline]]
lns) = [[Inline]] -> Block
LineBlock ([[Inline]] -> Block) -> [[[Inline]]] -> [Block]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [[Inline]] -> [[[Inline]]]
shrinkInlinesList [[Inline]]
lns
  shrink (CodeBlock Attr
attr Text
s) = (Attr -> Text -> Block
CodeBlock Attr
attr (Text -> Block) -> [Text] -> [Block]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> [Text]
shrinkText Text
s)
                           [Block] -> [Block] -> [Block]
forall a. [a] -> [a] -> [a]
++ ((Attr -> Text -> Block) -> Text -> Attr -> Block
forall a b c. (a -> b -> c) -> b -> a -> c
flip Attr -> Text -> Block
CodeBlock Text
s (Attr -> Block) -> [Attr] -> [Block]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Attr -> [Attr]
shrinkAttr Attr
attr)
  shrink (RawBlock Format
fmt Text
s) = Format -> Text -> Block
RawBlock Format
fmt (Text -> Block) -> [Text] -> [Block]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> [Text]
shrinkText Text
s
  shrink (BlockQuote [Block]
blks) = [Block] -> Block
BlockQuote ([Block] -> Block) -> [[Block]] -> [Block]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Block] -> [[Block]]
shrinkBlockList [Block]
blks
  shrink (OrderedList ListAttributes
listAttrs [[Block]]
blksList) = ListAttributes -> [[Block]] -> Block
OrderedList ListAttributes
listAttrs ([[Block]] -> Block) -> [[[Block]]] -> [Block]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [[Block]] -> [[[Block]]]
shrinkBlocksList [[Block]]
blksList
  shrink (BulletList [[Block]]
blksList) = [[Block]] -> Block
BulletList ([[Block]] -> Block) -> [[[Block]]] -> [Block]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [[Block]] -> [[[Block]]]
shrinkBlocksList [[Block]]
blksList
  shrink (DefinitionList [([Inline], [[Block]])]
defs) = [([Inline], [[Block]])] -> Block
DefinitionList ([([Inline], [[Block]])] -> Block)
-> [[([Inline], [[Block]])]] -> [Block]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [([Inline], [[Block]])] -> [[([Inline], [[Block]])]]
shrinkDefinitionList [([Inline], [[Block]])]
defs
    where shrinkDefinition :: ([Inline], [[Block]]) -> [([Inline], [[Block]])]
shrinkDefinition ([Inline]
ils, [[Block]]
blksList) = [([Inline]
ils', [[Block]]
blksList) | [Inline]
ils' <- [Inline] -> [[Inline]]
shrinkInlineList [Inline]
ils]
                                          [([Inline], [[Block]])]
-> [([Inline], [[Block]])] -> [([Inline], [[Block]])]
forall a. [a] -> [a] -> [a]
++ [([Inline]
ils, [[Block]]
blksList') | [[Block]]
blksList' <- [[Block]] -> [[[Block]]]
shrinkBlocksList [[Block]]
blksList]
          shrinkDefinitionList :: [([Inline], [[Block]])] -> [[([Inline], [[Block]])]]
shrinkDefinitionList (([Inline], [[Block]])
x:[([Inline], [[Block]])]
xs) = [[([Inline], [[Block]])]
xs]
                                     [[([Inline], [[Block]])]]
-> [[([Inline], [[Block]])]] -> [[([Inline], [[Block]])]]
forall a. [a] -> [a] -> [a]
++ [([Inline], [[Block]])
x'([Inline], [[Block]])
-> [([Inline], [[Block]])] -> [([Inline], [[Block]])]
forall a. a -> [a] -> [a]
:[([Inline], [[Block]])]
xs | ([Inline], [[Block]])
x' <- ([Inline], [[Block]]) -> [([Inline], [[Block]])]
shrinkDefinition ([Inline], [[Block]])
x]
                                     [[([Inline], [[Block]])]]
-> [[([Inline], [[Block]])]] -> [[([Inline], [[Block]])]]
forall a. [a] -> [a] -> [a]
++ [([Inline], [[Block]])
x([Inline], [[Block]])
-> [([Inline], [[Block]])] -> [([Inline], [[Block]])]
forall a. a -> [a] -> [a]
:[([Inline], [[Block]])]
xs' | [([Inline], [[Block]])]
xs' <- [([Inline], [[Block]])] -> [[([Inline], [[Block]])]]
shrinkDefinitionList [([Inline], [[Block]])]
xs]
          shrinkDefinitionList [] = []
  shrink (Header Int
n Attr
attr [Inline]
ils) = (Int -> Attr -> [Inline] -> Block
Header Int
n Attr
attr ([Inline] -> Block) -> [[Inline]] -> [Block]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Inline] -> [[Inline]]
shrinkInlineList [Inline]
ils)
                            [Block] -> [Block] -> [Block]
forall a. [a] -> [a] -> [a]
++ ((Attr -> [Inline] -> Block) -> [Inline] -> Attr -> Block
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Int -> Attr -> [Inline] -> Block
Header Int
n) [Inline]
ils (Attr -> Block) -> [Attr] -> [Block]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Attr -> [Attr]
shrinkAttr Attr
attr)
  shrink Block
HorizontalRule = []
  shrink (Table Attr
attr Caption
capt [ColSpec]
specs TableHead
thead [TableBody]
tbody TableFoot
tfoot) =
    -- TODO: shrink number of columns
    [Attr
-> Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> Block
Table Attr
attr' Caption
capt [ColSpec]
specs TableHead
thead [TableBody]
tbody TableFoot
tfoot | Attr
attr' <- Attr -> [Attr]
shrinkAttr Attr
attr] [Block] -> [Block] -> [Block]
forall a. [a] -> [a] -> [a]
++
    [Attr
-> Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> Block
Table Attr
attr Caption
capt [ColSpec]
specs TableHead
thead' [TableBody]
tbody TableFoot
tfoot | TableHead
thead' <- TableHead -> [TableHead]
forall a. Arbitrary a => a -> [a]
shrink TableHead
thead] [Block] -> [Block] -> [Block]
forall a. [a] -> [a] -> [a]
++
    [Attr
-> Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> Block
Table Attr
attr Caption
capt [ColSpec]
specs TableHead
thead [TableBody]
tbody' TableFoot
tfoot | [TableBody]
tbody' <- [TableBody] -> [[TableBody]]
forall a. Arbitrary a => a -> [a]
shrink [TableBody]
tbody] [Block] -> [Block] -> [Block]
forall a. [a] -> [a] -> [a]
++
    [Attr
-> Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> Block
Table Attr
attr Caption
capt [ColSpec]
specs TableHead
thead [TableBody]
tbody TableFoot
tfoot' | TableFoot
tfoot' <- TableFoot -> [TableFoot]
forall a. Arbitrary a => a -> [a]
shrink TableFoot
tfoot] [Block] -> [Block] -> [Block]
forall a. [a] -> [a] -> [a]
++
    [Attr
-> Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> Block
Table Attr
attr Caption
capt' [ColSpec]
specs TableHead
thead [TableBody]
tbody TableFoot
tfoot | Caption
capt' <- Caption -> [Caption]
forall a. Arbitrary a => a -> [a]
shrink Caption
capt]
  shrink (Div Attr
attr [Block]
blks) = (Attr -> [Block] -> Block
Div Attr
attr ([Block] -> Block) -> [[Block]] -> [Block]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Block] -> [[Block]]
shrinkBlockList [Block]
blks)
                        [Block] -> [Block] -> [Block]
forall a. [a] -> [a] -> [a]
++ ((Attr -> [Block] -> Block) -> [Block] -> Attr -> Block
forall a b c. (a -> b -> c) -> b -> a -> c
flip Attr -> [Block] -> Block
Div [Block]
blks (Attr -> Block) -> [Attr] -> [Block]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Attr -> [Attr]
shrinkAttr Attr
attr)
  shrink Block
Null = []

arbBlock :: Int -> Gen Block
arbBlock :: Int -> Gen Block
arbBlock Int
n = [(Int, Gen Block)] -> Gen Block
forall a. [(Int, Gen a)] -> Gen a
frequency ([(Int, Gen Block)] -> Gen Block)
-> [(Int, Gen Block)] -> Gen Block
forall a b. (a -> b) -> a -> b
$ [ (Int
10, [Inline] -> Block
Plain ([Inline] -> Block) -> Gen [Inline] -> Gen Block
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen [Inline]
arbInlines (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1))
                         , (Int
15, [Inline] -> Block
Para ([Inline] -> Block) -> Gen [Inline] -> Gen Block
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen [Inline]
arbInlines (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1))
                         , (Int
5,  Attr -> Text -> Block
CodeBlock (Attr -> Text -> Block) -> Gen Attr -> Gen (Text -> Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Attr
arbAttr Gen (Text -> Block) -> Gen Text -> Gen Block
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Text
realString)
                         , (Int
3,  [[Inline]] -> Block
LineBlock ([[Inline]] -> Block) -> Gen [[Inline]] -> Gen Block
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
                                ((:) ([Inline] -> [[Inline]] -> [[Inline]])
-> Gen [Inline] -> Gen ([[Inline]] -> [[Inline]])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
                                  Int -> Gen [Inline]
arbInlines ((Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
3) Gen ([[Inline]] -> [[Inline]]) -> Gen [[Inline]] -> Gen [[Inline]]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
                                  [Int] -> (Int -> Gen [Inline]) -> Gen [[Inline]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [Int
1..((Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
3)] (Gen [Inline] -> Int -> Gen [Inline]
forall a b. a -> b -> a
const (Int -> Gen [Inline]
arbInlines Int
3))))
                         , (Int
2,  [Block] -> Gen Block
forall a. [a] -> Gen a
elements [ Format -> Text -> Block
RawBlock (Text -> Format
Format Text
"html")
                                            Text
"<div>\n*&amp;*\n</div>"
                                         , Format -> Text -> Block
RawBlock (Text -> Format
Format Text
"latex")
                                            Text
"\\begin[opt]{env}\nhi\n{\\end{env}"
                                         ])
                         , (Int
5,  Int -> Attr -> [Inline] -> Block
Header (Int -> Attr -> [Inline] -> Block)
-> Gen Int -> Gen (Attr -> [Inline] -> Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
1 :: Int, Int
6)
                                       Gen (Attr -> [Inline] -> Block)
-> Gen Attr -> Gen ([Inline] -> Block)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Attr -> Gen Attr
forall (f :: * -> *) a. Applicative f => a -> f a
pure Attr
nullAttr
                                       Gen ([Inline] -> Block) -> Gen [Inline] -> Gen Block
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Gen [Inline]
arbInlines (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1))
                         , (Int
2,  Block -> Gen Block
forall (f :: * -> *) a. Applicative f => a -> f a
pure Block
HorizontalRule)
                         ] [(Int, Gen Block)] -> [(Int, Gen Block)] -> [(Int, Gen Block)]
forall a. [a] -> [a] -> [a]
++ [(Int, Gen Block)
x | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0, (Int, Gen Block)
x <- [(Int, Gen Block)]
nesters]
   where nesters :: [(Int, Gen Block)]
nesters = [ (Int
5, [Block] -> Block
BlockQuote ([Block] -> Block) -> Gen [Block] -> Gen Block
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Block -> Gen [Block]
forall a. Gen a -> Gen [a]
listOf1 (Int -> Gen Block
arbBlock (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1)))
                   , (Int
5, ListAttributes -> [[Block]] -> Block
OrderedList (ListAttributes -> [[Block]] -> Block)
-> Gen ListAttributes -> Gen ([[Block]] -> Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((,,) (Int -> ListNumberStyle -> ListNumberDelim -> ListAttributes)
-> Gen Int
-> Gen (ListNumberStyle -> ListNumberDelim -> ListAttributes)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Gen Int
forall a. Arbitrary a => Gen a
arbitrary Gen Int -> (Int -> Bool) -> Gen Int
forall a. Gen a -> (a -> Bool) -> Gen a
`suchThat` (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0))
                                                Gen (ListNumberStyle -> ListNumberDelim -> ListAttributes)
-> Gen ListNumberStyle -> Gen (ListNumberDelim -> ListAttributes)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ListNumberStyle
forall a. Arbitrary a => Gen a
arbitrary
                                                Gen (ListNumberDelim -> ListAttributes)
-> Gen ListNumberDelim -> Gen ListAttributes
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ListNumberDelim
forall a. Arbitrary a => Gen a
arbitrary)
                                      Gen ([[Block]] -> Block) -> Gen [[Block]] -> Gen Block
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen [Block] -> Gen [[Block]]
forall a. Gen a -> Gen [a]
listOf1 (Gen Block -> Gen [Block]
forall a. Gen a -> Gen [a]
listOf1 (Gen Block -> Gen [Block]) -> Gen Block -> Gen [Block]
forall a b. (a -> b) -> a -> b
$ Int -> Gen Block
arbBlock (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1)))
                   , (Int
5, [[Block]] -> Block
BulletList ([[Block]] -> Block) -> Gen [[Block]] -> Gen Block
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [Block] -> Gen [[Block]]
forall a. Gen a -> Gen [a]
listOf1 (Gen Block -> Gen [Block]
forall a. Gen a -> Gen [a]
listOf1 (Gen Block -> Gen [Block]) -> Gen Block -> Gen [Block]
forall a b. (a -> b) -> a -> b
$ Int -> Gen Block
arbBlock (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1)))
                   , (Int
5, [([Inline], [[Block]])] -> Block
DefinitionList ([([Inline], [[Block]])] -> Block)
-> Gen [([Inline], [[Block]])] -> Gen Block
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ([Inline], [[Block]]) -> Gen [([Inline], [[Block]])]
forall a. Gen a -> Gen [a]
listOf1 ((,) ([Inline] -> [[Block]] -> ([Inline], [[Block]]))
-> Gen [Inline] -> Gen ([[Block]] -> ([Inline], [[Block]]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Gen [Inline]
arbInlines (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1)
                                                          Gen ([[Block]] -> ([Inline], [[Block]]))
-> Gen [[Block]] -> Gen ([Inline], [[Block]])
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen [Block] -> Gen [[Block]]
forall a. Gen a -> Gen [a]
listOf1 (Gen Block -> Gen [Block]
forall a. Gen a -> Gen [a]
listOf1 (Gen Block -> Gen [Block]) -> Gen Block -> Gen [Block]
forall a b. (a -> b) -> a -> b
$ Int -> Gen Block
arbBlock (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1))))
                   , (Int
5, Attr -> [Block] -> Block
Div (Attr -> [Block] -> Block) -> Gen Attr -> Gen ([Block] -> Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Attr
arbAttr Gen ([Block] -> Block) -> Gen [Block] -> Gen Block
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Block -> Gen [Block]
forall a. Gen a -> Gen [a]
listOf1 (Int -> Gen Block
arbBlock (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1)))
                   , (Int
2, do Int
cs <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
1 :: Int, Int
6)
                            Int
bs <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0 :: Int, Int
2)
                            Attr
-> Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> Block
Table (Attr
 -> Caption
 -> [ColSpec]
 -> TableHead
 -> [TableBody]
 -> TableFoot
 -> Block)
-> Gen Attr
-> Gen
     (Caption
      -> [ColSpec] -> TableHead -> [TableBody] -> TableFoot -> Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Attr
arbAttr
                                  Gen
  (Caption
   -> [ColSpec] -> TableHead -> [TableBody] -> TableFoot -> Block)
-> Gen Caption
-> Gen
     ([ColSpec] -> TableHead -> [TableBody] -> TableFoot -> Block)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Caption
forall a. Arbitrary a => Gen a
arbitrary
                                  Gen ([ColSpec] -> TableHead -> [TableBody] -> TableFoot -> Block)
-> Gen [ColSpec]
-> Gen (TableHead -> [TableBody] -> TableFoot -> Block)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Gen ColSpec -> Gen [ColSpec]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
cs ((,) (Alignment -> ColWidth -> ColSpec)
-> Gen Alignment -> Gen (ColWidth -> ColSpec)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Alignment
forall a. Arbitrary a => Gen a
arbitrary
                                                       Gen (ColWidth -> ColSpec) -> Gen ColWidth -> Gen ColSpec
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [ColWidth] -> Gen ColWidth
forall a. [a] -> Gen a
elements [ ColWidth
ColWidthDefault
                                                                    , Double -> ColWidth
ColWidth (Double
1Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/Double
3)
                                                                    , Double -> ColWidth
ColWidth Double
0.25 ])
                                  Gen (TableHead -> [TableBody] -> TableFoot -> Block)
-> Gen TableHead -> Gen ([TableBody] -> TableFoot -> Block)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Gen TableHead
arbTableHead (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1)
                                  Gen ([TableBody] -> TableFoot -> Block)
-> Gen [TableBody] -> Gen (TableFoot -> Block)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Gen TableBody -> Gen [TableBody]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
bs (Int -> Gen TableBody
arbTableBody (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1))
                                  Gen (TableFoot -> Block) -> Gen TableFoot -> Gen Block
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Gen TableFoot
arbTableFoot (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1))
                   ]

arbRow :: Int -> Gen Row
arbRow :: Int -> Gen Row
arbRow Int
n = do
  Int
cs <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0, Int
5)
  Attr -> [Cell] -> Row
Row (Attr -> [Cell] -> Row) -> Gen Attr -> Gen ([Cell] -> Row)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Attr
arbAttr Gen ([Cell] -> Row) -> Gen [Cell] -> Gen Row
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Gen Cell -> Gen [Cell]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
cs (Int -> Gen Cell
arbCell Int
n)

arbTableHead :: Int -> Gen TableHead
arbTableHead :: Int -> Gen TableHead
arbTableHead Int
n = do
  Int
rs <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0, Int
5)
  Attr -> [Row] -> TableHead
TableHead (Attr -> [Row] -> TableHead)
-> Gen Attr -> Gen ([Row] -> TableHead)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Attr
arbAttr Gen ([Row] -> TableHead) -> Gen [Row] -> Gen TableHead
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Gen Row -> Gen [Row]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
rs (Int -> Gen Row
arbRow Int
n)

arbTableBody :: Int -> Gen TableBody
arbTableBody :: Int -> Gen TableBody
arbTableBody Int
n = do
  Int
hrs <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0 :: Int, Int
2)
  Int
rs <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0, Int
5)
  Int
rhc <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0, Int
5)
  Attr -> RowHeadColumns -> [Row] -> [Row] -> TableBody
TableBody (Attr -> RowHeadColumns -> [Row] -> [Row] -> TableBody)
-> Gen Attr -> Gen (RowHeadColumns -> [Row] -> [Row] -> TableBody)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Attr
arbAttr
            Gen (RowHeadColumns -> [Row] -> [Row] -> TableBody)
-> Gen RowHeadColumns -> Gen ([Row] -> [Row] -> TableBody)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RowHeadColumns -> Gen RowHeadColumns
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int -> RowHeadColumns
RowHeadColumns Int
rhc)
            Gen ([Row] -> [Row] -> TableBody)
-> Gen [Row] -> Gen ([Row] -> TableBody)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Gen Row -> Gen [Row]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
hrs (Int -> Gen Row
arbRow Int
n)
            Gen ([Row] -> TableBody) -> Gen [Row] -> Gen TableBody
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Gen Row -> Gen [Row]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
rs (Int -> Gen Row
arbRow Int
n)

arbTableFoot :: Int -> Gen TableFoot
arbTableFoot :: Int -> Gen TableFoot
arbTableFoot Int
n = do
    Int
rs <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0, Int
5)
    Attr -> [Row] -> TableFoot
TableFoot (Attr -> [Row] -> TableFoot)
-> Gen Attr -> Gen ([Row] -> TableFoot)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Attr
arbAttr Gen ([Row] -> TableFoot) -> Gen [Row] -> Gen TableFoot
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Gen Row -> Gen [Row]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
rs (Int -> Gen Row
arbRow Int
n)

arbCell :: Int -> Gen Cell
arbCell :: Int -> Gen Cell
arbCell Int
n = Attr -> Alignment -> RowSpan -> ColSpan -> [Block] -> Cell
Cell (Attr -> Alignment -> RowSpan -> ColSpan -> [Block] -> Cell)
-> Gen Attr
-> Gen (Alignment -> RowSpan -> ColSpan -> [Block] -> Cell)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Attr
arbAttr
                 Gen (Alignment -> RowSpan -> ColSpan -> [Block] -> Cell)
-> Gen Alignment -> Gen (RowSpan -> ColSpan -> [Block] -> Cell)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Alignment
forall a. Arbitrary a => Gen a
arbitrary
                 Gen (RowSpan -> ColSpan -> [Block] -> Cell)
-> Gen RowSpan -> Gen (ColSpan -> [Block] -> Cell)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Int -> RowSpan
RowSpan (Int -> RowSpan) -> Gen Int -> Gen RowSpan
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
1 :: Int, Int
2))
                 Gen (ColSpan -> [Block] -> Cell)
-> Gen ColSpan -> Gen ([Block] -> Cell)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Int -> ColSpan
ColSpan (Int -> ColSpan) -> Gen Int -> Gen ColSpan
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
1 :: Int, Int
2))
                 Gen ([Block] -> Cell) -> Gen [Block] -> Gen Cell
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Block -> Gen [Block]
forall a. Gen a -> Gen [a]
listOf (Int -> Gen Block
arbBlock Int
n)

instance Arbitrary Pandoc where
        arbitrary :: Gen Pandoc
arbitrary = Int -> Gen Pandoc -> Gen Pandoc
forall a. Int -> Gen a -> Gen a
resize Int
8 (Meta -> [Block] -> Pandoc
Pandoc (Meta -> [Block] -> Pandoc) -> Gen Meta -> Gen ([Block] -> Pandoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Meta
forall a. Arbitrary a => Gen a
arbitrary Gen ([Block] -> Pandoc) -> Gen [Block] -> Gen Pandoc
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen [Block]
forall a. Arbitrary a => Gen a
arbitrary)

instance Arbitrary CitationMode where
        arbitrary :: Gen CitationMode
arbitrary
          = do Int
x <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0 :: Int, Int
2)
               case Int
x of
                   Int
0 -> CitationMode -> Gen CitationMode
forall (m :: * -> *) a. Monad m => a -> m a
return CitationMode
AuthorInText
                   Int
1 -> CitationMode -> Gen CitationMode
forall (m :: * -> *) a. Monad m => a -> m a
return CitationMode
SuppressAuthor
                   Int
2 -> CitationMode -> Gen CitationMode
forall (m :: * -> *) a. Monad m => a -> m a
return CitationMode
NormalCitation
                   Int
_ -> String -> Gen CitationMode
forall a. HasCallStack => String -> a
error String
"FATAL ERROR: Arbitrary instance, logic bug"

instance Arbitrary Citation where
        arbitrary :: Gen Citation
arbitrary
          = Text
-> [Inline] -> [Inline] -> CitationMode -> Int -> Int -> Citation
Citation (Text
 -> [Inline] -> [Inline] -> CitationMode -> Int -> Int -> Citation)
-> Gen Text
-> Gen
     ([Inline] -> [Inline] -> CitationMode -> Int -> Int -> Citation)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Text) -> Gen String -> Gen Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Text
T.pack (Gen Char -> Gen String
forall a. Gen a -> Gen [a]
listOf (Gen Char -> Gen String) -> Gen Char -> Gen String
forall a b. (a -> b) -> a -> b
$ String -> Gen Char
forall a. [a] -> Gen a
elements (String -> Gen Char) -> String -> Gen Char
forall a b. (a -> b) -> a -> b
$ [Char
'a'..Char
'z'] String -> String -> String
forall a. [a] -> [a] -> [a]
++ [Char
'0'..Char
'9'] String -> String -> String
forall a. [a] -> [a] -> [a]
++ [Char
'_'])
                     Gen
  ([Inline] -> [Inline] -> CitationMode -> Int -> Int -> Citation)
-> Gen [Inline]
-> Gen ([Inline] -> CitationMode -> Int -> Int -> Citation)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Gen [Inline]
arbInlines Int
1
                     Gen ([Inline] -> CitationMode -> Int -> Int -> Citation)
-> Gen [Inline] -> Gen (CitationMode -> Int -> Int -> Citation)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Gen [Inline]
arbInlines Int
1
                     Gen (CitationMode -> Int -> Int -> Citation)
-> Gen CitationMode -> Gen (Int -> Int -> Citation)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen CitationMode
forall a. Arbitrary a => Gen a
arbitrary
                     Gen (Int -> Int -> Citation) -> Gen Int -> Gen (Int -> Citation)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Int
forall a. Arbitrary a => Gen a
arbitrary
                     Gen (Int -> Citation) -> Gen Int -> Gen Citation
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Int
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary Row where
  arbitrary :: Gen Row
arbitrary = Int -> Gen Row -> Gen Row
forall a. Int -> Gen a -> Gen a
resize Int
3 (Gen Row -> Gen Row) -> Gen Row -> Gen Row
forall a b. (a -> b) -> a -> b
$ Int -> Gen Row
arbRow Int
2
  shrink :: Row -> [Row]
shrink (Row Attr
attr [Cell]
body)
    = [Attr -> [Cell] -> Row
Row Attr
attr' [Cell]
body | Attr
attr' <- Attr -> [Attr]
shrinkAttr Attr
attr] [Row] -> [Row] -> [Row]
forall a. [a] -> [a] -> [a]
++
      [Attr -> [Cell] -> Row
Row Attr
attr [Cell]
body' | [Cell]
body' <- [Cell] -> [[Cell]]
forall a. Arbitrary a => a -> [a]
shrink [Cell]
body]

instance Arbitrary TableHead where
  arbitrary :: Gen TableHead
arbitrary = Int -> Gen TableHead -> Gen TableHead
forall a. Int -> Gen a -> Gen a
resize Int
3 (Gen TableHead -> Gen TableHead) -> Gen TableHead -> Gen TableHead
forall a b. (a -> b) -> a -> b
$ Int -> Gen TableHead
arbTableHead Int
2
  shrink :: TableHead -> [TableHead]
shrink (TableHead Attr
attr [Row]
body)
    = [Attr -> [Row] -> TableHead
TableHead Attr
attr' [Row]
body | Attr
attr' <- Attr -> [Attr]
shrinkAttr Attr
attr] [TableHead] -> [TableHead] -> [TableHead]
forall a. [a] -> [a] -> [a]
++
      [Attr -> [Row] -> TableHead
TableHead Attr
attr [Row]
body' | [Row]
body' <- [Row] -> [[Row]]
forall a. Arbitrary a => a -> [a]
shrink [Row]
body]

instance Arbitrary TableBody where
  arbitrary :: Gen TableBody
arbitrary = Int -> Gen TableBody -> Gen TableBody
forall a. Int -> Gen a -> Gen a
resize Int
3 (Gen TableBody -> Gen TableBody) -> Gen TableBody -> Gen TableBody
forall a b. (a -> b) -> a -> b
$ Int -> Gen TableBody
arbTableBody Int
2
  -- TODO: shrink rhc?
  shrink :: TableBody -> [TableBody]
shrink (TableBody Attr
attr RowHeadColumns
rhc [Row]
hd [Row]
bd)
    = [Attr -> RowHeadColumns -> [Row] -> [Row] -> TableBody
TableBody Attr
attr' RowHeadColumns
rhc [Row]
hd [Row]
bd | Attr
attr' <- Attr -> [Attr]
shrinkAttr Attr
attr] [TableBody] -> [TableBody] -> [TableBody]
forall a. [a] -> [a] -> [a]
++
      [Attr -> RowHeadColumns -> [Row] -> [Row] -> TableBody
TableBody Attr
attr RowHeadColumns
rhc [Row]
hd' [Row]
bd | [Row]
hd' <- [Row] -> [[Row]]
forall a. Arbitrary a => a -> [a]
shrink [Row]
hd] [TableBody] -> [TableBody] -> [TableBody]
forall a. [a] -> [a] -> [a]
++
      [Attr -> RowHeadColumns -> [Row] -> [Row] -> TableBody
TableBody Attr
attr RowHeadColumns
rhc [Row]
hd [Row]
bd' | [Row]
bd' <- [Row] -> [[Row]]
forall a. Arbitrary a => a -> [a]
shrink [Row]
bd]

instance Arbitrary TableFoot where
  arbitrary :: Gen TableFoot
arbitrary = Int -> Gen TableFoot -> Gen TableFoot
forall a. Int -> Gen a -> Gen a
resize Int
3 (Gen TableFoot -> Gen TableFoot) -> Gen TableFoot -> Gen TableFoot
forall a b. (a -> b) -> a -> b
$ Int -> Gen TableFoot
arbTableFoot Int
2
  shrink :: TableFoot -> [TableFoot]
shrink (TableFoot Attr
attr [Row]
body)
    = [Attr -> [Row] -> TableFoot
TableFoot Attr
attr' [Row]
body | Attr
attr' <- Attr -> [Attr]
shrinkAttr Attr
attr] [TableFoot] -> [TableFoot] -> [TableFoot]
forall a. [a] -> [a] -> [a]
++
      [Attr -> [Row] -> TableFoot
TableFoot Attr
attr [Row]
body' | [Row]
body' <- [Row] -> [[Row]]
forall a. Arbitrary a => a -> [a]
shrink [Row]
body]

instance Arbitrary Cell where
  arbitrary :: Gen Cell
arbitrary = Int -> Gen Cell -> Gen Cell
forall a. Int -> Gen a -> Gen a
resize Int
3 (Gen Cell -> Gen Cell) -> Gen Cell -> Gen Cell
forall a b. (a -> b) -> a -> b
$ Int -> Gen Cell
arbCell Int
2
  shrink :: Cell -> [Cell]
shrink (Cell Attr
attr Alignment
malign RowSpan
h ColSpan
w [Block]
body)
    = [Attr -> Alignment -> RowSpan -> ColSpan -> [Block] -> Cell
Cell Attr
attr Alignment
malign RowSpan
h ColSpan
w [Block]
body' | [Block]
body' <- [Block] -> [[Block]]
shrinkBlockList [Block]
body] [Cell] -> [Cell] -> [Cell]
forall a. [a] -> [a] -> [a]
++
      [Attr -> Alignment -> RowSpan -> ColSpan -> [Block] -> Cell
Cell Attr
attr' Alignment
malign RowSpan
h ColSpan
w [Block]
body | Attr
attr' <- Attr -> [Attr]
shrinkAttr Attr
attr] [Cell] -> [Cell] -> [Cell]
forall a. [a] -> [a] -> [a]
++
      [Attr -> Alignment -> RowSpan -> ColSpan -> [Block] -> Cell
Cell Attr
attr Alignment
malign' RowSpan
h ColSpan
w [Block]
body | Alignment
malign' <- Alignment -> [Alignment]
forall a. Arbitrary a => a -> [a]
shrink Alignment
malign]

instance Arbitrary Caption where
  arbitrary :: Gen Caption
arbitrary = Maybe [Inline] -> [Block] -> Caption
Caption (Maybe [Inline] -> [Block] -> Caption)
-> Gen (Maybe [Inline]) -> Gen ([Block] -> Caption)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Maybe [Inline])
forall a. Arbitrary a => Gen a
arbitrary Gen ([Block] -> Caption) -> Gen [Block] -> Gen Caption
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen [Block]
forall a. Arbitrary a => Gen a
arbitrary
  shrink :: Caption -> [Caption]
shrink (Caption Maybe [Inline]
mshort [Block]
body)
    = [Maybe [Inline] -> [Block] -> Caption
Caption Maybe [Inline]
mshort' [Block]
body | Maybe [Inline]
mshort' <- Maybe [Inline] -> [Maybe [Inline]]
forall a. Arbitrary a => a -> [a]
shrink Maybe [Inline]
mshort] [Caption] -> [Caption] -> [Caption]
forall a. [a] -> [a] -> [a]
++
      [Maybe [Inline] -> [Block] -> Caption
Caption Maybe [Inline]
mshort [Block]
body' | [Block]
body' <- [Block] -> [[Block]]
shrinkBlockList [Block]
body]

instance Arbitrary MathType where
        arbitrary :: Gen MathType
arbitrary
          = do Int
x <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0 :: Int, Int
1)
               case Int
x of
                   Int
0 -> MathType -> Gen MathType
forall (m :: * -> *) a. Monad m => a -> m a
return MathType
DisplayMath
                   Int
1 -> MathType -> Gen MathType
forall (m :: * -> *) a. Monad m => a -> m a
return MathType
InlineMath
                   Int
_ -> String -> Gen MathType
forall a. HasCallStack => String -> a
error String
"FATAL ERROR: Arbitrary instance, logic bug"

instance Arbitrary QuoteType where
        arbitrary :: Gen QuoteType
arbitrary
          = do Int
x <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0 :: Int, Int
1)
               case Int
x of
                   Int
0 -> QuoteType -> Gen QuoteType
forall (m :: * -> *) a. Monad m => a -> m a
return QuoteType
SingleQuote
                   Int
1 -> QuoteType -> Gen QuoteType
forall (m :: * -> *) a. Monad m => a -> m a
return QuoteType
DoubleQuote
                   Int
_ -> String -> Gen QuoteType
forall a. HasCallStack => String -> a
error String
"FATAL ERROR: Arbitrary instance, logic bug"

instance Arbitrary Meta where
        arbitrary :: Gen Meta
arbitrary
          = do (Inlines
x1 :: Inlines) <- Gen Inlines
forall a. Arbitrary a => Gen a
arbitrary
               ([Inlines]
x2 :: [Inlines]) <- (Inlines -> Bool) -> [Inlines] -> [Inlines]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Inlines -> Bool) -> Inlines -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null) ([Inlines] -> [Inlines]) -> Gen [Inlines] -> Gen [Inlines]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [Inlines]
forall a. Arbitrary a => Gen a
arbitrary
               (Inlines
x3 :: Inlines) <- Gen Inlines
forall a. Arbitrary a => Gen a
arbitrary
               Meta -> Gen Meta
forall (m :: * -> *) a. Monad m => a -> m a
return (Meta -> Gen Meta) -> Meta -> Gen Meta
forall a b. (a -> b) -> a -> b
$ Text -> Inlines -> Meta -> Meta
forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
setMeta Text
"title" Inlines
x1
                      (Meta -> Meta) -> Meta -> Meta
forall a b. (a -> b) -> a -> b
$ Text -> [Inlines] -> Meta -> Meta
forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
setMeta Text
"author" [Inlines]
x2
                      (Meta -> Meta) -> Meta -> Meta
forall a b. (a -> b) -> a -> b
$ Text -> Inlines -> Meta -> Meta
forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
setMeta Text
"date" Inlines
x3
                        Meta
nullMeta

instance Arbitrary Alignment where
        arbitrary :: Gen Alignment
arbitrary
          = do Int
x <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0 :: Int, Int
3)
               case Int
x of
                   Int
0 -> Alignment -> Gen Alignment
forall (m :: * -> *) a. Monad m => a -> m a
return Alignment
AlignLeft
                   Int
1 -> Alignment -> Gen Alignment
forall (m :: * -> *) a. Monad m => a -> m a
return Alignment
AlignRight
                   Int
2 -> Alignment -> Gen Alignment
forall (m :: * -> *) a. Monad m => a -> m a
return Alignment
AlignCenter
                   Int
3 -> Alignment -> Gen Alignment
forall (m :: * -> *) a. Monad m => a -> m a
return Alignment
AlignDefault
                   Int
_ -> String -> Gen Alignment
forall a. HasCallStack => String -> a
error String
"FATAL ERROR: Arbitrary instance, logic bug"

instance Arbitrary ListNumberStyle where
        arbitrary :: Gen ListNumberStyle
arbitrary
          = do Int
x <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0 :: Int, Int
6)
               case Int
x of
                   Int
0 -> ListNumberStyle -> Gen ListNumberStyle
forall (m :: * -> *) a. Monad m => a -> m a
return ListNumberStyle
DefaultStyle
                   Int
1 -> ListNumberStyle -> Gen ListNumberStyle
forall (m :: * -> *) a. Monad m => a -> m a
return ListNumberStyle
Example
                   Int
2 -> ListNumberStyle -> Gen ListNumberStyle
forall (m :: * -> *) a. Monad m => a -> m a
return ListNumberStyle
Decimal
                   Int
3 -> ListNumberStyle -> Gen ListNumberStyle
forall (m :: * -> *) a. Monad m => a -> m a
return ListNumberStyle
LowerRoman
                   Int
4 -> ListNumberStyle -> Gen ListNumberStyle
forall (m :: * -> *) a. Monad m => a -> m a
return ListNumberStyle
UpperRoman
                   Int
5 -> ListNumberStyle -> Gen ListNumberStyle
forall (m :: * -> *) a. Monad m => a -> m a
return ListNumberStyle
LowerAlpha
                   Int
6 -> ListNumberStyle -> Gen ListNumberStyle
forall (m :: * -> *) a. Monad m => a -> m a
return ListNumberStyle
UpperAlpha
                   Int
_ -> String -> Gen ListNumberStyle
forall a. HasCallStack => String -> a
error String
"FATAL ERROR: Arbitrary instance, logic bug"

instance Arbitrary ListNumberDelim where
        arbitrary :: Gen ListNumberDelim
arbitrary
          = do Int
x <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0 :: Int, Int
3)
               case Int
x of
                   Int
0 -> ListNumberDelim -> Gen ListNumberDelim
forall (m :: * -> *) a. Monad m => a -> m a
return ListNumberDelim
DefaultDelim
                   Int
1 -> ListNumberDelim -> Gen ListNumberDelim
forall (m :: * -> *) a. Monad m => a -> m a
return ListNumberDelim
Period
                   Int
2 -> ListNumberDelim -> Gen ListNumberDelim
forall (m :: * -> *) a. Monad m => a -> m a
return ListNumberDelim
OneParen
                   Int
3 -> ListNumberDelim -> Gen ListNumberDelim
forall (m :: * -> *) a. Monad m => a -> m a
return ListNumberDelim
TwoParens
                   Int
_ -> String -> Gen ListNumberDelim
forall a. HasCallStack => String -> a
error String
"FATAL ERROR: Arbitrary instance, logic bug"