From 06b3302862e0c427439136241fb6299f215cec52 Mon Sep 17 00:00:00 2001 From: Danny Navarro Date: Tue, 22 Sep 2015 13:53:37 +0200 Subject: Add kitchen sink parse/encode unit test This also includes the fixes to make it work. Golden tests have been removed. --- Data/GraphQL/Parser.hs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'Data/GraphQL/Parser.hs') diff --git a/Data/GraphQL/Parser.hs b/Data/GraphQL/Parser.hs index 3ff780c..00e4df1 100644 --- a/Data/GraphQL/Parser.hs +++ b/Data/GraphQL/Parser.hs @@ -14,7 +14,6 @@ import Data.Char import Data.Foldable (traverse_) import Data.Text (Text, append) -import qualified Data.Text as T import Data.Attoparsec.Text ( Parser , () @@ -29,7 +28,6 @@ import Data.Attoparsec.Text , peekChar , sepBy1 , signed - , takeText , takeWhile , takeWhile1 ) @@ -170,15 +168,9 @@ booleanValue :: Parser Bool booleanValue = True <$ tok "true" <|> False <$ tok "false" +-- TODO: Escape characters. Look at `jsstring_` in aeson package. stringValue :: Parser StringValue -stringValue = StringValue <$> quotes (T.foldl' step mempty <$> takeText) - where - -- TODO: Handle unicode and the rest of escaped chars. - step acc c - | T.null acc = T.singleton c - | T.last acc == '\\' = if c == '"' then T.init acc `T.snoc` '"' - else acc `T.snoc` c - | otherwise = acc `T.snoc` c +stringValue = StringValue <$> quotes (takeWhile (/= '"')) -- Notice it can be empty listValue :: Parser ListValue @@ -205,9 +197,9 @@ directive = Directive -- * Type Reference type_ :: Parser Type -type_ = TypeNamed <$> namedType - <|> TypeList <$> listType +type_ = TypeList <$> listType <|> TypeNonNull <$> nonNullType + <|> TypeNamed <$> namedType "type_ error!" namedType :: Parser NamedType -- cgit v1.2.3