Skip to content

Commit

Permalink
Don't add a space between literals and period in BasicFormat
Browse files Browse the repository at this point in the history
Fixes apple#2344
rdar://118176218
  • Loading branch information
ahoppen committed Nov 9, 2023
1 parent a21dfa6 commit c9e4788
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/SwiftBasicFormat/BasicFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,19 @@ open class BasicFormat: SyntaxRewriter {
(.rawStringPoundDelimiter, .multilineStringQuote), // opening raw string delimiter should never be separate by a space
(.rawStringPoundDelimiter, .singleQuote), // opening raw string delimiter should never be separate by a space
(.rawStringPoundDelimiter, .stringQuote), // opening raw string delimiter should never be separate by a space
(.rawStringPoundDelimiter, .period), // opening raw string delimiter should never be separate by a space
(.regexLiteralPattern, _),
(.regexPoundDelimiter, .period), // #/myRegex/#.someMember
(.regexSlash, .regexPoundDelimiter), // closing extended regex delimiter should never be separate by a space
(.regexSlash, .period), // /myRegex/.someMember
(.rightAngle, .leftParen), // func foo<T>(x: T)
(.rightBrace, .leftParen), // { return 1 }()
(.rightParen, .leftParen), // returnsClosure()()
(.rightParen, .period), // foo().bar
(.rightSquare, .period), // myArray[1].someProperty
(.singleQuote, .rawStringPoundDelimiter), // closing raw string delimiter should never be separate by a space
(.stringQuote, .rawStringPoundDelimiter), // closing raw string delimiter should never be separate by a space
(.stringQuote, .period), // "test".lowercased
(.stringSegment, _),
(_, .comma),
(_, .ellipsis),
Expand Down
28 changes: 28 additions & 0 deletions Tests/SwiftBasicFormatTest/BasicFormatTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -503,4 +503,32 @@ final class BasicFormatTest: XCTestCase {
)
}
}

func testPeriodAfterStringLiteral() {
let source = """
"test".lowercased()
"""
assertFormatted(source: source, expected: source)
}

func testPeriodAfterRawStringLiteral() {
let source = """
#"test"#.lowercased()
"""
assertFormatted(source: source, expected: source)
}

func testPeriodAfterRegexLiteral() {
let source = """
/test/.something
"""
assertFormatted(source: source, expected: source)
}

func testPeriodAfterRawRegexLiteral() {
let source = """
/test/.something
"""
assertFormatted(source: source, expected: source)
}
}

0 comments on commit c9e4788

Please sign in to comment.