megaparsec/old-tests/Bugs/Bug2.hs

34 lines
798 B
Haskell
Raw Normal View History

2015-07-28 16:32:19 +03:00
module Bugs.Bug2 (main) where
2015-09-08 14:34:02 +03:00
import Control.Applicative (empty)
import Control.Monad (void)
import Text.Megaparsec
2015-09-08 14:34:02 +03:00
import Text.Megaparsec.String
import qualified Text.Megaparsec.Lexer as L
2015-09-08 14:34:02 +03:00
import Test.Framework
import Test.Framework.Providers.HUnit
import Test.HUnit hiding (Test)
sc :: Parser ()
sc = L.space (void spaceChar) empty empty
lexeme :: Parser a -> Parser a
lexeme = L.lexeme sc
stringLiteral :: Parser String
stringLiteral = lexeme $ char '"' >> manyTill L.charLiteral (char '"')
main :: Test
main =
testCase "Control Char Parsing (#2)" $
parseString "\"test\\^Bstring\"" @?= "test\^Bstring"
where
parseString :: String -> String
parseString input =
2015-09-08 14:34:02 +03:00
case parse stringLiteral "Example" input of
Left{} -> error "Parse failure"
Right str -> str