Skip to content

Commit

Permalink
Adding fixed or mobile type and test
Browse files Browse the repository at this point in the history
  • Loading branch information
marmelroy committed Nov 21, 2015
1 parent e74f1ec commit b17390b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions PhoneNumberKit/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public enum PNParsingError: ErrorType {

- FixedLine: Fixed line numbers
- Mobile: Mobile numbers
- FixedOrMobile: Either fixed or mobile numbers if we can't tell conclusively.
- Pager: Pager numbers
- PersonalNumber: Personal number numbers
- PremiumRate: Premium rate numbers
Expand All @@ -72,6 +73,7 @@ public enum PNParsingError: ErrorType {
public enum PNPhoneNumberType {
case FixedLine
case Mobile
case FixedOrMobile
case Pager
case PersonalNumber
case PremiumRate
Expand Down
10 changes: 9 additions & 1 deletion PhoneNumberKit/PhoneNumberParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,15 @@ class PhoneNumberParser {
return .Unknown
}
if (isNumberMatchingDesc(nationalNumber, numberDesc: metadata.fixedLine)) {
return .FixedLine
if metadata.fixedLine?.nationalNumberPattern == metadata.mobile?.nationalNumberPattern {
return .FixedOrMobile
}
else if (isNumberMatchingDesc(nationalNumber, numberDesc: metadata.mobile)) {
return .FixedOrMobile
}
else {
return .FixedLine
}
}
if (isNumberMatchingDesc(nationalNumber, numberDesc: metadata.mobile)) {
return .Mobile
Expand Down
13 changes: 13 additions & 0 deletions PhoneNumberKitTests/PhoneNumberKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ class PhoneNumberKitTests: XCTestCase {
XCTAssert(true)
}
}

// Invalid american number, GitHub issue #9 by lobodin
func testAmbiguousFixedOrMobileNumber() {
do {
let phoneNumber = try PhoneNumber(rawNumber: "+16307792428", region: "US")
print(phoneNumber.toE164())
XCTAssertEqual(phoneNumber.type, PNPhoneNumberType.FixedOrMobile)
}
catch {
XCTFail()
}
}


// Italian number with a leading zero
func testItalianLeadingZero() {
Expand Down

0 comments on commit b17390b

Please sign in to comment.