module Test.Types where
import Pipes.KeyValueCsv.Cell
import Data.Char
import Test.QuickCheck
newtype Alphabetic = Alphabetic { getAlphabetic :: String }
deriving (Eq)
instance Show Alphabetic where
show (Alphabetic a) = show a
alphabetLower :: String
alphabetLower = "abcdefghijklmnopqrstuvwxyz"
alphabet :: String
alphabet = alphabetLower ++ map toUpper alphabetLower
instance FromCell Alphabetic where
fromCell = fmap Alphabetic <$> fromCell
instance Arbitrary Alphabetic where
arbitrary = Alphabetic <$> listOf1 (elements alphabet)
shrink (Alphabetic a) = Alphabetic <$> shrink a
newtype Quoted = Quoted { quoted :: String }
deriving (Eq)
instance Show Quoted where
show (Quoted q) = q
quote :: String -> String
quote s = "\"" ++ s ++ "\""
instance Arbitrary Quoted where
arbitrary = Quoted . quote <$> listOf1 (elements $ alphabet ++ " ")
shrink (Quoted q) = Quoted . quote <$> shrink contents
where contents = init $ tail q
instance FromCell Quoted where
fromCell = fmap (Quoted . quote) <$> fromCell