From aaa3c868a5d90ea1f8d96737381c47574f3a4aff Mon Sep 17 00:00:00 2001 From: Liam Nichols Date: Tue, 24 Dec 2019 11:58:28 +0000 Subject: [PATCH] Add tests to verify bug with PackageReference.name property and resolve --- Sources/MintKit/PackageReference.swift | 2 +- Tests/MintTests/PackageTests.swift | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Sources/MintKit/PackageReference.swift b/Sources/MintKit/PackageReference.swift index c10f6dc..88ee2aa 100644 --- a/Sources/MintKit/PackageReference.swift +++ b/Sources/MintKit/PackageReference.swift @@ -42,7 +42,7 @@ public class PackageReference { } public var name: String { - return repo.components(separatedBy: "/").last!.components(separatedBy: ".").first! + return repo.components(separatedBy: "/").last!.replacingOccurrences(of: ".git", with: "") } public var gitPath: String { diff --git a/Tests/MintTests/PackageTests.swift b/Tests/MintTests/PackageTests.swift index 5c4acae..5a8a815 100644 --- a/Tests/MintTests/PackageTests.swift +++ b/Tests/MintTests/PackageTests.swift @@ -41,6 +41,26 @@ class PackageTests: XCTestCase { } } + func testPackageNames() { + + let urls: [String: String] = [ + "yonaskolb/mint": "mint", + "github.com/yonaskolb/mint": "mint", + "https://github.com/yonaskolb/mint": "mint", + "https://github.com/yonaskolb/mint.git": "mint", + "mycustomdomain.com/package": "package", + "mycustomdomain.com/package.git": "package", + "https://mycustomdomain.com/package": "package", + "https://mycustomdomain.com/package.git": "package", + "git@github.com:yonaskolb/Mint.git": "Mint", + "mac-cain13/R.swift": "R.swift", + ] + + for (url, expected) in urls { + XCTAssertEqual(PackageReference(repo: url).name, expected) + } + } + func testPackageReferenceInfo() { XCTAssertEqual(PackageReference(package: "yonaskolb/mint"), PackageReference(repo: "yonaskolb/mint"))