Skip to content

Commit

Permalink
parse schema with path equations #6
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosh committed Sep 17, 2018
1 parent bc26402 commit 290ae3d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/Language/Parser/Generator/Generator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ schemaPathGen = oneof
, SchemaPathDotted <$> schemaPathGen <*> identifierGen
, SchemaPathParen <$> identifierGen <*> schemaPathGen
]

schemaPathEqnSigGen :: Gen SchemaPathEqnSig
schemaPathEqnSigGen = SchemaPathEqnSig <$> schemaPathGen <*> schemaPathGen
2 changes: 1 addition & 1 deletion src/Language/Parser/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ schemaLiteralSectionParser = do
(fromMaybe [] maybeImports)
(fromMaybe [] maybeEntities)
(fromMaybe [] maybeForeignKeys)
[]
(fromMaybe [] maybePathEquations)
[]
[]

Expand Down
3 changes: 3 additions & 0 deletions src/Language/Parser/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ type SchemaForeignId = String
data SchemaPathEqnSig = SchemaPathEqnSig SchemaPath SchemaPath
deriving (Eq)

instance Show SchemaPathEqnSig where
show (SchemaPathEqnSig schemaPathLeft schemaPathRight) = (show schemaPathLeft) ++ " = " ++ (show schemaPathRight)

data SchemaPath
= SchemaPathArrowId SchemaArrowId
| SchemaPathDotted SchemaPath SchemaArrowId
Expand Down
24 changes: 17 additions & 7 deletions test/Parser/SchemaSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,28 @@ spec = do
forAll (listOf identifierGen) $
\identifiers -> parse schemaLiteralSectionParser "" ("entities " ++ (unwords $ identifiers))
== Right (SchemaLiteralSection [] identifiers [] [] [] [])
specify "parses correctly a SchemaLiteralSection with foreign keys" $
specify "parses correctly a SchemaLiteralSection with foreign keys" $ withMaxSuccess 30 $
forAll (listOf schemaForeignSigGen) $
\schemaForeignSigs -> parse schemaLiteralSectionParser "" ("foreign_keys " ++ (unwords $ map show schemaForeignSigs))
== Right (SchemaLiteralSection [] [] schemaForeignSigs [] [] [])
specify "parses correctly a SchemaLiteralSection with every piece" $
forAll ((\a b c -> (a, b, c)) <$> listOf typesideImportGen <*> listOf identifierGen <*> listOf schemaForeignSigGen) $
\(typesideImports, identifiers, schemaForeignSigs) ->
specify "parses correctly a SchemaLiteralSection with path equations" $ withMaxSuccess 30 $
forAll (listOf schemaPathEqnSigGen) $
\schemaPathEqnSigs -> parse schemaLiteralSectionParser "" ("path_equations" ++ (unwords $ map show schemaPathEqnSigs))
== Right (SchemaLiteralSection [] [] [] schemaPathEqnSigs [] [])
specify "parses correctly a SchemaLiteralSection with every piece" $ withMaxSuccess 30 $
forAll ((\a b c d -> (a, b, c, d)) <$> listOf typesideImportGen <*> listOf identifierGen <*> listOf schemaForeignSigGen <*> listOf schemaPathEqnSigGen) $
\(typesideImports, identifiers, schemaForeignSigs, schemaPathEqnSigs) ->
parse schemaLiteralSectionParser ""
( "imports "
++ (unwords $ map show typesideImports)
++ " entities "
++ (unwords $ identifiers)
++ " foreign_keys "
++ (unwords $ map show schemaForeignSigs)
++ " path_equations "
++ (unwords $ map show schemaPathEqnSigs)
)
== Right (SchemaLiteralSection typesideImports identifiers schemaForeignSigs [] [] [])
== Right (SchemaLiteralSection typesideImports identifiers schemaForeignSigs schemaPathEqnSigs [] [])

describe "schemaForeignSigParser" $ do
specify "parses correctly a SchemaForeignSig" $
Expand All @@ -73,8 +79,12 @@ spec = do
parse schemaForeignSigParser "" ((unwords $ toList schemaForeignIds) ++ " : " ++ originSchemaEntityId ++ " -> " ++ targetSchemaEntityId)
== Right (SchemaForeignSig schemaForeignIds originSchemaEntityId targetSchemaEntityId)

-- describe "schemaPathEqnSigParser" $ do
-- specify "parses correctly a SchemaPathEqnSig" $
describe "schemaPathEqnSigParser" $ do
specify "parses correctly a SchemaPathEqnSig" $
forAll ((\a b -> (a, b)) <$> schemaPathGen <*> schemaPathGen) $
\(schemaPathLeft, schemaPathRight) ->
parse schemaPathEqnSigParser "" ((show schemaPathLeft) ++ " = " ++ (show schemaPathRight)) ==
Right (SchemaPathEqnSig schemaPathLeft schemaPathRight)

describe "schemaPathParser" $ do
specify "parses correctly a SchemaPathArrowId schemaPath" $
Expand Down

0 comments on commit 290ae3d

Please sign in to comment.