diff --git a/compiler/src/Parse/Declaration.hs b/compiler/src/Parse/Declaration.hs index 914c2f8a..ae00f415 100644 --- a/compiler/src/Parse/Declaration.hs +++ b/compiler/src/Parse/Declaration.hs @@ -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 = diff --git a/gren.cabal b/gren.cabal index 8d96f35f..fd968037 100644 --- a/gren.cabal +++ b/gren.cabal @@ -263,6 +263,7 @@ Test-Suite gren-tests Parse.SpaceSpec Parse.UnderscorePatternSpec Parse.MultilineStringSpec + Parse.DeclSpec Build-Depends: hspec >= 2.7.10 && < 3 diff --git a/tests/Parse/DeclSpec.hs b/tests/Parse/DeclSpec.hs new file mode 100644 index 00000000..baa5801d --- /dev/null +++ b/tests/Parse/DeclSpec.hs @@ -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