@@ -9,6 +9,7 @@ import com.quarkdown.core.pipeline.output.OutputResource
99import com.quarkdown.core.pipeline.output.TextOutputArtifact
1010import com.quarkdown.test.util.execute
1111import com.quarkdown.test.util.getSubResources
12+ import java.io.File
1213import kotlin.test.Test
1314import kotlin.test.assertContains
1415import kotlin.test.assertEquals
@@ -55,7 +56,7 @@ class SubdocumentTest {
5556 @Test
5657 fun `root to subdocument` () {
5758 execute(
58- source = " " ,
59+ " " ,
5960 subdocumentGraph = { it.addVertex(simpleSubdoc).addEdge(Subdocument .Root , simpleSubdoc) },
6061 outputResourceHook = { group ->
6162 val resource = getResource(group, simpleSubdoc, this )
@@ -70,7 +71,7 @@ class SubdocumentTest {
7071 @Test
7172 fun `collision-proof subdocument name` () {
7273 execute(
73- source = " " ,
74+ " " ,
7475 subdocumentGraph = { it.addVertex(simpleSubdoc).addEdge(Subdocument .Root , simpleSubdoc) },
7576 minimizeSubdocumentCollisions = true ,
7677 outputResourceHook = { group ->
@@ -84,13 +85,12 @@ class SubdocumentTest {
8485 @Test
8586 fun `context should be shared to subdocument` () {
8687 execute(
87- source =
88- """
89- .doctype {paged}
90-
91- .function {$NON_EXISTENT_FUNCTION }
92- hello
93- """ .trimIndent(),
88+ """
89+ .doctype {paged}
90+
91+ .function {$NON_EXISTENT_FUNCTION }
92+ hello
93+ """ .trimIndent(),
9494 subdocumentGraph = {
9595 it.addVertex(referenceToParentSubdoc).addEdge(Subdocument .Root , referenceToParentSubdoc)
9696 },
@@ -105,7 +105,7 @@ class SubdocumentTest {
105105 @Test
106106 fun `context should not be shared from subdocument to parent` () {
107107 execute(
108- source = " .doctype {paged}" ,
108+ " .doctype {paged}" ,
109109 subdocumentGraph = { it.addVertex(definitionSubdoc).addEdge(Subdocument .Root , definitionSubdoc) },
110110 outputResourceHook = {
111111 assertEquals(DocumentType .PAGED , documentInfo.type)
@@ -117,7 +117,7 @@ class SubdocumentTest {
117117 @Test
118118 fun `third-party presence should be shared from subdocument to parent` () {
119119 execute(
120- source = " " ,
120+ " " ,
121121 subdocumentGraph = { it.addVertex(thirdPartySubdoc).addEdge(Subdocument .Root , thirdPartySubdoc) },
122122 outputResourceHook = {
123123 assertTrue(attributes.hasMermaidDiagram)
@@ -127,48 +127,108 @@ class SubdocumentTest {
127127
128128 @Test
129129 fun `simple subdocument from file` () {
130- execute(
131- source = " [1](subdoc/simple-1.qd)" ,
132- outputResourceHook = {
133- assertEquals(2 , subdocumentGraph.vertices.size)
134- assertEquals(2 , getTextResourceCount(it))
135- },
136- ) {
137- if (subdocument == Subdocument .Root ) {
138- assertEquals(" <p><a href=\" ./simple-1.html\" >1</a></p>" , it)
130+ arrayOf(
131+ " The link is: [1](subdoc/simple-1.qd)" ,
132+ " The link is: .subdocument {subdoc/simple-1.qd} label:{1}" ,
133+ ).forEach { source ->
134+ execute(
135+ source,
136+ outputResourceHook = {
137+ assertEquals(2 , subdocumentGraph.vertices.size)
138+ assertEquals(2 , getTextResourceCount(it))
139+ },
140+ ) {
141+ if (subdocument == Subdocument .Root ) {
142+ assertEquals(" <p>The link is: <a href=\" ./simple-1.html\" >1</a></p>" , it)
143+ }
144+ }
145+ }
146+ }
147+
148+ @Test
149+ fun `empty label subdocument from file` () {
150+ arrayOf(
151+ " The link is: [](subdoc/simple-1.qd)" ,
152+ " The link is: .subdocument {subdoc/simple-1.qd}" ,
153+ ).forEach { source ->
154+ execute(
155+ source,
156+ outputResourceHook = {
157+ assertEquals(2 , subdocumentGraph.vertices.size)
158+ assertEquals(2 , getTextResourceCount(it))
159+ },
160+ ) {
161+ if (subdocument == Subdocument .Root ) {
162+ assertEquals(" <p>The link is: <a href=\" ./simple-1.html\" ></a></p>" , it)
163+ }
139164 }
140165 }
141166 }
142167
143168 @Test
144169 fun `root to gateway to 1 and 2` () {
145- execute(
146- source = " [Gateway](subdoc/gateway.qd)" ,
147- outputResourceHook = {
148- assertEquals(4 , subdocumentGraph.vertices.size)
149- assertEquals(4 , getTextResourceCount(it))
150- },
151- ) {}
170+ arrayOf(
171+ " [Gateway](subdoc/gateway.qd)" ,
172+ " .subdocument {subdoc/gateway.qd} label:{Gateway}" ,
173+ ).forEach { source ->
174+ execute(
175+ source,
176+ outputResourceHook = {
177+ assertEquals(4 , subdocumentGraph.vertices.size)
178+ assertEquals(4 , getTextResourceCount(it))
179+ },
180+ ) {}
181+ }
152182 }
153183
154184 @Test
155185 fun `circular, root to 1 to 2 to 1` () {
156- execute(
157- source = " [1](subdoc/circular-1.qd)" ,
158- outputResourceHook = {
159- assertEquals(3 , subdocumentGraph.vertices.size)
160- assertEquals(3 , getTextResourceCount(it))
161- },
162- ) {}
186+ arrayOf(
187+ " [1](subdoc/circular-1.qd)" ,
188+ " .subdocument {subdoc/circular-1.qd} label:{1}" ,
189+ ).forEach { source ->
190+ execute(
191+ source,
192+ outputResourceHook = {
193+ assertEquals(3 , subdocumentGraph.vertices.size)
194+ assertEquals(3 , getTextResourceCount(it))
195+ },
196+ ) {}
197+ }
163198 }
164199
165200 @Test
166201 fun `recursive, root to 1 recursively` () {
202+ arrayOf(
203+ " [1](subdoc/recursive.qd)" ,
204+ " .subdocument {subdoc/recursive.qd} label:{1}" ,
205+ ).forEach { source ->
206+ execute(
207+ source,
208+ outputResourceHook = {
209+ assertEquals(2 , subdocumentGraph.vertices.size)
210+ assertEquals(2 , getTextResourceCount(it))
211+ },
212+ ) {}
213+ }
214+ }
215+
216+ @Test
217+ fun `all from directory` () {
167218 execute(
168- source = " [1](subdoc/recursive.qd)" ,
219+ """
220+ .foreach {.listfiles {subdoc} sortby:{name}}
221+ path:
222+ .path::subdocument label:{.path::filename extension:{no}}
223+ """ .trimIndent(),
169224 outputResourceHook = {
170- assertEquals(2 , subdocumentGraph.vertices.size)
171- assertEquals(2 , getTextResourceCount(it))
225+ val files = File (fileSystem.workingDirectory, " subdoc" ).listFiles()!!
226+ assertEquals(files.size + 1 , subdocumentGraph.vertices.size) // +1 for root
227+
228+ files.forEach { file ->
229+ val subdocName = file.nameWithoutExtension
230+ assertTrue(subdocumentGraph.vertices.any { vertex -> vertex.name.startsWith(subdocName) })
231+ }
172232 },
173233 ) {}
174234 }
0 commit comments