-
-
Notifications
You must be signed in to change notification settings - Fork 147
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 #133 from funzin/support-mintfile
Support Mintfile 🌱
- Loading branch information
Showing
13 changed files
with
127 additions
and
34 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
31 changes: 31 additions & 0 deletions
31
Sources/LicensePlistCore/Entity/GitHubLibraryConfigFile.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,31 @@ | ||
public struct GitHubLibraryConfigFile: Equatable { | ||
let type: GitHubLibraryConfigFileType | ||
let content: String? | ||
} | ||
|
||
extension GitHubLibraryConfigFile { | ||
static func carthage(content: String?) -> GitHubLibraryConfigFile { .init(type: .carthage, content: content) } | ||
static func mint(content: String?) -> GitHubLibraryConfigFile { .init(type: .mint, content: content) } | ||
static func licensePlist(content: String?) -> GitHubLibraryConfigFile { .init(type: .licensePlist, content: content) } | ||
} | ||
|
||
public enum GitHubLibraryConfigFileType: Int, CaseIterable { | ||
case carthage | ||
case mint | ||
case licensePlist | ||
} | ||
|
||
extension GitHubLibraryConfigFileType { | ||
func regexString(version: Bool) -> String { | ||
let pattern = "[\\w\\.\\-]+" | ||
switch self { | ||
case .carthage: | ||
let quotes = "\"" | ||
return "github \(quotes)(\(pattern))/(\(pattern))\(quotes)" + (version ? " \(quotes)(\(pattern))\(quotes)" : "") | ||
case .mint: | ||
return "(\(pattern))/(\(pattern))" + (version ? "@(\(pattern))" : "") | ||
case .licensePlist: | ||
return "(\(pattern))/(\(pattern))" + (version ? " (\(pattern))" : "") | ||
} | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
Tests/LicensePlistTests/Entity/GitHubLibraryConfigFileTests.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,11 @@ | ||
import XCTest | ||
@testable import LicensePlistCore | ||
|
||
class GitHubLibraryConfigFileTests: XCTestCase { | ||
|
||
func testInit() { | ||
XCTAssertEqual(GitHubLibraryConfigFile.carthage(content: "content"), GitHubLibraryConfigFile(type: .carthage, content: "content")) | ||
XCTAssertEqual(GitHubLibraryConfigFile.mint(content: "content"), GitHubLibraryConfigFile(type: .mint, content: "content")) | ||
XCTAssertEqual(GitHubLibraryConfigFile.licensePlist(content: "content"), GitHubLibraryConfigFile(type: .licensePlist, content: "content")) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Tests/LicensePlistTests/Entity/GitHubLibraryConfigFileTypeTests.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,28 @@ | ||
import XCTest | ||
@testable import LicensePlistCore | ||
|
||
class GitHubLibraryConfigFileTypeTests: XCTestCase { | ||
|
||
func testRegexString() { | ||
// carthage | ||
do { | ||
let type = GitHubLibraryConfigFileType.carthage | ||
XCTAssertEqual(type.regexString(version: false), "github \"([\\w\\.\\-]+)/([\\w\\.\\-]+)\"") | ||
XCTAssertEqual(type.regexString(version: true), "github \"([\\w\\.\\-]+)/([\\w\\.\\-]+)\" \"([\\w\\.\\-]+)\"") | ||
} | ||
|
||
// mint | ||
do { | ||
let type = GitHubLibraryConfigFileType.mint | ||
XCTAssertEqual(type.regexString(version: false), "([\\w\\.\\-]+)/([\\w\\.\\-]+)") | ||
XCTAssertEqual(type.regexString(version: true), "([\\w\\.\\-]+)/([\\w\\.\\-]+)@([\\w\\.\\-]+)") | ||
} | ||
|
||
// licensePlist | ||
do { | ||
let type = GitHubLibraryConfigFileType.licensePlist | ||
XCTAssertEqual(type.regexString(version: false), "([\\w\\.\\-]+)/([\\w\\.\\-]+)") | ||
XCTAssertEqual(type.regexString(version: true), "([\\w\\.\\-]+)/([\\w\\.\\-]+) ([\\w\\.\\-]+)") | ||
} | ||
} | ||
} |
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