Skip to content

Commit f46fa98

Browse files
committed
regression: NBSP can occur in other place too
1 parent ff3446f commit f46fa98

File tree

8 files changed

+133
-19
lines changed

8 files changed

+133
-19
lines changed

Cabal/Cabal.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ extra-source-files:
3232
-- Generated with 'misc/gen-extra-source-files.sh'
3333
-- Do NOT edit this section manually; instead, run the script.
3434
-- BEGIN gen-extra-source-files
35+
tests/ParserTests/regressions/Octree-0.5.cabal
3536
tests/ParserTests/regressions/encoding-0.8.cabal
3637
tests/ParserTests/warnings/bom.cabal
3738
tests/ParserTests/warnings/bool.cabal

Cabal/Distribution/PackageDescription/Check.hs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import Distribution.Simple.Utils hiding (findPackageDesc, notice)
5555
import Distribution.Version
5656
import Distribution.Package
5757
import Distribution.Text
58+
import Distribution.Utils.Generic (isAscii)
5859
import Language.Haskell.Extension
5960

6061
import Control.Monad (mapM)
@@ -146,6 +147,7 @@ checkPackage gpkg mpkg =
146147
++ checkConditionals gpkg
147148
++ checkPackageVersions gpkg
148149
++ checkDevelopmentOnlyFlags gpkg
150+
++ checkFlagNames gpkg
149151
where
150152
pkg = fromMaybe (flattenPackageDescription gpkg) mpkg
151153

@@ -1584,6 +1586,27 @@ checkConditionals pkg =
15841586
COr c1 c2 -> condfv c1 ++ condfv c2
15851587
CAnd c1 c2 -> condfv c1 ++ condfv c2
15861588

1589+
checkFlagNames ::GenericPackageDescription -> [PackageCheck]
1590+
checkFlagNames gpd
1591+
| null invalidFlagNames = []
1592+
| otherwise = [ PackageDistSuspicious
1593+
$ "Suspicious flag names: " ++ unwords invalidFlagNames ++ ". "
1594+
++ "To avoid ambiguity in command line interfaces, flag shouldn't "
1595+
++ "start with a dash. Also for better compatibility, flag names "
1596+
++ "shouldn't contain non-ascii characters."
1597+
]
1598+
where
1599+
invalidFlagNames =
1600+
[ fn
1601+
| flag <- genPackageFlags gpd
1602+
, let fn = unFlagName (flagName flag)
1603+
, invalidFlagName fn
1604+
]
1605+
-- starts with dash
1606+
invalidFlagName ('-':_) = True
1607+
-- mon ascii letter
1608+
invalidFlagName cs = any (\c -> not (isAscii c) && isAlpha c) cs
1609+
15871610
checkDevelopmentOnlyFlagsBuildInfo :: BuildInfo -> [PackageCheck]
15881611
checkDevelopmentOnlyFlagsBuildInfo bi =
15891612
catMaybes [

Cabal/Distribution/Parsec/Lexer.hs

Lines changed: 14 additions & 12 deletions
Large diffs are not rendered by default.

Cabal/tests/ParserHackageTests.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ problematicFiles =
197197
, eq "ixset/1.0.4/ixset.cabal"
198198
-- comments in braces
199199
, isPrefixOf "hint/"
200+
-- other-modules:\n .
201+
, eq "unicode-transforms/0.3.3/unicode-transforms.cabal"
200202
]
201203
where
202204
eq = (==)

Cabal/tests/ParserTests.hs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ import qualified Data.ByteString as BS
1616
tests :: TestTree
1717
tests = testGroup "parsec tests"
1818
[ warningTests
19+
, regressionTests
1920
]
2021

22+
-------------------------------------------------------------------------------
23+
-- Warnings
24+
-------------------------------------------------------------------------------
25+
2126
-- Verify that we trigger warnings
2227
warningTests :: TestTree
2328
warningTests = testGroup "warnings triggered"
@@ -52,5 +57,28 @@ warningTest wt fp = testCase (show wt) $ do
5257
[] -> assertFailure "got no warnings"
5358
_ -> assertFailure $ "got multiple warnings: " ++ show warns
5459

60+
-------------------------------------------------------------------------------
61+
-- Regressions
62+
-------------------------------------------------------------------------------
63+
64+
regressionTests :: TestTree
65+
regressionTests = testGroup "regressions"
66+
[ regressionTest "encoding-0.8.cabal"
67+
, regressionTest "Octree-0.5.cabal"
68+
]
69+
70+
regressionTest :: FilePath -> TestTree
71+
regressionTest fp = testCase fp $ do
72+
contents <- BS.readFile $ "tests" </> "ParserTests" </> "regressions" </> fp
73+
let res = parseGenericPackageDescription contents
74+
let (_, errs, x) = runParseResult res
75+
76+
assertBool ("parses successfully: " ++ show errs) $ isJust x
77+
assertBool ("parses without errors: " ++ show errs) $ null errs
78+
79+
-------------------------------------------------------------------------------
80+
-- Main
81+
-------------------------------------------------------------------------------
82+
5583
main :: IO ()
5684
main = defaultMain tests
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Octree
2+
version: 0.5
3+
stability: beta
4+
homepage: https://github.com/mgajda/octree
5+
package-url: http://hackage.haskell.org/package/octree
6+
synopsis: Simple unbalanced Octree for storing data about 3D points
7+
description: Octree data structure is relatively shallow data structure for space partitioning.
8+
category: Data
9+
license: BSD3
10+
license-file: LICENSE
11+
12+
author: Michal J. Gajda
13+
copyright: Copyright by Michal J. Gajda '2012
14+
maintainer: [email protected]
15+
bug-reports: mailto:[email protected]
16+
17+
18+
build-type: Simple
19+
cabal-version: >=1.8
20+
tested-with: GHC==7.0.4,GHC==7.4.1,GHC==7.4.2,GHC==7.6.0
21+
22+
source-repository head
23+
type: git
24+
location: [email protected]:mgajda/octree.git
25+
26+
Library
27+
build-depends: base>=4.0 && < 4.7, AC-Vector >= 2.3.0, QuickCheck >= 2.4.0
28+
exposed-modules: Data.Octree
29+
other-modules: Data.Octree.Internal
30+
exposed: True
31+
extensions: ScopedTypeVariables
32+
33+
Test-suite test_Octree
34+
Type: exitcode-stdio-1.0
35+
Build-depends: base>=4.0 && < 4.7, AC-Vector >= 2.3.0, QuickCheck >= 2.4.0
36+
Main-is: tests/test_Octree.hs
37+
38+
Test-suite readme
39+
  type: exitcode-stdio-1.0
40+
-- We have a symlink: README.lhs -> README.md
41+
  main-is: README.lhs
42+
Build-depends: base>=4.0 && < 4.7, AC-Vector >= 2.3.0, QuickCheck >= 2.4.0, markdown-unlit
43+
  ghc-options: -pgmL markdown-unlit
44+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Name: encoding
2+
Version: 0.8
3+
4+
custom-setup
5+
  setup-depends:
6+
base < 5,
7+
    ghc-prim
8+
9+
Library
10+
build-depends: base
11+
Exposed-Modules:
12+
Data.Encoding

boot/Lexer.x

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,12 @@ tokens :-
125125
}
126126

127127
<bol_field_layout> {
128-
$spacetab* --TODO prevent or record leading tabs
129-
{ \pos len inp -> if B.length inp == len
128+
$nbspspacetab* --TODO prevent or record leading tabs
129+
{ \pos len inp -> checkWhitespace len inp >>= \len' ->
130+
if B.length inp == len
130131
then return (L pos EOF)
131132
else setStartCode in_field_layout
132-
>> return (L pos (Indent len)) }
133+
>> return (L pos (Indent len')) }
133134
}
134135

135136
<in_field_layout> {
@@ -175,11 +176,12 @@ toki t pos len input = return $! L pos (t (B.take len input))
175176
tok :: Monad m => Token -> Position -> t -> t1 -> m LToken
176177
tok t pos _len _input = return $! L pos t
177178

178-
checkWhitespace :: Int -> ByteString -> Lex ()
179+
checkWhitespace :: Int -> ByteString -> Lex Int
179180
checkWhitespace len bs
180-
| B.any (== 194) (B.take len bs) =
181-
addWarning LexWarningNBSP "Non-breaking space found"
182-
| otherwise = return ()
181+
| B.any (== 194) (B.take len bs) = do
182+
addWarning LexWarningNBSP "Non-breaking space found"
183+
return $ len - B.count 194 (B.take len bs)
184+
| otherwise = return len
183185

184186
-- -----------------------------------------------------------------------------
185187
-- The input type

0 commit comments

Comments
 (0)