File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -90,8 +90,8 @@ instance HasParser Identifier where
9090-- identifiers by Nix, see 'nixKeywords'.
9191parseSimpleIdentifier :: CharParser st tok m Identifier
9292parseSimpleIdentifier = do
93- c <- satisfy (\ x -> x == ' _' || isAlpha x)
94- cs <- many (satisfy (\ x -> x `elem` " _'-" || isAlphaNum x))
93+ c <- satisfy (\ x -> x == ' _' || (isAscii x && isAlpha x) )
94+ cs <- many (satisfy (\ x -> x `elem` " _'-" || (isAscii x && isAlphaNum x) ))
9595 return (Identifier (c: cs))
9696
9797-- | 'ReadP' parser for quoted identifiers, i.e. those that /do/ need
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ module Main (main) where
22
33import Control.Lens
44import Control.Monad (forM_ )
5+ import Data.Char (isAscii , isSpace )
56import Data.String (fromString )
67import Language.Nix.Identifier
78import Test.Hspec
@@ -31,10 +32,17 @@ main = hspec $ do
3132 shouldSatisfy str needsQuoting
3233 prettyShow (ident # str) `shouldBe` " \" " ++ str ++ " \" "
3334
34- stringIdentProperty :: (String -> Bool ) -> Property
35+ describe " needsQuoting" $ do
36+ it " if string contains non ASCII characters" $ stringIdentProperty $ \ s ->
37+ any (not . isAscii) s ==> needsQuoting s
38+ it " if string contains spaces" $ stringIdentProperty $ \ s ->
39+ any isSpace s ==> needsQuoting s
40+ it " if length is zero" $ shouldSatisfy " " needsQuoting
41+
42+ stringIdentProperty :: Testable prop => (String -> prop ) -> Property
3543stringIdentProperty p = property $ \ s ->
3644 '\ 0 ' `notElem` s ==> classify (needsQuoting s) " need quoting" $ p s
3745
38- identProperty :: (Identifier -> Bool ) -> Property
46+ identProperty :: Testable prop => (Identifier -> prop ) -> Property
3947identProperty p = property $ \ i ->
4048 classify (needsQuoting (from ident # i)) " need quoting" $ p i
You can’t perform that action at this time.
0 commit comments