diff options
| author | Eugen Wissner <belka@caraus.de> | 2019-07-22 05:50:00 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2019-07-22 05:50:00 +0200 |
| commit | 1b5094b6a3e6eb68f67bc3238487818f7b7d552a (patch) | |
| tree | 6e51bc6bba9613b60af81d56a39b8dad10750cef /tests/Language | |
| parent | 9d15b831648ff7a7acb1327efbce3b22181b6157 (diff) | |
| download | graphql-1b5094b6a3e6eb68f67bc3238487818f7b7d552a.tar.gz | |
Parse the BOM header if any
Diffstat (limited to 'tests/Language')
| -rw-r--r-- | tests/Language/GraphQL/LexerSpec.hs | 19 | ||||
| -rw-r--r-- | tests/Language/GraphQL/ParserSpec.hs | 18 |
2 files changed, 30 insertions, 7 deletions
diff --git a/tests/Language/GraphQL/LexerSpec.hs b/tests/Language/GraphQL/LexerSpec.hs index 2a370ea..b5b605d 100644 --- a/tests/Language/GraphQL/LexerSpec.hs +++ b/tests/Language/GraphQL/LexerSpec.hs @@ -5,14 +5,16 @@ module Language.GraphQL.LexerSpec ( spec ) where -import Language.GraphQL.Lexer -import qualified Data.Text as T +import Data.Either (isRight) +import Data.Text (Text) import Data.Void (Void) +import Language.GraphQL.Lexer import Test.Hspec ( Spec , context , describe , it , shouldBe + , shouldSatisfy ) import Text.Megaparsec ( ParseErrorBundle , parse @@ -22,6 +24,9 @@ import Text.RawString.QQ (r) spec :: Spec spec = describe "Lexer" $ do context "Reference tests" $ do + it "accepts BOM header" $ + runParser unicodeBOM "\xfeff" `shouldSatisfy` isRight + it "lexes strings" $ do runParser string [r|"simple"|] `shouldBe` Right "simple" runParser string [r|" white space "|] `shouldBe` Right " white space " @@ -77,13 +82,13 @@ spec = describe "Lexer" $ do it "lexes punctuation" $ do runParser bang "!" `shouldBe` Right '!' runParser dollar "$" `shouldBe` Right '$' - runBetween parens "()" `shouldBe` Right () + runBetween parens "()" `shouldSatisfy` isRight runParser spread "..." `shouldBe` Right "..." runParser colon ":" `shouldBe` Right ":" runParser equals "=" `shouldBe` Right "=" runParser at "@" `shouldBe` Right '@' - runBetween brackets "[]" `shouldBe` Right () - runBetween braces "{}" `shouldBe` Right () + runBetween brackets "[]" `shouldSatisfy` isRight + runBetween braces "{}" `shouldSatisfy` isRight runParser pipe "|" `shouldBe` Right "|" context "Implementation tests" $ do @@ -92,8 +97,8 @@ spec = describe "Lexer" $ do it "lexes ampersand" $ runParser amp "&" `shouldBe` Right "&" -runParser :: forall a. Parser a -> T.Text -> Either (ParseErrorBundle T.Text Void) a +runParser :: forall a. Parser a -> Text -> Either (ParseErrorBundle Text Void) a runParser = flip parse "" -runBetween :: (Parser () -> Parser ()) -> T.Text -> Either (ParseErrorBundle T.Text Void) () +runBetween :: (Parser () -> Parser ()) -> Text -> Either (ParseErrorBundle Text Void) () runBetween parser = parse (parser $ pure ()) "" diff --git a/tests/Language/GraphQL/ParserSpec.hs b/tests/Language/GraphQL/ParserSpec.hs new file mode 100644 index 0000000..c412c85 --- /dev/null +++ b/tests/Language/GraphQL/ParserSpec.hs @@ -0,0 +1,18 @@ +{-# LANGUAGE OverloadedStrings #-} +module Language.GraphQL.ParserSpec + ( spec + ) where + +import Data.Either (isRight) +import Language.GraphQL.Parser (document) +import Test.Hspec ( Spec + , describe + , it + , shouldSatisfy + ) +import Text.Megaparsec (parse) + +spec :: Spec +spec = describe "Parser" $ + it "accepts BOM header" $ + parse document "" "\xfeff{foo}" `shouldSatisfy` isRight |
