Reproduce bug in test.

This commit is contained in:
Robin Heggelund Hansen 2023-09-20 21:15:34 +02:00
parent 9f055d9727
commit 0517d24b1e
No known key found for this signature in database
3 changed files with 39 additions and 0 deletions

View File

@ -39,6 +39,7 @@ data Decl
| Alias (Maybe Src.DocComment) (A.Located Src.Alias)
| Port (Maybe Src.DocComment) Src.Port
| TopLevelComments (NonEmpty Src.Comment)
deriving (Show)
declaration :: Space.Parser E.Decl (Decl, [Src.Comment])
declaration =

View File

@ -263,6 +263,7 @@ Test-Suite gren-tests
Parse.SpaceSpec
Parse.UnderscorePatternSpec
Parse.MultilineStringSpec
Parse.DeclSpec
Build-Depends:
hspec >= 2.7.10 && < 3

37
tests/Parse/DeclSpec.hs Normal file
View File

@ -0,0 +1,37 @@
{-# LANGUAGE OverloadedStrings #-}
module Parse.DeclSpec where
import Data.ByteString qualified as BS
import Helpers.Instances ()
import Parse.Declaration (declaration)
import Parse.Primitives qualified as P
import Test.Hspec (Spec, describe, it, shouldSatisfy)
data ParseError
= DeclError P.Row P.Col
| OtherError String P.Row P.Col
deriving (Show, Eq)
spec :: Spec
spec = do
describe "Top Level Variables" $ do
it "regression test" $
parse "test = \"test\""
it "Variables can be non-ascii characters" $ do
parse "æøå = \"test\""
parse :: BS.ByteString -> IO ()
parse str =
P.fromByteString
(P.specialize (\_ row col -> DeclError row col) declaration)
(OtherError "fromByteString failed")
str
`shouldSatisfy` valid
valid :: Either x y -> Bool
valid result =
case result of
Right _ -> True
Left _ -> False