@@ -28,7 +28,7 @@ func assertOutput(
2828 _ mode: JExtractGenerationMode ,
2929 _ renderKind: RenderKind ,
3030 swiftModuleName: String = " SwiftModule " ,
31- detectChunkByInitialLines: Int = 4 ,
31+ detectChunkByInitialLines _detectChunkByInitialLines : Int = 4 ,
3232 expectedChunks: [ String ] ,
3333 fileID: String = #fileID,
3434 filePath: String = #filePath,
@@ -79,19 +79,22 @@ func assertOutput(
7979 let gotLines = output. split ( separator: " \n " ) . filter { l in
8080 l. trimmingCharacters ( in: CharacterSet . whitespacesAndNewlines) . count > 0
8181 }
82- for expected in expectedChunks {
83- let expectedLines = expected. split ( separator: " \n " )
82+ for expectedChunk in expectedChunks {
83+ let expectedLines = expectedChunk. split ( separator: " \n " )
84+ let detectChunkByInitialLines = min ( expectedLines. count, _detectChunkByInitialLines)
85+ precondition ( detectChunkByInitialLines > 0 , " Chunk size to detect cannot be zero lines! " )
8486
8587 var matchingOutputOffset : Int ? = nil
8688 let expectedInitialMatchingLines = expectedLines [ 0 ..< min ( expectedLines. count, detectChunkByInitialLines) ]
8789 . map ( { $0. trimmingCharacters ( in: . whitespacesAndNewlines) } )
8890 . joined ( separator: " \n " )
89- for offset in 0 ..< gotLines. count where gotLines. count > ( offset+ detectChunkByInitialLines) {
90- let textLinesAtOffset = gotLines [ offset..< offset+ detectChunkByInitialLines]
91+
92+ for lineOffset in 0 ..< gotLines. count where gotLines. count > ( lineOffset+ detectChunkByInitialLines) {
93+ let textLinesAtOffset = gotLines [ lineOffset..< lineOffset+ detectChunkByInitialLines]
9194 . map ( { $0. trimmingCharacters ( in: . whitespacesAndNewlines) } )
9295 . joined ( separator: " \n " )
9396 if textLinesAtOffset == expectedInitialMatchingLines {
94- matchingOutputOffset = offset
97+ matchingOutputOffset = lineOffset
9598 break
9699 }
97100 }
@@ -105,13 +108,13 @@ func assertOutput(
105108
106109 print ( " ==== --------------------------------------------------------------- " )
107110 print ( " Expected output: " )
108- print ( expected . yellow)
111+ print ( " ' \( expectedChunk . yellow) ' " )
109112 print ( " ==== --------------------------------------------------------------- " )
110113 print ( " Got output: " )
111114 print ( output)
112115 print ( " ==== --------------------------------------------------------------- " )
113116
114- #expect( output. contains ( expected ) , sourceLocation: sourceLocation)
117+ #expect( output. contains ( expectedChunk ) , sourceLocation: sourceLocation)
115118 fatalError ( " Failed: \( filePath) : \( line) " )
116119 continue
117120 }
0 commit comments