diff --git a/examples/docs/src/ChildDeclOrder.purs b/examples/docs/src/ChildDeclOrder.purs new file mode 100644 index 0000000000..7f677856e7 --- /dev/null +++ b/examples/docs/src/ChildDeclOrder.purs @@ -0,0 +1,27 @@ +-- Tests should ensure that, in the docs: +-- - First should come before Second +-- - foo1 should be listed before foo2 +-- - the instances should be listed in the same order as this source file +module ChildDeclOrder where + +data Two + = First + | Second + +class Show a where + show :: a -> String + +class Foo a where + foo1 :: a + foo2 :: a + +instance showTwo :: Show Two where + show _ = "" + +instance fooTwo :: Foo Two where + foo1 = First + foo2 = Second + +instance fooInt :: Foo Int where + foo1 = 1 + foo2 = 2 diff --git a/src/Language/PureScript/Docs/AsHtml.hs b/src/Language/PureScript/Docs/AsHtml.hs index cc1568d35f..f7f3ba1e03 100644 --- a/src/Language/PureScript/Docs/AsHtml.hs +++ b/src/Language/PureScript/Docs/AsHtml.hs @@ -294,10 +294,13 @@ withClass className content = H.span ! A.class_ (fromString className) $ content partitionChildren :: [ChildDeclaration] -> ([ChildDeclaration], [ChildDeclaration], [ChildDeclaration]) -partitionChildren = foldl go ([], [], []) +partitionChildren = + reverseAll . foldl go ([], [], []) where go (instances, dctors, members) rcd = case cdeclInfo rcd of ChildInstance _ _ -> (rcd : instances, dctors, members) ChildDataConstructor _ -> (instances, rcd : dctors, members) ChildTypeClassMember _ -> (instances, dctors, rcd : members) + + reverseAll (xs, ys, zs) = (reverse xs, reverse ys, reverse zs) diff --git a/tests/TestDocs.hs b/tests/TestDocs.hs index 0237bfee8f..d3dbbdbd35 100644 --- a/tests/TestDocs.hs +++ b/tests/TestDocs.hs @@ -13,7 +13,6 @@ import Control.Arrow (first) import Control.Monad.IO.Class (liftIO) import Data.Foldable -import Data.List ((\\)) import Data.Maybe (fromMaybe) import Data.Monoid import Data.Text (Text) @@ -99,7 +98,7 @@ instance Show (ShowFn a) where data AssertionFailure -- | A declaration was not documented, but should have been = NotDocumented P.ModuleName Text - -- | A child declaration was not documented, but should have been + -- | The expected list of child declarations did not match the actual list | ChildrenNotDocumented P.ModuleName Text [Text] -- | A declaration was documented, but should not have been | Documented P.ModuleName Text @@ -152,9 +151,9 @@ runAssertion assertion linksCtx Docs.Module{..} = Nothing -> Fail (NotDocumented mn decl) Just actualChildren -> - case children \\ actualChildren of - [] -> Pass - cs -> Fail (ChildrenNotDocumented mn decl cs) + if children == actualChildren + then Pass + else Fail (ChildrenNotDocumented mn decl actualChildren) ShouldNotBeDocumented mn decl -> case findChildren decl (declarationsFor mn) of @@ -406,6 +405,11 @@ testCases = , ("Desugar", [ ValueShouldHaveTypeSignature (n "Desugar") "test" (renderedType "forall a b. X (a -> b) a -> b") ]) + + , ("ChildDeclOrder", + [ ShouldBeDocumented (n "ChildDeclOrder") "Two" ["First", "Second", "showTwo", "fooTwo"] + , ShouldBeDocumented (n "ChildDeclOrder") "Foo" ["foo1", "foo2", "fooTwo", "fooInt"] + ]) ] where