From 9cddfd403ca899b48e5f6fbd0e9922aca9c35510 Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Fri, 6 Nov 2015 07:32:54 +0100 Subject: [PATCH] Additional formatting tests --- .../PhoneNumberKitParsingTests.swift | 80 ++++++++++++------- 1 file changed, 52 insertions(+), 28 deletions(-) diff --git a/PhoneNumberKitTests/PhoneNumberKitParsingTests.swift b/PhoneNumberKitTests/PhoneNumberKitParsingTests.swift index b7182d38a..b653f4d9e 100644 --- a/PhoneNumberKitTests/PhoneNumberKitParsingTests.swift +++ b/PhoneNumberKitTests/PhoneNumberKitParsingTests.swift @@ -107,14 +107,28 @@ class PhoneNumberKitParsingTests: XCTestCase { do { let phoneNumber1 = try PhoneNumber(rawNumber: "0291 12345678", region: "DE") XCTAssertNotNil(phoneNumber1) - let phoneNumber2 = try PhoneNumber(rawNumber: "+49 291 12345678", region: "DE") + let phoneNumberInternationalFormat1 = phoneNumber1.toInternational() + XCTAssertTrue(phoneNumberInternationalFormat1 == "+49 291 12345678") + let phoneNumberNationalFormat1 = phoneNumber1.toNational() + XCTAssertTrue(phoneNumberNationalFormat1 == "0291 12345678") + let phoneNumberE164Format1 = phoneNumber1.toE164() + XCTAssertTrue(phoneNumberE164Format1 == "+4929112345678") + let phoneNumber2 = try PhoneNumber(rawNumber: "04134 1234", region: "DE") XCTAssertNotNil(phoneNumber2) - let phoneNumber3 = try PhoneNumber(rawNumber: "04134 1234", region: "DE") + let phoneNumberInternationalFormat2 = phoneNumber2.toInternational() + XCTAssertTrue(phoneNumberInternationalFormat2 == "+49 4134 1234") + let phoneNumberNationalFormat2 = phoneNumber2.toNational() + XCTAssertTrue(phoneNumberNationalFormat2 == "04134 1234") + let phoneNumberE164Format2 = phoneNumber2.toE164() + XCTAssertTrue(phoneNumberE164Format2 == "+4941341234") + let phoneNumber3 = try PhoneNumber(rawNumber: "+49 8021 2345", region: "DE") XCTAssertNotNil(phoneNumber3) - let phoneNumber4 = try PhoneNumber(rawNumber: "09123 12345", region: "DE") - XCTAssertNotNil(phoneNumber4) - let phoneNumber5 = try PhoneNumber(rawNumber: "+49 8021 2345", region: "DE") - XCTAssertNotNil(phoneNumber5) + let phoneNumberInternationalFormat3 = phoneNumber3.toInternational() + XCTAssertTrue(phoneNumberInternationalFormat3 == "+49 8021 2345") + let phoneNumberNationalFormat3 = phoneNumber3.toNational() + XCTAssertTrue(phoneNumberNationalFormat3 == "08021 2345") + let phoneNumberE164Format3 = phoneNumber3.toE164() + XCTAssertTrue(phoneNumberE164Format3 == "+4980212345") } catch { XCTFail() @@ -125,10 +139,12 @@ class PhoneNumberKitParsingTests: XCTestCase { do { let phoneNumber1 = try PhoneNumber(rawNumber: "02 3661 8300", region: "IT") XCTAssertNotNil(phoneNumber1) - let phoneNumber2 = try PhoneNumber(rawNumber: "+39 02 3661 8300", region: "IT") - XCTAssertNotNil(phoneNumber2) - let phoneNumber3 = try PhoneNumber(rawNumber: "+390236618300", region: "IT") - XCTAssertNotNil(phoneNumber3) + let phoneNumberInternationalFormat1 = phoneNumber1.toInternational() + XCTAssertTrue(phoneNumberInternationalFormat1 == "+39 02 3661 8300") + let phoneNumberNationalFormat1 = phoneNumber1.toNational() + XCTAssertTrue(phoneNumberNationalFormat1 == "02 3661 8300") + let phoneNumberE164Format1 = phoneNumber1.toE164() + XCTAssertTrue(phoneNumberE164Format1 == "+390236618300") } catch { XCTFail() @@ -139,16 +155,20 @@ class PhoneNumberKitParsingTests: XCTestCase { do { let phoneNumber1 = try PhoneNumber(rawNumber: "02 3661 8300", region: "AU") XCTAssertNotNil(phoneNumber1) - let phoneNumber2 = try PhoneNumber(rawNumber: "+61 2 3661 8300", region: "AU") + let phoneNumberInternationalFormat1 = phoneNumber1.toInternational() + XCTAssertTrue(phoneNumberInternationalFormat1 == "+61 2 3661 8300") + let phoneNumberNationalFormat1 = phoneNumber1.toNational() + XCTAssertTrue(phoneNumberNationalFormat1 == "(02) 3661 8300") + let phoneNumberE164Format1 = phoneNumber1.toE164() + XCTAssertTrue(phoneNumberE164Format1 == "+61236618300") + let phoneNumber2 = try PhoneNumber(rawNumber: "+61 1800 123 456", region: "AU") XCTAssertNotNil(phoneNumber2) - let phoneNumber3 = try PhoneNumber(rawNumber: "+61236618300", region: "AU") - XCTAssertNotNil(phoneNumber3) - let phoneNumber4 = try PhoneNumber(rawNumber: "1800 123 456", region: "AU") - XCTAssertNotNil(phoneNumber4) - let phoneNumber5 = try PhoneNumber(rawNumber: "+61 1800 123 456", region: "AU") - XCTAssertNotNil(phoneNumber5) - let phoneNumber6 = try PhoneNumber(rawNumber: "+611800123456", region: "AU") - XCTAssertNotNil(phoneNumber6) + let phoneNumberInternationalFormat2 = phoneNumber2.toInternational() + XCTAssertTrue(phoneNumberInternationalFormat2 == "+61 1800 123 456") + let phoneNumberNationalFormat2 = phoneNumber2.toNational() + XCTAssertTrue(phoneNumberNationalFormat2 == "1800 123 456") + let phoneNumberE164Format2 = phoneNumber2.toE164() + XCTAssertTrue(phoneNumberE164Format2 == "+611800123456") } catch { XCTFail() @@ -159,16 +179,20 @@ class PhoneNumberKitParsingTests: XCTestCase { do { let phoneNumber1 = try PhoneNumber(rawNumber: "011 8765-4321", region: "AR") XCTAssertNotNil(phoneNumber1) - let phoneNumber2 = try PhoneNumber(rawNumber: "+54 11 8765-4321", region: "AR") + let phoneNumberInternationalFormat1 = phoneNumber1.toInternational() + XCTAssertTrue(phoneNumberInternationalFormat1 == "+54 11 8765-4321") + let phoneNumberNationalFormat1 = phoneNumber1.toNational() + XCTAssertTrue(phoneNumberNationalFormat1 == "011 8765-4321") + let phoneNumberE164Format1 = phoneNumber1.toE164() + XCTAssertTrue(phoneNumberE164Format1 == "+541187654321") + let phoneNumber2 = try PhoneNumber(rawNumber: "011 15 8765-4321", region: "AR") XCTAssertNotNil(phoneNumber2) - let phoneNumber3 = try PhoneNumber(rawNumber: "+541187654321", region: "AR") - XCTAssertNotNil(phoneNumber3) - let phoneNumber4 = try PhoneNumber(rawNumber: "011 15 8765-4321", region: "AR") - XCTAssertNotNil(phoneNumber4) - let phoneNumber5 = try PhoneNumber(rawNumber: "+54 9 11 8765 4321", region: "AR") - XCTAssertNotNil(phoneNumber5) - let phoneNumber6 = try PhoneNumber(rawNumber: "+5491187654321", region: "AR") - XCTAssertNotNil(phoneNumber6) + let phoneNumberInternationalFormat2 = phoneNumber2.toInternational() + XCTAssertTrue(phoneNumberInternationalFormat2 == "+54 9 11 8765-4321") + let phoneNumberNationalFormat2 = phoneNumber2.toNational() + XCTAssertTrue(phoneNumberNationalFormat2 == "011 15-8765-4321") + let phoneNumberE164Format2 = phoneNumber2.toE164() + XCTAssertTrue(phoneNumberE164Format2 == "+5491187654321") } catch { XCTFail()