Skip to content

Commit

Permalink
test parsing of schema with both imports and entities #6
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosh committed Sep 17, 2018
1 parent 89944ec commit 5d2b59a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Language/Parser/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,13 @@ schemaLiteralSectionParser = do
maybeImports <- optional $ do
constant "imports"
many typesideImportParser
pure $ SchemaLiteralSection (fromMaybe [] maybeImports) [] [] [] [] []
maybeEntities <- optional $ do
constant "entities"
many identifier
pure $ SchemaLiteralSection
(fromMaybe [] maybeImports)
(fromMaybe [] maybeEntities)
[]
[]
[]
[]
9 changes: 9 additions & 0 deletions test/Parser/SchemaSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,12 @@ spec = do
forAll (listOf typesideImportGen) $
\typesideImports -> parse schemaLiteralSectionParser "" ("imports " ++ (unwords $ map show typesideImports))
== Right (SchemaLiteralSection typesideImports [] [] [] [] [])
specify "parses correctly a SchemaLiteralSection with entities" $
forAll (listOf identifierGen) $
\identifiers -> parse schemaLiteralSectionParser "" ("entities " ++ (unwords $ identifiers))
== Right (SchemaLiteralSection [] identifiers [] [] [] [])
specify "parses correctly a SchemaLiteralSection with every piece" $
forAll ((\a b -> (a, b)) <$> listOf typesideImportGen <*> listOf identifierGen) $
\(typesideImports, identifiers) ->
parse schemaLiteralSectionParser "" ("imports " ++ (unwords $ map show typesideImports) ++ " entities " ++ (unwords $ identifiers))
== Right (SchemaLiteralSection typesideImports identifiers [] [] [] [])

0 comments on commit 5d2b59a

Please sign in to comment.