diff --git a/Text/Parsec/Token.hs b/Text/Parsec/Token.hs index 6a6f29b32a971e40cc40ee0b55a4bccf24463299..885f797c8afab6b523b9abc7c3448e4a78e7e42b 100644 --- a/Text/Parsec/Token.hs +++ b/Text/Parsec/Token.hs @@ -448,7 +448,7 @@ makeTokenParser languageDef charControl = do{ char '^' ; code <- upper - ; return (toEnum (fromEnum code - fromEnum 'A')) + ; return (toEnum (fromEnum code - fromEnum 'A' + 1)) } charNum = do{ code <- decimal diff --git a/parsec.cabal b/parsec.cabal index fbe1750634598f4228d27dc8cfb688a3f85c9193..bc1c9eaf02838079a5ed9b101fbf51e97c9a684d 100644 --- a/parsec.cabal +++ b/parsec.cabal @@ -1,6 +1,6 @@ name: parsec version: 3.1.6 -cabal-version: >= 1.6 +cabal-version: >= 1.8 license: BSD3 license-file: LICENSE author: Daan Leijen <daan@microsoft.com>, Paolo Martini <paolo@nemail.it> @@ -63,3 +63,16 @@ library build-depends: mtl, bytestring, text >= 0.2 && < 1.3 extensions: ExistentialQuantification, PolymorphicComponents, MultiParamTypeClasses, FlexibleInstances, FlexibleContexts, DeriveDataTypeable, CPP ghc-options: -O2 + +Test-Suite tests + type: exitcode-stdio-1.0 + hs-source-dirs: test + main-is: Main.hs + other-modules: + Tokens + build-depends: + base, + parsec, + HUnit == 1.2.*, + test-framework >= 0.6 && < 0.9, + test-framework-hunit >= 0.2 && < 0.4 \ No newline at end of file diff --git a/test/Main.hs b/test/Main.hs new file mode 100644 index 0000000000000000000000000000000000000000..864f0771c1c760ff1682cc57f04d001dfa58ec91 --- /dev/null +++ b/test/Main.hs @@ -0,0 +1,10 @@ + +import Test.Framework + +import Tokens ( tokensTests ) + +main :: IO () +main = do + defaultMain + [ testGroup "Text.Parsec.Tokens" tokensTests + ] \ No newline at end of file diff --git a/test/Tokens.hs b/test/Tokens.hs new file mode 100644 index 0000000000000000000000000000000000000000..3a626255c59740b79c6c300f86d05df943ade75b --- /dev/null +++ b/test/Tokens.hs @@ -0,0 +1,29 @@ + +module Tokens + ( tokensTests + ) where + +import Test.HUnit hiding ( Test ) +import Test.Framework +import Test.Framework.Providers.HUnit + +import Text.Parsec +import Text.Parsec.String +import qualified Text.Parsec.Token as P +import Text.Parsec.Language (haskellDef) + +tokensTests :: [Test] +tokensTests = + return $ + testCase "Control Char Parsing" $ + parseString "\"test\\^Bstring\"" @?= "test\^Bstring" + + where + parseString :: String -> String + parseString input = + case parse parser "Example" input of + Left{} -> error "Parse failure" + Right str -> str + + parser :: Parser String + parser = P.stringLiteral $ P.makeTokenParser haskellDef \ No newline at end of file