// Tests setLeadingDigitsPatterns() in the case of international and national formatting rules // being present but not both defined for this numberFormat - we don't want to add them twice. [TestMethod] public void testSetLeadingDigitsPatternsNotAddedTwiceWhenInternationalFormatsPresent() { String xmlInput = " <availableFormats>" + " <numberFormat pattern=\"(1)(\\d{3})\">" + " <leadingDigits>1</leadingDigits>" + " <format>$1</format>" + " </numberFormat>" + " <numberFormat pattern=\"(2)(\\d{3})\">" + " <leadingDigits>2</leadingDigits>" + " <format>$1</format>" + " <intlFormat>9-$1</intlFormat>" + " </numberFormat>" + " </availableFormats>"; XmlElement element = parseXmlString(xmlInput); PhoneMetadata.Builder metadata = PhoneMetadata.newBuilder(); BuildMetadataFromXml.loadAvailableFormats( metadata, element, "0", "", false /* NP not optional */); Assert.AreEqual(1, metadata.getNumberFormat(0).leadingDigitsPatternSize()); Assert.AreEqual(1, metadata.getNumberFormat(1).leadingDigitsPatternSize()); // When we merge the national format rules into the international format rules, we shouldn't add // the leading digit patterns multiple times. Assert.AreEqual(1, metadata.getIntlNumberFormat(0).leadingDigitsPatternSize()); Assert.AreEqual(1, metadata.getIntlNumberFormat(1).leadingDigitsPatternSize()); }
[TestMethod] public void testLoadAvailableFormatsHandlesMultipleNumberFormats() { String xmlInput = "<territory>" + " <availableFormats>" + " <numberFormat><format>$1 $2 $3</format></numberFormat>" + " <numberFormat><format>$1-$2</format></numberFormat>" + " </availableFormats>" + "</territory>"; XmlElement element = parseXmlString(xmlInput); PhoneMetadata.Builder metadata = PhoneMetadata.newBuilder(); BuildMetadataFromXml.loadAvailableFormats( metadata, element, "0", "($1)", false /* NP not optional */); Assert.AreEqual("$1 $2 $3", metadata.getNumberFormat(0).getFormat()); Assert.AreEqual("$1-$2", metadata.getNumberFormat(1).getFormat()); }
[TestMethod] public void testLoadAvailableFormatsPropagatesCarrierCodeFormattingRule() { String xmlInput = "<territory carrierCodeFormattingRule='$NP $CC ($FG)'>" + " <availableFormats>" + " <numberFormat nationalPrefixFormattingRule='($FG)'>" + " <format>$1 $2 $3</format>" + " </numberFormat>" + " </availableFormats>" + "</territory>"; XmlElement element = parseXmlString(xmlInput); PhoneMetadata.Builder metadata = PhoneMetadata.newBuilder(); BuildMetadataFromXml.loadAvailableFormats( metadata, element, "0", "", false /* NP not optional */); Assert.AreEqual("($1)", metadata.getNumberFormat(0).getNationalPrefixFormattingRule()); Assert.AreEqual("0 $CC ($1)", metadata.getNumberFormat(0).getDomesticCarrierCodeFormattingRule()); Assert.AreEqual("$1 $2 $3", metadata.getNumberFormat(0).getFormat()); }
[TestMethod] public void testLoadAvailableFormatsSetsProvidedNationalPrefixFormattingRule() { String xmlInput = "<territory>" + " <availableFormats>" + " <numberFormat><format>$1 $2 $3</format></numberFormat>" + " </availableFormats>" + "</territory>"; XmlElement element = parseXmlString(xmlInput); PhoneMetadata.Builder metadata = PhoneMetadata.newBuilder(); BuildMetadataFromXml.loadAvailableFormats( metadata, element, "", "($1)", false /* NP not optional */); Assert.AreEqual("($1)", metadata.getNumberFormat(0).getNationalPrefixFormattingRule()); }