Skip to content

Commit 810ddf7

Browse files
committed
Apply requested changes to diagram tests
1 parent 0021d97 commit 810ddf7

File tree

2 files changed

+103
-103
lines changed

2 files changed

+103
-103
lines changed

scala3doc/src/dotty/dokka/model/api/membersUtils.scala

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ import scala.jdk.CollectionConverters.{ListHasAsScala, SeqHasAsJava}
55
import dotty.dokka.model.api._
66

77
extension (m: DModule)
8-
def visitMembers(callback: Member => Unit): Unit =
9-
def visitClasslike(c: Member, callback: Member => Unit): Unit =
10-
callback(c)
11-
c.allMembers.foreach(visitClasslike(_, callback))
12-
m.getPackages.asScala.foreach(_.allMembers.foreach(visitClasslike(_, callback)))
8+
def visitMembers(callback: Member => Unit): Unit =
9+
def visitClasslike(c: Member): Unit =
10+
callback(c)
11+
c.allMembers.foreach(visitClasslike(_))
12+
m.getPackages.asScala.foreach(_.allMembers.foreach(visitClasslike(_)))
1313

1414
extension (s: Signature)
15-
def getName: String =
16-
s.map { _ match
17-
case s: String => s
18-
case l: Link => l.name
19-
}.mkString
15+
def getName: String =
16+
s.map {
17+
case s: String => s
18+
case l: Link => l.name
19+
}.mkString
2020

2121
extension (m: Member):
22-
def getDirectParentsAsStrings: Seq[String] =
23-
m.directParents.map(_.getName).sorted
24-
def getParentsAsStrings: Seq[String] =
25-
m.parents.map(_.signature.getName).sorted
26-
def getKnownChildrenAsStrings: Seq[String] =
27-
m.knownChildren.map(_.signature.getName).sorted
22+
def getDirectParentsAsStrings: Seq[String] =
23+
m.directParents.map(_.getName).sorted
24+
def getParentsAsStrings: Seq[String] =
25+
m.parents.map(_.signature.getName).sorted
26+
def getKnownChildrenAsStrings: Seq[String] =
27+
m.knownChildren.map(_.signature.getName).sorted

scala3doc/test/dotty/dokka/diagram/HierarchyTest.scala

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -8,91 +8,91 @@ import scala.jdk.CollectionConverters.{ListHasAsScala, SeqHasAsJava}
88
import org.junit.Assert.{assertSame, assertTrue, assertEquals}
99

1010
class HierarchyTest extends ScaladocTest("hierarchy"):
11-
override def assertions = Seq(
12-
AfterDocumentablesTransformation { m =>
13-
m.visitMembers { x =>
14-
if (x.getName == "C1") {
15-
assertEquals(List("A1", "A2[Int]", "A3[Int, String]", "Any", "B1", "B2", "B3", "Object"), x.getParentsAsStrings)
16-
assertEquals(List("B1", "B2", "B3"), x.getDirectParentsAsStrings)
17-
assertEquals(List("E1", "E2"), x.getKnownChildrenAsStrings)
18-
val graph = MemberExtension.getFrom(x).map(_.graph)
19-
assertEquals(true, graph.isDefined)
20-
assertEquals(
21-
Seq(
22-
"Object" -> "Any",
23-
"A1" -> "Object",
24-
"A2[Int]" -> "Object",
25-
"A3[Int, String]" -> "Object",
26-
"B1" -> "Object",
27-
"B1" -> "A1",
28-
"B2" -> "Object",
29-
"B2" -> "A1",
30-
"B2" -> "A2[Int]",
31-
"B3" -> "Object",
32-
"B3" -> "A2[Int]",
33-
"B3" -> "A3[Int, String]",
34-
"C1[A, B, C]" -> "Object",
35-
"C1[A, B, C]" -> "B1",
36-
"C1[A, B, C]" -> "B2",
37-
"C1[A, B, C]" -> "B3",
38-
"E1" -> "C1[A, B, C]",
39-
"E2" -> "C1[A, B, C]"
40-
).sorted,
41-
graph.get.edges.map((a, b) => (a.signature.getName, b.signature.getName)).sorted
42-
)
43-
}
44-
if (x.getName == "E2") {
45-
assertEquals(List("A1", "A2[Int]", "A3[Int, String]", "Any", "B1", "B2", "B3", "C1[Int, Boolean, Any]", "D2[Int, Boolean]", "D3", "Object"), x.getParentsAsStrings)
46-
assertEquals(List("C1[Int, Boolean, Any]", "D2[Int, Boolean]", "D3"), x.getDirectParentsAsStrings)
47-
assertEquals(List.empty, x.getKnownChildrenAsStrings)
48-
val graph = MemberExtension.getFrom(x).map(_.graph)
49-
assertEquals(true, graph.isDefined)
50-
assertEquals(
51-
Seq(
52-
"Object" -> "Any",
53-
// "A1" -> "Object", // These are not applicable beacuase of bug and its workaround
54-
// "A2[Int]" -> "Object", // More info at ClassLikeSupport.scala:37
55-
// "A3[Int, String]" -> "Object",
56-
// "B1" -> "Object",
57-
// "B1" -> "A1",
58-
// "B2" -> "Object",
59-
// "B2" -> "A1",
60-
// "B2" -> "A2[Int]",
61-
// "B3" -> "Object",
62-
// "B3" -> "A2[Int]",
63-
// "B3" -> "A3[Int, String]",
64-
// "C1[Int, Boolean, Any]" -> "Object",
65-
// "C1[Int, Boolean, Any]" -> "B1",
66-
// "C1[Int, Boolean, Any]" -> "B2",
67-
// "C1[Int, Boolean, Any]" -> "B3",
68-
"E2" -> "D2[Int, Boolean]",
69-
"E2" -> "D3",
70-
"D2[Int, Boolean]" -> "Object",
71-
"D3" -> "Object",
72-
"E2" -> "C1[Int, Boolean, Any]"
73-
).sorted,
74-
graph.get.edges.map((a, b) => (a.signature.getName, b.signature.getName)).sorted
75-
)
76-
}
77-
if (x.getName == "A2") {
78-
assertEquals(List("Any", "Object"), x.getParentsAsStrings)
79-
assertEquals(List.empty, x.getDirectParentsAsStrings)
80-
assertEquals(List("B2", "B3", "C1[A, B, C]", "E1", "E2"), x.getKnownChildrenAsStrings)
81-
val graph = MemberExtension.getFrom(x).map(_.graph)
82-
assertEquals(true, graph.isDefined)
83-
assertEquals(
84-
Seq(
85-
"Object" -> "Any",
86-
"A2[T]" -> "Object",
87-
"B2" -> "A2[T]", // These are not actually true, becuase we lose information about hierarchy in subtypes and their possible mapping to supertypes other that that type itself, e. g. linking to `Object`
88-
"B3" -> "A2[T]",
89-
"C1[A, B, C]" -> "A2[T]",
90-
"E1" -> "A2[T]",
91-
"E2" -> "A2[T]"
92-
).sorted,
93-
graph.get.edges.map((a, b) => (a.signature.getName, b.signature.getName)).sorted
94-
)
95-
}
96-
}
11+
override def assertions = Seq(
12+
AfterDocumentablesTransformation { m =>
13+
m.visitMembers { x =>
14+
if (x.getName == "C1") {
15+
assertEquals(List("A1", "A2[Int]", "A3[Int, String]", "Any", "B1", "B2", "B3", "Object"), x.getParentsAsStrings)
16+
assertEquals(List("B1", "B2", "B3"), x.getDirectParentsAsStrings)
17+
assertEquals(List("E1", "E2"), x.getKnownChildrenAsStrings)
18+
val graph = MemberExtension.getFrom(x).map(_.graph)
19+
assertTrue("Graph is empty!", graph.isDefined)
20+
assertEquals(
21+
Set(
22+
"Object" -> "Any",
23+
"A1" -> "Object",
24+
"A2[Int]" -> "Object",
25+
"A3[Int, String]" -> "Object",
26+
"B1" -> "Object",
27+
"B1" -> "A1",
28+
"B2" -> "Object",
29+
"B2" -> "A1",
30+
"B2" -> "A2[Int]",
31+
"B3" -> "Object",
32+
"B3" -> "A2[Int]",
33+
"B3" -> "A3[Int, String]",
34+
"C1[A, B, C]" -> "Object",
35+
"C1[A, B, C]" -> "B1",
36+
"C1[A, B, C]" -> "B2",
37+
"C1[A, B, C]" -> "B3",
38+
"E1" -> "C1[A, B, C]",
39+
"E2" -> "C1[A, B, C]"
40+
),
41+
graph.get.edges.map((a, b) => (a.signature.getName, b.signature.getName)).toSet
42+
)
9743
}
98-
)
44+
if (x.getName == "E2") {
45+
assertEquals(List("A1", "A2[Int]", "A3[Int, String]", "Any", "B1", "B2", "B3", "C1[Int, Boolean, Any]", "D2[Int, Boolean]", "D3", "Object"), x.getParentsAsStrings)
46+
assertEquals(List("C1[Int, Boolean, Any]", "D2[Int, Boolean]", "D3"), x.getDirectParentsAsStrings)
47+
assertEquals(List.empty, x.getKnownChildrenAsStrings)
48+
val graph = MemberExtension.getFrom(x).map(_.graph)
49+
assertTrue("Graph is empty!", graph.isDefined)
50+
assertEquals(
51+
Set(
52+
"Object" -> "Any",
53+
// "A1" -> "Object", // These are not applicable beacuase of bug and its workaround
54+
// "A2[Int]" -> "Object", // More info at ClassLikeSupport.scala:37
55+
// "A3[Int, String]" -> "Object",
56+
// "B1" -> "Object",
57+
// "B1" -> "A1",
58+
// "B2" -> "Object",
59+
// "B2" -> "A1",
60+
// "B2" -> "A2[Int]",
61+
// "B3" -> "Object",
62+
// "B3" -> "A2[Int]",
63+
// "B3" -> "A3[Int, String]",
64+
// "C1[Int, Boolean, Any]" -> "Object",
65+
// "C1[Int, Boolean, Any]" -> "B1",
66+
// "C1[Int, Boolean, Any]" -> "B2",
67+
// "C1[Int, Boolean, Any]" -> "B3",
68+
"E2" -> "D2[Int, Boolean]",
69+
"E2" -> "D3",
70+
"D2[Int, Boolean]" -> "Object",
71+
"D3" -> "Object",
72+
"E2" -> "C1[Int, Boolean, Any]"
73+
),
74+
graph.get.edges.map((a, b) => (a.signature.getName, b.signature.getName)).toSet
75+
)
76+
}
77+
if (x.getName == "A2") {
78+
assertEquals(List("Any", "Object"), x.getParentsAsStrings)
79+
assertEquals(List.empty, x.getDirectParentsAsStrings)
80+
assertEquals(List("B2", "B3", "C1[A, B, C]", "E1", "E2"), x.getKnownChildrenAsStrings)
81+
val graph = MemberExtension.getFrom(x).map(_.graph)
82+
assertTrue("Graph is empty!", graph.isDefined)
83+
assertEquals(
84+
Set(
85+
"Object" -> "Any",
86+
"A2[T]" -> "Object",
87+
"B2" -> "A2[T]", // These are not actually true, becuase we lose information about hierarchy in subtypes and their possible mapping to supertypes other that that type itself, e. g. linking to `Object`
88+
"B3" -> "A2[T]",
89+
"C1[A, B, C]" -> "A2[T]",
90+
"E1" -> "A2[T]",
91+
"E2" -> "A2[T]"
92+
),
93+
graph.get.edges.map((a, b) => (a.signature.getName, b.signature.getName)).toSet
94+
)
95+
}
96+
}
97+
}
98+
)

0 commit comments

Comments
 (0)