Fix off-by-one error in Token charControl.

Fixes #2.
This commit is contained in:
Antoine Latter 2014-09-09 20:17:49 -05:00
parent 3276ef770c
commit fd8ecf5d03
4 changed files with 54 additions and 2 deletions

View File

@ -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

View File

@ -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

10
test/Main.hs Normal file
View File

@ -0,0 +1,10 @@
import Test.Framework
import Tokens ( tokensTests )
main :: IO ()
main = do
defaultMain
[ testGroup "Text.Parsec.Tokens" tokensTests
]

29
test/Tokens.hs Normal file
View File

@ -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