Skip to content

Commit

Permalink
Generate multiline comments properly (Closes #11)
Browse files Browse the repository at this point in the history
  • Loading branch information
liamnichols committed Sep 26, 2023
1 parent afe7601 commit 304c80d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
17 changes: 8 additions & 9 deletions Sources/StringGenerator/StringGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,16 @@ extension Resource {
}

var leadingTrivia: Trivia {
let commentTrivia: [TriviaPiece] = if let comment {
comment
.components(separatedBy: .newlines)
.map { TriviaPiece.docLineComment("/// \($0)") }
} else {
[]
var trivia: Trivia = .newlines(2)

if let commentLines = comment?.components(separatedBy: .newlines), !commentLines.isEmpty {
for line in commentLines {
trivia = trivia.appending(Trivia.docLineComment("/// \(line)"))
trivia = trivia.appending(.newline)
}
}

return .newlines(2)
.merging(Trivia(pieces: commentTrivia))
.merging(.newline)
return trivia
}

func statements(table: String, bundle: TokenSyntax) -> CodeBlockItemListSyntax {
Expand Down
14 changes: 14 additions & 0 deletions Tests/LocalizationTests/StringGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ final class StringGeneratorTests: XCTestCase {
XCTAssertNotNil(output)
}

func testGenerateMultilineComment() {
let output = generate([
Resource(
key: "foo",
comment: "A comment\n\nA comment that covers many lines.",
identifier: "foo",
arguments: [],
defaultValue: [.string("FOO")]
)
])

XCTAssertNotNil(output)
}

private func generate(
_ resources: [Resource],
tableName: String = "Localizable",
Expand Down

0 comments on commit 304c80d

Please sign in to comment.