From 826f94e665a06a39ce8b1f62e52d3f5754a478af Mon Sep 17 00:00:00 2001 From: Masayuki Ono Date: Wed, 3 May 2017 19:07:27 +0900 Subject: [PATCH] Fix regex to allow dot and hyphen --- .../LicensePlistCore/Parser/Carthage.parser.swift | 3 ++- .../Parser/Cartfile.parserTests.swift | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Sources/LicensePlistCore/Parser/Carthage.parser.swift b/Sources/LicensePlistCore/Parser/Carthage.parser.swift index 5bcd9311..3c5ca5f0 100644 --- a/Sources/LicensePlistCore/Parser/Carthage.parser.swift +++ b/Sources/LicensePlistCore/Parser/Carthage.parser.swift @@ -2,7 +2,8 @@ import Foundation extension Carthage: Parser { public static func parse(_ content: String) -> [Carthage] { - let regex = try! NSRegularExpression(pattern: "github \"(\\w+)/(\\w+)\"", options: []) + let pattern = "[\\w\\.\\-]+" + let regex = try! NSRegularExpression(pattern: "github \"(\(pattern))/(\(pattern))\"", options: []) let nsContent = content as NSString let matches = regex.matches(in: content, options: [], range: NSRange(location: 0, length: nsContent.length)) return matches.map { match -> Carthage? in diff --git a/Tests/LicensePlistTests/Parser/Cartfile.parserTests.swift b/Tests/LicensePlistTests/Parser/Cartfile.parserTests.swift index 920715ee..0e7e16ea 100644 --- a/Tests/LicensePlistTests/Parser/Cartfile.parserTests.swift +++ b/Tests/LicensePlistTests/Parser/Cartfile.parserTests.swift @@ -16,6 +16,21 @@ class CartfileParserTests: XCTestCase { XCTAssertEqual(result, Carthage(name: "NativePopup", owner: "mono0926")) } + func testParse_one_dot() { + let results = Carthage.parse("github \"tephencelis/SQLite.swift\"") + XCTAssertTrue(results.count == 1) + let result = results.first + XCTAssertEqual(result, Carthage(name: "SQLite.swift", owner: "tephencelis")) + } + + func testParse_one_hyphen() { + let results = Carthage.parse("github \"mono0926/ios-license-generator\"") + XCTAssertTrue(results.count == 1) + let result = results.first + XCTAssertEqual(result, Carthage(name: "ios-license-generator", owner: "mono0926")) + } + + func testParse_multiple() { let results = Carthage.parse("github \"mono0926/NativePopup\"\ngithub \"ReactiveX/RxSwift\"") XCTAssertTrue(results.count == 2)