|
2 | 2 | import TestHelpers |
3 | 3 |
|
4 | 4 | final class LineLengthRuleTests: SwiftLintTestCase { |
| 5 | + private static let longString = String(repeating: "a", count: 121) |
| 6 | + |
5 | 7 | 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 | + """), |
16 | 24 | Example(""" |
17 | 25 | struct S { |
18 | 26 | public init(a: String, b: String, c: String, d: String, e: String, f: String, \ |
@@ -40,29 +48,49 @@ final class LineLengthRuleTests: SwiftLintTestCase { |
40 | 48 |
|
41 | 49 | private let longComment = Example(String(repeating: "/", count: 121) + "\n") |
42 | 50 | 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 | + """) |
46 | 57 | private let declarationWithTrailingLongComment = Example("let foo = 1 " + String(repeating: "/", count: 121) + "\n") |
47 | 58 | 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 | + """) |
66 | 94 |
|
67 | 95 | func testLineLength() { |
68 | 96 | verifyRule(LineLengthRule.description, commentDoesntViolate: false, stringDoesntViolate: false) |
|
0 commit comments