- | @checkChar p test label s@ runs parser @p@ on input @s@ and checks if
-- the parser correctly parses single character that satisfies @test@. The
-- character may be labelled, in this case @label@ is used to check quality
-- of error messages.

checkChar :: Parser Char -> (Char -> Bool) ->
              Maybe String -> String -> Property
checkChar p f l' s = checkParser p r s
  where h = head s
        l = exSpec <$> maybeToList l'
        r | null s = posErr 0 s (uneEof : l)
          | length s == 1 && f h = Right h
          | not (f h) = posErr 0 s (uneCh h : l)
          | otherwise = posErr 1 s [uneCh (s !! 1), exEof]

-- | @checkString p a test label s@ runs parser @p@ on input @s@ and checks if
-- the result is equal to @a@ and also quality of error messages. @test@ is
-- used to compare tokens. @label@ is used as expected representation of
-- parser's result in error messages.

checkChar :: Parser Char -> (Char -> Bool) ->
              Maybe String -> String -> Property
checkChar p f l' s = checkParser p r s
  where h = head s
        l = exSpec <$> maybeToList l'
        r | null s = posErr 0 s (uneEof : l)
          | length s == 1 && f h = Right h
          | not (f h) = posErr 0 s (uneCh h : l)
          | otherwise = posErr 1 s [uneCh (s !! 1), exEof]

-- | @checkString p a test label s@ runs parser @p@ on input @s@ and checks if
-- the result is equal to @a@ and also quality of error messages. @test@ is
-- used to compare tokens. @label@ is used as expected representation of
-- parser's result in error messages.
checkChar p f l' s = checkParser p r s
  where h = head s
        l = exSpec <$> maybeToList l'
        r | null s = posErr 0 s (uneEof : l)
          | length s == 1 && f h = Right h
          | not (f h) = posErr 0 s (uneCh h : l)
          | otherwise = posErr 1 s [uneCh (s !! 1), exEof]

-- | @checkString p a test label s@ runs parser @p@ on input @s@ and checks if
-- the result is equal to @a@ and also quality of error messages. @test@ is
-- used to compare tokens. @label@ is used as expected representation of
-- parser's result in error messages.