mirror of
https://github.com/gren-lang/compiler.git
synced 2024-09-11 08:45:42 +03:00
Setup test suite for alias parsing.
This commit is contained in:
parent
36e6417829
commit
d7cf013116
@ -252,6 +252,7 @@ Test-Suite gren-tests
|
||||
|
||||
-- tests
|
||||
Integration.FormatSpec
|
||||
Parse.AliasSpec
|
||||
Parse.RecordUpdateSpec
|
||||
Parse.SpaceSpec
|
||||
Parse.UnderscorePatternSpec
|
||||
|
42
tests/Parse/AliasSpec.hs
Normal file
42
tests/Parse/AliasSpec.hs
Normal file
@ -0,0 +1,42 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Parse.AliasSpec where
|
||||
|
||||
import AST.Source qualified as Src
|
||||
import Data.Name qualified as Name
|
||||
import Data.ByteString qualified as BS
|
||||
import Helpers.Instances ()
|
||||
import Parse.Primitives qualified as P
|
||||
import Parse.Module qualified as Module
|
||||
import Reporting.Error.Syntax qualified as Error.Syntax
|
||||
import Test.Hspec (Spec, describe, it, shouldSatisfy)
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
describe "Import alias" $ do
|
||||
it "regression test" $
|
||||
parse
|
||||
"Module"
|
||||
"import Some.Long.Module as Module\n"
|
||||
|
||||
it "Aliases can have dots in them" $ do
|
||||
parse
|
||||
"My.Module"
|
||||
"import Some.Long.Module as My.Module\n"
|
||||
|
||||
parse :: String -> BS.ByteString -> IO ()
|
||||
parse expectedAlias str =
|
||||
let checkResult result =
|
||||
case result of
|
||||
Right imp ->
|
||||
case Src._alias imp of
|
||||
Just alias ->
|
||||
Name.toChars alias == expectedAlias
|
||||
|
||||
Nothing ->
|
||||
False
|
||||
Left _ ->
|
||||
False
|
||||
in shouldSatisfy
|
||||
(P.fromByteString Module.chompImport Error.Syntax.ModuleBadEnd str)
|
||||
checkResult
|
Loading…
Reference in New Issue
Block a user