@@ -3,6 +3,10 @@ package site
3
3
4
4
import org .junit .Test
5
5
import org .junit .Assert ._
6
+ import dotty .tools .scaladoc .site .Sidebar
7
+ import dotty .tools .scaladoc .site .Sidebar .RawInput
8
+ import java .io .ByteArrayOutputStream
9
+ import java .io .PrintStream
6
10
7
11
// TODO add negaitve and more details tests
8
12
class SidebarParserTest :
@@ -34,10 +38,10 @@ class SidebarParserTest:
34
38
| - page: my-page6/my-page6/my-page6.md
35
39
""" .stripMargin
36
40
37
- private val sidebarErrorNoTitle =
38
- """ index: index.md
41
+ private val sidebarErrorNoPage =
42
+ """ index: index.md
39
43
|subsection:
40
- | page: my-page1.md
44
+ | - title: My title
41
45
| - page: my-page2.md
42
46
| - page: my-page3/subsection
43
47
| - title: Reference
@@ -60,28 +64,12 @@ class SidebarParserTest:
60
64
| - page: my-page6/my-page6/my-page6.md
61
65
""" .stripMargin
62
66
63
- private val msg = " Error parsing YAML configuration file: Title is not provided."
67
+ private val msgNoTitle = " Error parsing YAML configuration file: Title is not provided."
68
+ private val msgNoPage = " Error parsing YAML configuration file: Index or page path to at least one page is missing."
64
69
65
- private def schemaMessage : String =
66
- s """ Static site YAML configuration file should comply with the following description:
67
- |The root element of static site needs to be <subsection>
68
- |`title` and `directory` properties are ignored in root subsection.
69
- |
70
- |<subsection>:
71
- | title: <string> # optional - Default value is file name. Title can be also set using front-matter.
72
- | index: <string> # optional - If not provided, default empty index template is generated.
73
- | directory: <string> # optional - By default, directory name is title name in kebab case.
74
- | subsection: # optional - If not provided, pages are loaded from the index directory
75
- | - <subsection> | <page>
76
- | # either index or subsection needs to be present
77
- |<page>:
78
- | title: <string> # optional - Default value is file name. Title can be also set using front-matter.
79
- | page: <string>
80
- | hidden: <boolean> # optional - Default value is false.
81
- |
82
- |For more information visit:
83
- |https://docs.scala-lang.org/scala3/guides/scaladoc/static-site.html
84
- | """ .stripMargin
70
+ private def schemaMessage : String = Sidebar .schemaMessage
71
+
72
+ private val noPageExpectedError = s " $msgNoPage\n $schemaMessage\n Page my-page2.md does not exist. \n Page my-page3/subsection does not exist. \n Page my-page3.md does not exist. \n Page my-page4/my-page4.md does not exist. \n Page my-page5/my-page5.md does not exist. \n Page my-page7/my-page7.md does not exist. \n Page my-page6/my-page6/my-page6.md does not exist. "
85
73
86
74
@ Test
87
75
def loadSidebar (): Unit = assertEquals(
@@ -103,15 +91,11 @@ class SidebarParserTest:
103
91
Sidebar .load(sidebar)(using testContext)
104
92
)
105
93
106
- @ Test (expected = classOf [ IllegalArgumentException ])
94
+ @ Test
107
95
def loadSidebarError (): Unit =
108
- assertEquals(
109
- Sidebar .Category (
110
- None ,
111
- None ,
112
- List (),
113
- None
114
- ),
115
- Sidebar .load(sidebarErrorNoTitle)(using testContext)
116
- )
117
- throw new IllegalArgumentException (s " $msg\n $schemaMessage" )
96
+ val out = new ByteArrayOutputStream ()
97
+ Console .withErr(new PrintStream (out)) {
98
+ Sidebar .load(sidebarErrorNoPage)(using testContext)
99
+ }
100
+ val error = out.toString().trim()
101
+ assertEquals(noPageExpectedError, error)
0 commit comments