-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2428 from biboran/compiler-protocol-init-description
#2422 - Specify which literal rule was violated for CompilerProtocolInitRule
- Loading branch information
Showing
6 changed files
with
60 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
Tests/SwiftLintFrameworkTests/CompilerProtocolInitRuleTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
@testable import SwiftLintFramework | ||
import XCTest | ||
|
||
class CompilerProtocolInitRuleTests: XCTestCase { | ||
private let ruleID = CompilerProtocolInitRule.description.identifier | ||
|
||
func testWithDefaultConfiguration() { | ||
verifyRule(CompilerProtocolInitRule.description) | ||
} | ||
|
||
func testViolationMessageForExpressibleByIntegerLiteral() { | ||
guard let config = makeConfig(nil, ruleID) else { | ||
XCTFail("Failed to create configuration") | ||
return | ||
} | ||
let allViolations = violations("let a = NSNumber(integerLiteral: 1)", config: config) | ||
|
||
let compilerProtocolInitViolation = allViolations.first { $0.ruleDescription.identifier == ruleID } | ||
if let violation = compilerProtocolInitViolation { | ||
XCTAssertEqual( | ||
violation.reason, | ||
"The initializers declared in compiler protocol ExpressibleByIntegerLiteral " + | ||
"shouldn't be called directly." | ||
) | ||
} else { | ||
XCTFail("A compiler protocol init violation should have been triggered!") | ||
} | ||
} | ||
} |