import GitYrp
import Test.QuickCheck
import Text.Printf
import System.Exit

succOrFail :: Result -> IO ()
succOrFail (Success _ _ _) = return ()
succOrFail x =  print x >> exitFailure >> return ()

testOne :: Testable p => (String, p) -> IO Result
testOne (s, prop) = printf "%-25s: " s >> quickCheckResult prop

main :: IO ()
main  = mapM testOne tests >>= mapM_ succOrFail

prop_getCoverLetterFilename1 =
    getCoverLetterFilename [] == Nothing

prop_getCoverLetterFilename2 =
    getCoverLetterFilename ["foo", x] == Just x
  where
    x = "0000-cover-letter.patch"

prop_getCoverLetterFilename3 =
    getCoverLetterFilename ["foo", x] == Just x
  where
    x = "v2-0000-cover-letter.patch"

prop_cutOffBlurb =
    cutOffBlurb "foo\nbar\n*** BLURB HERE ***\nqux\nquuux" == "foo\nbar\n"

tests =
    [ ("xy1", prop_getCoverLetterFilename1)
    , ("xy2", prop_getCoverLetterFilename2)
    , ("xy3", prop_getCoverLetterFilename3)
    , ("cutOffBlurb", prop_cutOffBlurb)
    ]
