Skip to content

Commit 5b9db55

Browse files
CopilotSimplyDanny
andauthored
Convert multiline strings to string blocks (#6244)
Co-authored-by: SimplyDanny <[email protected]>
1 parent 60671f4 commit 5b9db55

File tree

1 file changed

+59
-31
lines changed

1 file changed

+59
-31
lines changed

Tests/BuiltInRulesTests/LineLengthRuleTests.swift

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@
22
import TestHelpers
33

44
final class LineLengthRuleTests: SwiftLintTestCase {
5+
private static let longString = String(repeating: "a", count: 121)
6+
57
private let longFunctionDeclarations = [
6-
Example("public func superDuperLongFunctionDeclaration(a: String, b: String, " +
7-
"c: String, d: String, e: String, f: String, g: String, h: String, i: String, " +
8-
"j: String, k: String, l: String, m: String, n: String, o: String, p: String, " +
9-
"q: String, r: String, s: String, t: String, u: String, v: String, w: String, " +
10-
"x: String, y: String, z: String) {}\n"),
11-
Example("func superDuperLongFunctionDeclaration(a: String, b: String, " +
12-
"c: String, d: String, e: String, f: String, g: String, h: String, i: String, " +
13-
"j: String, k: String, l: String, m: String, n: String, o: String, p: String, " +
14-
"q: String, r: String, s: String, t: String, u: String, v: String, w: String, " +
15-
"x: String, y: String, z: String) {}\n"),
8+
Example("""
9+
public func superDuperLongFunctionDeclaration(a: String, b: String, \
10+
c: String, d: String, e: String, f: String, g: String, h: String, i: String, \
11+
j: String, k: String, l: String, m: String, n: String, o: String, p: String, \
12+
q: String, r: String, s: String, t: String, u: String, v: String, w: String, \
13+
x: String, y: String, z: String) {}
14+
15+
"""),
16+
Example("""
17+
func superDuperLongFunctionDeclaration(a: String, b: String, \
18+
c: String, d: String, e: String, f: String, g: String, h: String, i: String, \
19+
j: String, k: String, l: String, m: String, n: String, o: String, p: String, \
20+
q: String, r: String, s: String, t: String, u: String, v: String, w: String, \
21+
x: String, y: String, z: String) {}
22+
23+
"""),
1624
Example("""
1725
struct S {
1826
public init(a: String, b: String, c: String, d: String, e: String, f: String, \
@@ -40,29 +48,49 @@ final class LineLengthRuleTests: SwiftLintTestCase {
4048

4149
private let longComment = Example(String(repeating: "/", count: 121) + "\n")
4250
private let longBlockComment = Example("/*" + String(repeating: " ", count: 121) + "*/\n")
43-
private let longRealBlockComment = Example("/*\n" +
44-
String(repeating: "a", count: 121) + "\n" +
45-
"*/\n")
51+
private let longRealBlockComment = Example("""
52+
/*
53+
\(LineLengthRuleTests.longString)
54+
*/
55+
56+
""")
4657
private let declarationWithTrailingLongComment = Example("let foo = 1 " + String(repeating: "/", count: 121) + "\n")
4758
private let interpolatedString = Example("print(\"\\(value)" + String(repeating: "A", count: 113) + "\" )\n")
48-
private let plainString = Example("print(\"" + String(repeating: "A", count: 121) + ")\"\n")
49-
50-
private let multilineString = Example("let multilineString = \"\"\"\n" +
51-
String(repeating: "A", count: 121) + "\n" +
52-
"\"\"\"\n")
53-
private let tripleStringSingleLine = Example("let tripleString = \"\"\""
54-
+ String(repeating: "A", count: 121) + "\"\"\"\n")
55-
private let poundStringSingleLine = Example("let poundString = #\""
56-
+ String(repeating: "A", count: 121) + "\"#\n")
57-
private let multilineStringWithExpression = Example("let multilineString = \"\"\"\n" +
58-
String(repeating: "A", count: 121) + "\n\n\"\"\"; let a = 1")
59-
private let multilineStringWithNewlineExpression = Example("let multilineString = \"\"\"\n" +
60-
String(repeating: "A", count: 121) + "\n\n\"\"\"\n; let a = 1")
61-
private let multilineStringFail = Example("let multilineString = \"A\" + \n\"" +
62-
String(repeating: "A", count: 121) + "\"\n")
63-
private let multilineStringWithFunction = Example("let multilineString = \"\"\"\n" +
64-
String(repeating: "A", count: 121) + "\n" +
65-
"\"\"\".functionCall()")
59+
private let plainString = Example("print(\"" + LineLengthRuleTests.longString + ")\"\n")
60+
61+
private let multilineString = Example("""
62+
let multilineString = \"\"\"
63+
\(LineLengthRuleTests.longString)
64+
\"\"\"
65+
66+
""")
67+
private let tripleStringSingleLine = Example(
68+
"let tripleString = \"\"\"\(LineLengthRuleTests.longString)\"\"\"\n"
69+
)
70+
private let poundStringSingleLine = Example("let poundString = #\"\(LineLengthRuleTests.longString)\"#\n")
71+
private let multilineStringWithExpression = Example("""
72+
let multilineString = \"\"\"
73+
\(LineLengthRuleTests.longString)
74+
75+
\"\"\"; let a = 1
76+
""")
77+
private let multilineStringWithNewlineExpression = Example("""
78+
let multilineString = \"\"\"
79+
\(LineLengthRuleTests.longString)
80+
81+
\"\"\"
82+
; let a = 1
83+
""")
84+
private let multilineStringFail = Example("""
85+
let multilineString = "A" +
86+
"\(LineLengthRuleTests.longString)"
87+
88+
""")
89+
private let multilineStringWithFunction = Example("""
90+
let multilineString = \"\"\"
91+
\(LineLengthRuleTests.longString)
92+
\"\"\".functionCall()
93+
""")
6694

6795
func testLineLength() {
6896
verifyRule(LineLengthRule.description, commentDoesntViolate: false, stringDoesntViolate: false)

0 commit comments

Comments
 (0)