Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write new Format and Formats types, some helper functions #78

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pandoc-types.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Library
Text.Pandoc.Builder
Text.Pandoc.JSON
Text.Pandoc.Arbitrary
Text.Pandoc.Format
Other-modules: Paths_pandoc_types
Autogen-modules: Paths_pandoc_types
Build-depends: base >= 4.5 && < 5,
Expand Down
16 changes: 16 additions & 0 deletions src/Text/Pandoc/Arbitrary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ where
import Test.QuickCheck
import Control.Applicative (Applicative ((<*>), pure), (<$>))
import Control.Monad (forM)
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as T
import Text.Pandoc.Definition
import Text.Pandoc.Builder
import qualified Text.Pandoc.Format as F

realString :: Gen Text
realString = fmap T.pack $ resize 8 $ listOf $ frequency [ (9, elements [' '..'\127'])
Expand Down Expand Up @@ -398,3 +400,17 @@ instance Arbitrary ListNumberDelim where
2 -> return OneParen
3 -> return TwoParens
_ -> error "FATAL ERROR: Arbitrary instance, logic bug"

instance Arbitrary F.KnownFormat where
arbitrary = arbitraryBoundedEnum

instance Arbitrary F.Format where
arbitrary = frequency $ [(80, F.KnownFormat <$> arbitrary)
,(20, F.CustomFormat . T.pack <$> arbitrary)]
shrink F.KnownFormat{} = []
shrink (F.CustomFormat t) = F.CustomFormat <$> shrinkText t

instance Arbitrary F.Formats where
arbitrary = F.exactly <$> arbitrary
shrink (F.OneOfFormats s) = F.exactly <$> shrink (Set.toList s)
shrink (F.NoneOfFormats s) = F.exactlyNone <$> shrink (Set.toList s)
Loading