Skip to content

Commit

Permalink
Fix regex to allow dot and hyphen
Browse files Browse the repository at this point in the history
  • Loading branch information
mono0926 committed May 3, 2017
1 parent d09bb45 commit 826f94e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Sources/LicensePlistCore/Parser/Carthage.parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions Tests/LicensePlistTests/Parser/Cartfile.parserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 826f94e

Please sign in to comment.