diff --git a/lib/src/main/scala/generator/GeneratorUtil.scala b/lib/src/main/scala/generator/GeneratorUtil.scala index 4610ed7e4..b4636d598 100644 --- a/lib/src/main/scala/generator/GeneratorUtil.scala +++ b/lib/src/main/scala/generator/GeneratorUtil.scala @@ -160,9 +160,15 @@ object GeneratorUtil { * leading indentation. */ def splitIntoLines(comment: String, maxLength: Int = 80): Seq[String] = { + comment.split("\\n").toSeq.flatMap { line => + splitLineByLength(line, maxLength) + } + } + + private[this] def splitLineByLength(comment: String, maxLength: Int = 80): Seq[String] = { val sb = new scala.collection.mutable.ListBuffer[String]() var currentWord = new StringBuilder() - comment.split(" ").map(_.trim).foreach { word => + comment.split("\\s+").map(_.trim).foreach { word => if (word.length + currentWord.length >= maxLength) { if (currentWord.nonEmpty) { sb.append(currentWord.toString) diff --git a/lib/src/test/scala/generator/GeneratorUtilSpec.scala b/lib/src/test/scala/generator/GeneratorUtilSpec.scala index b709841a4..19a5ad5d8 100644 --- a/lib/src/test/scala/generator/GeneratorUtilSpec.scala +++ b/lib/src/test/scala/generator/GeneratorUtilSpec.scala @@ -6,6 +6,14 @@ import org.scalatest.matchers.should.Matchers class GeneratorUtilSpec extends AnyFunSpec with Matchers { + it("formatComment handles newlines") { + GeneratorUtil.formatComment("test\nthis") should be(""" +# test +# this +""".trim + ) + } + it("formatComment") { GeneratorUtil.formatComment("test") should be("# test") GeneratorUtil.formatComment("test this") should be("# test this")