@@ -67,13 +67,12 @@ open class AsciiDocTestSuite(
67
67
private var currentDocumentLevel: DocumentLevel ? = null
68
68
private var currentDepth = 0
69
69
70
- private val globalCodeBlocks = mutableMapOf<String , ParsedBlock >()
71
- private var codeBlocksOfTest = mutableMapOf<String , ParsedBlock >()
70
+ private val globalCodeBlocks = mutableMapOf<String , MutableList < ParsedBlock > >()
71
+ private var codeBlocksOfTest = mutableMapOf<String , MutableList < ParsedBlock > >()
72
72
73
73
fun parse (): Stream <DynamicNode > {
74
- val file = File (AsciiDocTestSuite ::class .java.getResource(" /$fileName " ).toURI())
74
+ val file = File (AsciiDocTestSuite ::class .java.getResource(" /$fileName " )? .toURI()!! )
75
75
val lines = file.readLines()
76
- val terminatorElement = testCaseMarkers.lastOrNull()
77
76
78
77
var title: String? = null
79
78
var currentBlock: ParsedBlock ? = null
@@ -92,11 +91,17 @@ open class AsciiDocTestSuite(
92
91
val headlineMatcher = HEADLINE_PATTERN .matcher(line)
93
92
94
93
when {
95
- ! globalDone && globalMarkers.contains(line) -> currentBlock = startBlock(line, lineNr, globalCodeBlocks)
94
+ ! globalDone && globalMarkers.contains(line) -> currentBlock =
95
+ startBlock(line, lineNr, globalCodeBlocks)
96
96
testCaseMarkers.contains(line) -> {
97
97
globalDone = true
98
98
currentBlock = startBlock(line, lineNr, codeBlocksOfTest)
99
99
}
100
+ line == " '''" -> {
101
+ createTests(title, lineNr, ignore)
102
+ currentBlock = null
103
+ ignore = false
104
+ }
100
105
line == " ----" -> {
101
106
inside = ! inside
102
107
if (inside) {
@@ -111,16 +116,10 @@ open class AsciiDocTestSuite(
111
116
SCHEMA_MARKER -> {
112
117
val schemaTests = schemaTestFactory(currentBlock.code())
113
118
currentDocumentLevel?.tests?.add(schemaTests)
114
- if (terminatorElement == null ) {
119
+ if (testCaseMarkers.isEmpty()) {
115
120
break @loop
116
121
}
117
122
}
118
-
119
- terminatorElement -> {
120
- createTests(title, lineNr, ignore)
121
- currentBlock = null
122
- ignore = false
123
- }
124
123
}
125
124
126
125
}
@@ -143,15 +142,22 @@ open class AsciiDocTestSuite(
143
142
144
143
if (UPDATE_TEST_FILE ) {
145
144
// this test prints out the adjusted test file
146
- root?.afterTests?.add(DynamicTest .dynamicTest(" Write updated Testfile" , srcLocation, this @AsciiDocTestSuite::writeAdjustedTestFile))
145
+ root?.afterTests?.add(
146
+ DynamicTest .dynamicTest(" Write updated Testfile" , srcLocation, this @AsciiDocTestSuite::writeAdjustedTestFile)
147
+ )
147
148
} else if (GENERATE_TEST_FILE_DIFF ) {
148
149
// this test prints out the adjusted test file
149
- root?.afterTests?.add(DynamicTest .dynamicTest(" Adjusted Tests" , srcLocation, this @AsciiDocTestSuite::printAdjustedTestFile))
150
+ root?.afterTests?.add(
151
+ DynamicTest .dynamicTest(" Adjusted Tests" , srcLocation, this @AsciiDocTestSuite::printAdjustedTestFile)
152
+ )
150
153
}
151
154
return root?.generateTests() ? : Stream .empty()
152
155
}
153
156
154
157
private fun createTests (title : String? , lineNr : Int , ignore : Boolean ) {
158
+ if (codeBlocksOfTest.isEmpty()) {
159
+ throw IllegalStateException (" no code blocks for tests (line $lineNr )" )
160
+ }
155
161
val tests = testFactory(
156
162
title ? : throw IllegalStateException (" Title should be defined (line $lineNr )" ),
157
163
globalCodeBlocks,
@@ -211,33 +217,34 @@ open class AsciiDocTestSuite(
211
217
return rebuildTest.toString()
212
218
}
213
219
214
- fun startBlock (marker : String , lineIndex : Int , blocks : MutableMap <String , ParsedBlock >): ParsedBlock {
220
+ fun startBlock (marker : String , lineIndex : Int , blocks : MutableMap <String , MutableList < ParsedBlock > >): ParsedBlock {
215
221
val uri = UriBuilder .fromUri(srcLocation).queryParam(" line" , lineIndex + 1 ).build()
216
222
val block = ParsedBlock (marker, uri)
217
223
knownBlocks + = block
218
- blocks[ marker] = block
224
+ blocks.computeIfAbsent( marker) { mutableListOf () }.add( block)
219
225
return block
220
226
}
221
227
222
- protected open fun testFactory (title : String , globalBlocks : Map <String , ParsedBlock >, codeBlocks : Map <String , ParsedBlock >, ignore : Boolean ): List <DynamicNode > {
228
+ protected open fun testFactory (title : String , globalBlocks : Map <String , List < ParsedBlock >> , codeBlocks : Map <String , List < ParsedBlock > >, ignore : Boolean ): List <DynamicNode > {
223
229
return emptyList()
224
230
}
225
231
226
232
protected open fun schemaTestFactory (schema : String ): List <DynamicNode > {
227
233
return emptyList()
228
234
}
229
235
230
- protected fun getOrCreateBlock (codeBlocks : Map <String , ParsedBlock >, marker : String , headline : String ): ParsedBlock ? {
231
- var block = codeBlocks[marker]
232
- if (block == null && (GENERATE_TEST_FILE_DIFF || UPDATE_TEST_FILE )) {
236
+ protected fun getOrCreateBlocks (codeBlocks : Map <String , List < ParsedBlock >> , marker : String , headline : String ): List < ParsedBlock > {
237
+ val blocks = codeBlocks[marker]?.toMutableList() ? : mutableListOf ()
238
+ if (blocks.isEmpty() && (GENERATE_TEST_FILE_DIFF || UPDATE_TEST_FILE )) {
233
239
val insertPoints = testCaseMarkers.indexOf(marker).let { testCaseMarkers.subList(0 , it).asReversed() }
234
- val insertPoint = insertPoints.mapNotNull { codeBlocks[it] }.firstOrNull()
235
- ? : throw IllegalArgumentException (" none of the insert points $insertPoints found" )
236
- block = ParsedBlock (marker, insertPoint.uri, headline)
240
+ val insertPoint = insertPoints.mapNotNull { codeBlocks[it]?.firstOrNull() }.firstOrNull()
241
+ ? : throw IllegalArgumentException (" none of the insert points $insertPoints found in $fileName " )
242
+ val block = ParsedBlock (marker, insertPoint.uri, headline)
237
243
block.start = (insertPoint.end ? : throw IllegalStateException (" no start for block defined" )) + 6
238
- knownBlocks + = block
244
+ knownBlocks + = blocks
245
+ blocks + = block
239
246
}
240
- return block
247
+ return blocks
241
248
}
242
249
243
250
companion object {
0 commit comments