@@ -17,6 +17,7 @@ import System.Exit
18import qualified Language.PureScript as P
18import qualified Language.PureScript as P
19import qualified Language.PureScript.Docs as Docs
19import qualified Language.PureScript.Docs as Docs
20+import Language.PureScript.Docs.AsMarkdown (codeToString)
20import qualified Language.PureScript.Publish as Publish
21import qualified Language.PureScript.Publish as Publish
21import qualified Language.PureScript.Publish.ErrorsWarnings as Publish
22import qualified Language.PureScript.Publish.ErrorsWarnings as Publish
@@ -59,6 +60,10 @@ data Assertion
59 -- | Assert that a particular value declaration exists, and its type
60 -- | Assert that a particular value declaration exists, and its type
60 -- satisfies the given predicate.
61 -- satisfies the given predicate.
61 | ValueShouldHaveTypeSignature P.ModuleName String (ShowFn (P.Type -> Bool))
62 | 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
62 deriving (Show)
67 deriving (Show)
64newtype ShowFn a = ShowFn a
69newtype ShowFn a = ShowFn a
@@ -85,6 +90,9 @@ data AssertionFailure
85 -- should have been.
90 -- should have been.
86 -- Fields: module name, declaration name, actual type.
91 -- Fields: module name, declaration name, actual type.
87 | ValueDeclarationWrongType P.ModuleName String P.Type
92 | 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
88 deriving (Show)
96 deriving (Show)
90data AssertionResult
98data AssertionResult
@@ -149,6 +157,21 @@ runAssertion assertion Docs.Module{..} =
149 Fail (WrongDeclarationType mn decl "value"
157 Fail (WrongDeclarationType mn decl "value"
150 (Docs.declInfoToString declInfo))
158 (Docs.declInfoToString declInfo))
160+ TypeSynonymShouldRenderAs mn decl expected ->
161+ case find ((==) decl . Docs.declTitle) (declarationsFor mn) of
163+ Fail (NotDocumented mn decl)
164+ Just Docs.Declaration{..} ->
166+ Docs.TypeSynonymDeclaration [] ty ->
167+ let actual = codeToString (Docs.renderType ty) in
168+ if actual == expected
170+ else Fail (TypeSynonymMismatch mn decl expected actual)
172+ Fail (WrongDeclarationType mn decl "synonym"
173+ (Docs.declInfoToString declInfo))
153 declarationsFor mn =
176 declarationsFor mn =
154 if mn == modName
177 if mn == modName
@@ -261,6 +284,13 @@ testCases =
261 , ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "anInt" (ShowFn (P.tyInt ==))
284 , ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "anInt" (ShowFn (P.tyInt ==))
262 , ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "aNumber" (ShowFn (P.tyNumber ==))
285 , ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "aNumber" (ShowFn (P.tyNumber ==))
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"