TM-SGNL-iOS/SignalServiceKit/tests/Util/PhoneNumberRegionsTest.swift
TeleMessage developers dde0620daf initial commit
2025-05-03 12:28:28 -07:00

44 lines
1.3 KiB
Swift
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
import XCTest
@testable import SignalServiceKit
final class PhoneNumberRegionsTest: XCTestCase {
func testInitFromRemoteConfig() {
let empties = ["", " ", "a"]
for value in empties {
XCTAssertTrue(PhoneNumberRegions(fromRemoteConfig: value).isEmpty)
}
let justOne = ["1", " 1a ", "+1,", "1١", "6⃣1"]
for value in justOne {
XCTAssertEqual(PhoneNumberRegions(fromRemoteConfig: value), ["1"], value)
}
XCTAssertEqual(
PhoneNumberRegions(fromRemoteConfig: "1,2 345, +6 7,, ,89,٦,6"),
["1", "2345", "67", "89"]
)
}
func testIsEmpty() {
let empty: PhoneNumberRegions = []
XCTAssertTrue(empty.isEmpty)
let notEmpty: PhoneNumberRegions = ["1", "44"]
XCTAssertFalse(notEmpty.isEmpty)
}
func testContains() {
let regions: PhoneNumberRegions = ["1", "44"]
XCTAssertTrue(regions.contains(e164: "+17345550123"))
XCTAssertTrue(regions.contains(e164: "+447700900123"))
XCTAssertFalse(regions.contains(e164: "+33639981234"))
// This tests the caching behavior, which should not affect results.
XCTAssertFalse(regions.contains(e164: "+33639981234"))
}
}