mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-05-17 10:30:35 +00:00
Fix bug where acronyms rule would incorrectly always capitalize potentially matching acronyms one letter before end of identifier (#2226)
This commit is contained in:
@@ -27,7 +27,7 @@ public extension FormatRule {
|
||||
for replaceCandidateRange in token.string.ranges(of: find) {
|
||||
let acronymShouldBeCapitalized: Bool
|
||||
|
||||
if replaceCandidateRange.upperBound < token.string.indices.last! {
|
||||
if replaceCandidateRange.upperBound <= token.string.indices.last! {
|
||||
let indexAfterMatch = replaceCandidateRange.upperBound
|
||||
let characterAfterMatch = token.string[indexAfterMatch]
|
||||
|
||||
|
||||
@@ -90,4 +90,20 @@ class AcronymsTests: XCTestCase {
|
||||
let options = FormatOptions(preserveAcronyms: ["externallyProvidedUrl", "toUrl"])
|
||||
testFormatting(for: input, output, rule: .acronyms, options: options)
|
||||
}
|
||||
|
||||
func testAcronymMatchesPartOfOtherWordAtEndOfIdentifier() {
|
||||
let input = """
|
||||
struct MasKit {}
|
||||
struct Mask {}
|
||||
struct MaskView {}
|
||||
"""
|
||||
|
||||
let output = """
|
||||
struct MASKit {}
|
||||
struct Mask {}
|
||||
struct MaskView {}
|
||||
"""
|
||||
|
||||
testFormatting(for: input, output, rule: .acronyms, options: FormatOptions(acronyms: ["MAS"]))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user