Skip to content

Refactor: Path validation and SiderbarParserTest #18000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2023
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
8 changes: 8 additions & 0 deletions scaladoc/src/dotty/tools/scaladoc/site/SidebarParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ object Sidebar:

private def toSidebar(r: RawInput, content: String | java.io.File)(using CompilerContext): Sidebar = r match
case RawInput(title, page, index, subsection, dir, hidden) if page.nonEmpty && index.isEmpty && subsection.isEmpty() =>
val pagePath = content match
case f: java.io.File =>
val pagePath = f.toPath()
.getParent()
.resolve(s"_docs/$page")
if !Files.exists(pagePath) then
report.error(s"Page $page does not exist.")
case s: String => None
Sidebar.Page(Option.when(title.nonEmpty)(title), page, hidden)
case RawInput(title, page, index, subsection, dir, hidden) if page.isEmpty && (!subsection.isEmpty() || !index.isEmpty()) =>
Sidebar.Category(Option.when(title.nonEmpty)(title), Option.when(index.nonEmpty)(index), subsection.asScala.map(toSidebar(_, content)).toList, Option.when(dir.nonEmpty)(dir))
Expand Down
12 changes: 5 additions & 7 deletions scaladoc/test/dotty/tools/scaladoc/site/SidebarParserTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class SidebarParserTest:
private val sidebarNoTitle =
"""index: index.md
|subsection:
| - title: My title
| page: my-page1.md
| - page: my-page2.md
| - page: my-page3/subsection
Expand All @@ -57,7 +56,7 @@ class SidebarParserTest:
| subsection:
| - page: my-page5/my-page5.md
| - subsection:
| page: my-page7/my-page7.md
| - page: my-page7/my-page7.md
| - index: my-page6/index.md
| subsection:
| - index: my-page6/my-page6/index.md
Expand Down Expand Up @@ -122,10 +121,9 @@ class SidebarParserTest:
Console.withErr(new PrintStream(out)) {
Sidebar.load(sidebarErrorNoPage)(using testContext)
}
println(out.toString())
val error = out.toString().trim()
val errorPage = out.toString().trim()

assert(error.contains(msgNoPage) && error.contains(schemaMessage))
assert(errorPage.contains(msgNoPage) && errorPage.contains(schemaMessage))


@Test
Expand All @@ -134,6 +132,6 @@ class SidebarParserTest:
Console.withErr(new PrintStream(out)) {
Sidebar.load(sidebarNoTitle)(using testContext)
}
val error = out.toString().trim()
val errorTitle = out.toString().trim()

assert(error.contains(msgNoTitle) && error.contains(schemaMessage))
assert(errorTitle.contains(msgNoTitle) && errorTitle.contains(schemaMessage))