2014-09-10 05:17:49 +04:00
|
|
|
|
2015-07-28 16:32:19 +03:00
|
|
|
module Bugs.Bug2 (main) where
|
2014-09-10 05:17:49 +04:00
|
|
|
|
2015-09-08 14:34:02 +03:00
|
|
|
import Control.Applicative (empty)
|
|
|
|
import Control.Monad (void)
|
2014-09-10 05:17:49 +04:00
|
|
|
|
2015-08-01 19:24:45 +03:00
|
|
|
import Text.Megaparsec
|
2015-09-08 14:34:02 +03:00
|
|
|
import Text.Megaparsec.String
|
2015-08-30 13:00:07 +03:00
|
|
|
import qualified Text.Megaparsec.Lexer as L
|
2014-09-10 05:17:49 +04:00
|
|
|
|
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 '"')
|
|
|
|
|
2014-09-25 04:22:35 +04:00
|
|
|
main :: Test
|
|
|
|
main =
|
|
|
|
testCase "Control Char Parsing (#2)" $
|
2014-09-10 05:17:49 +04:00
|
|
|
parseString "\"test\\^Bstring\"" @?= "test\^Bstring"
|
|
|
|
where
|
2015-09-02 16:27:48 +03:00
|
|
|
parseString :: String -> String
|
2014-09-10 05:17:49 +04:00
|
|
|
parseString input =
|
2015-09-08 14:34:02 +03:00
|
|
|
case parse stringLiteral "Example" input of
|
2014-09-10 05:17:49 +04:00
|
|
|
Left{} -> error "Parse failure"
|
|
|
|
Right str -> str
|