@@ -17,6 +17,7 @@ import System.Exit
1717
1818import qualified Language.PureScript as P
1919import qualified Language.PureScript.Docs as Docs
20+import Language.PureScript.Docs.AsMarkdown (codeToString)
2021import qualified Language.PureScript.Publish as Publish
2122import qualified Language.PureScript.Publish.ErrorsWarnings as Publish
2223
@@ -59,6 +60,10 @@ data Assertion
5960 -- | Assert that a particular value declaration exists, and its type
6061 -- satisfies the given predicate.
6162 | ValueShouldHaveTypeSignature P.ModuleName String (ShowFn (P.Type -> Bool))
63+ -- | Assert that a particular type alias exists, and its corresponding
64+ -- type, when rendered, matches a given string exactly
65+ -- fields: module, type synonym name, expected type
66+ | TypeSynonymShouldRenderAs P.ModuleName String String
6267 deriving (Show)
6368
6469newtype ShowFn a = ShowFn a
@@ -85,6 +90,9 @@ data AssertionFailure
8590 -- should have been.
8691 -- Fields: module name, declaration name, actual type.
8792 | ValueDeclarationWrongType P.ModuleName String P.Type
93+ -- | A Type synonym has been rendered in an unexpected format
94+ -- Fields: module name, declaration name, expected rendering, actual rendering
95+ | TypeSynonymMismatch P.ModuleName String String String
8896 deriving (Show)
8997
9098data AssertionResult
@@ -149,6 +157,21 @@ runAssertion assertion Docs.Module{..} =
149157 Fail (WrongDeclarationType mn decl "value"
150158 (Docs.declInfoToString declInfo))
151159
160+ TypeSynonymShouldRenderAs mn decl expected ->
161+ case find ((==) decl . Docs.declTitle) (declarationsFor mn) of
162+ Nothing ->
163+ Fail (NotDocumented mn decl)
164+ Just Docs.Declaration{..} ->
165+ case declInfo of
166+ Docs.TypeSynonymDeclaration [] ty ->
167+ let actual = codeToString (Docs.renderType ty) in
168+ if actual == expected
169+ then Pass
170+ else Fail (TypeSynonymMismatch mn decl expected actual)
171+ _ ->
172+ Fail (WrongDeclarationType mn decl "synonym"
173+ (Docs.declInfoToString declInfo))
174+
152175 where
153176 declarationsFor mn =
154177 if mn == modName
@@ -261,6 +284,13 @@ testCases =
261284 , ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "anInt" (ShowFn (P.tyInt ==))
262285 , ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "aNumber" (ShowFn (P.tyNumber ==))
263286 ])
287+
288+ , ("ConstrainedArgument",
289+ [ TypeSynonymShouldRenderAs (n "ConstrainedArgument") "WithoutArgs" "forall a. (Partial => a) -> a"
290+ , TypeSynonymShouldRenderAs (n "ConstrainedArgument") "WithArgs" "forall a. (Foo a => a) -> a"
291+ , TypeSynonymShouldRenderAs (n "ConstrainedArgument") "MultiWithoutArgs" "forall a. ((Partial, Partial) => a) -> a"
292+ , TypeSynonymShouldRenderAs (n "ConstrainedArgument") "MultiWithArgs" "forall a b. ((Foo a, Foo b) => a) -> a"
293+ ])
264294 ]
265295
266296 where