Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions examples/docs/src/ChildDeclOrder.purs
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion src/Language/PureScript/Docs/AsHtml.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
14 changes: 9 additions & 5 deletions tests/TestDocs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down