Skip to content

Commit

Permalink
initial carrier work, more immutable, obsolete visiblefortesting
Browse files Browse the repository at this point in the history
  • Loading branch information
twcclegg committed Dec 9, 2020
1 parent e494237 commit 6d9e5f8
Show file tree
Hide file tree
Showing 27 changed files with 1,746 additions and 519 deletions.
4 changes: 2 additions & 2 deletions csharp/PhoneNumbers.Test/TestAreaCodeMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ private static SortedDictionary<int, string> CreateFlyweightStorageMapCandidate(
public void TestGetSmallerMapStorageChoosesDefaultImpl()
{
var mapStorage =
new AreaCodeMap().GetSmallerMapStorage(CreateDefaultStorageMapCandidate());
new AreaCodeMap().GetSmallerMapStorageInternal(CreateDefaultStorageMapCandidate());
Assert.False(mapStorage.GetType() == typeof(FlyweightMapStorage));
}

[Fact]
public void TestGetSmallerMapStorageChoosesFlyweightImpl()
{
var mapStorage =
new AreaCodeMap().GetSmallerMapStorage(CreateFlyweightStorageMapCandidate());
new AreaCodeMap().GetSmallerMapStorageInternal(CreateFlyweightStorageMapCandidate());
Assert.True(mapStorage.GetType() == typeof(FlyweightMapStorage));
}

Expand Down
46 changes: 23 additions & 23 deletions csharp/PhoneNumbers.Test/TestBuildMetadataFromXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public void TestValidateRERemovesWhiteSpaces()
{
var input = " hello world ";
// Should remove all the white spaces contained in the provided string.
Assert.Equal("helloworld", BuildMetadataFromXml.ValidateRE(input, true));
Assert.Equal("helloworld", BuildMetadataFromXml.ValidateRegex(input, true));
// Make sure it only happens when the last parameter is set to true.
Assert.Equal(" hello world ", BuildMetadataFromXml.ValidateRE(input, false));
Assert.Equal(" hello world ", BuildMetadataFromXml.ValidateRegex(input, false));
}

[Fact]
Expand All @@ -51,7 +51,7 @@ public void TestValidateREThrowsException()
// parameter (remove white spaces).
try
{
BuildMetadataFromXml.ValidateRE(invalidPattern, false);
BuildMetadataFromXml.ValidateRegex(invalidPattern, false);
Assert.True(false);
}
catch (ArgumentException)
Expand All @@ -60,7 +60,7 @@ public void TestValidateREThrowsException()
}
try
{
BuildMetadataFromXml.ValidateRE(invalidPattern, true);
BuildMetadataFromXml.ValidateRegex(invalidPattern, true);
Assert.True(false);
}
catch (ArgumentException)
Expand All @@ -74,7 +74,7 @@ public void TestValidateRE()
{
var validPattern = "[a-zA-Z]d{1,9}";
// The provided pattern should be left unchanged.
Assert.Equal(validPattern, BuildMetadataFromXml.ValidateRE(validPattern, false));
Assert.Equal(validPattern, BuildMetadataFromXml.ValidateRegex(validPattern, false));
}

// Tests NationalPrefix.
Expand All @@ -83,7 +83,7 @@ public void TestGetNationalPrefix()
{
var xmlInput = "<territory nationalPrefix='00'/>";
var territoryElement = ParseXmlString(xmlInput);
Assert.Equal("00", BuildMetadataFromXml.GetNationalPrefix(territoryElement));
Assert.Equal("00", BuildMetadataFromXml.GetNationalPrefixInternal(territoryElement));
}

// Tests LoadTerritoryTagMetadata().
Expand Down Expand Up @@ -154,7 +154,7 @@ public void TestLoadInternationalFormat()
var metadata = new PhoneMetadata.Builder();
var nationalFormat = "";

Assert.True(BuildMetadataFromXml.LoadInternationalFormat(metadata, numberFormatElement,
Assert.True(BuildMetadataFromXml.LoadInternationalFormatInternal(metadata, numberFormatElement,
nationalFormat));
Assert.Equal(intlFormat, metadata.IntlNumberFormatList[0].Format);
}
Expand All @@ -168,7 +168,7 @@ public void TestLoadInternationalFormatWithBothNationalAndIntlFormatsDefined()
var metadata = new PhoneMetadata.Builder();
var nationalFormat = "$1";

Assert.True(BuildMetadataFromXml.LoadInternationalFormat(metadata, numberFormatElement,
Assert.True(BuildMetadataFromXml.LoadInternationalFormatInternal(metadata, numberFormatElement,
nationalFormat));
Assert.Equal(intlFormat, metadata.IntlNumberFormatList[0].Format);
}
Expand All @@ -183,7 +183,7 @@ public void TestLoadInternationalFormatExpectsOnlyOnePattern()
// Should throw an exception as multiple intlFormats are provided.
try
{
BuildMetadataFromXml.LoadInternationalFormat(metadata, numberFormatElement, "");
BuildMetadataFromXml.LoadInternationalFormatInternal(metadata, numberFormatElement, "");
Assert.True(false);
}
catch (Exception)
Expand All @@ -200,7 +200,7 @@ public void TestLoadInternationalFormatUsesNationalFormatByDefault()
var metadata = new PhoneMetadata.Builder();
var nationalFormat = "$1 $2 $3";

Assert.False(BuildMetadataFromXml.LoadInternationalFormat(metadata, numberFormatElement,
Assert.False(BuildMetadataFromXml.LoadInternationalFormatInternal(metadata, numberFormatElement,
nationalFormat));
Assert.Equal(nationalFormat, metadata.IntlNumberFormatList[0].Format);
}
Expand All @@ -217,7 +217,7 @@ public void TestLoadNationalFormat()
var numberFormat = new NumberFormat.Builder();

Assert.Equal(nationalFormat,
BuildMetadataFromXml.LoadNationalFormat(metadata, numberFormatElement,
BuildMetadataFromXml.LoadNationalFormatInternal(metadata, numberFormatElement,
numberFormat));
}

Expand All @@ -231,7 +231,7 @@ public void TestLoadNationalFormatRequiresFormat()

try
{
BuildMetadataFromXml.LoadNationalFormat(metadata, numberFormatElement, numberFormat);
BuildMetadataFromXml.LoadNationalFormatInternal(metadata, numberFormatElement, numberFormat);
Assert.True(false);
}
catch (Exception)
Expand All @@ -250,7 +250,7 @@ public void TestLoadNationalFormatExpectsExactlyOneFormat()

try
{
BuildMetadataFromXml.LoadNationalFormat(metadata, numberFormatElement, numberFormat);
BuildMetadataFromXml.LoadNationalFormatInternal(metadata, numberFormatElement, numberFormat);
Assert.True(false);
}
catch (Exception)
Expand All @@ -274,7 +274,7 @@ public void TestLoadAvailableFormats()
"</territory>";
var element = ParseXmlString(xmlInput);
var metadata = new PhoneMetadata.Builder();
BuildMetadataFromXml.LoadAvailableFormats(
BuildMetadataFromXml.LoadAvailableFormatsInternal(
metadata, element, "0", "", false /* NP not optional */);
Assert.Equal("(${1})", metadata.NumberFormatList[0].NationalPrefixFormattingRule);
Assert.Equal("0 $CC (${1})", metadata.NumberFormatList[0].DomesticCarrierCodeFormattingRule);
Expand All @@ -294,7 +294,7 @@ public void TestLoadAvailableFormatsPropagatesCarrierCodeFormattingRule()
"</territory>";
var element = ParseXmlString(xmlInput);
var metadata = new PhoneMetadata.Builder();
BuildMetadataFromXml.LoadAvailableFormats(
BuildMetadataFromXml.LoadAvailableFormatsInternal(
metadata, element, "0", "", false /* NP not optional */);
Assert.Equal("(${1})", metadata.NumberFormatList[0].NationalPrefixFormattingRule);
Assert.Equal("0 $CC (${1})", metadata.NumberFormatList[0].DomesticCarrierCodeFormattingRule);
Expand All @@ -312,7 +312,7 @@ public void TestLoadAvailableFormatsSetsProvidedNationalPrefixFormattingRule()
"</territory>";
var element = ParseXmlString(xmlInput);
var metadata = new PhoneMetadata.Builder();
BuildMetadataFromXml.LoadAvailableFormats(
BuildMetadataFromXml.LoadAvailableFormatsInternal(
metadata, element, "0", "($1)", false /* NP not optional */);
Assert.Equal("($1)", metadata.NumberFormatList[0].NationalPrefixFormattingRule);
}
Expand All @@ -328,7 +328,7 @@ public void TestLoadAvailableFormatsClearsIntlFormat()
"</territory>";
var element = ParseXmlString(xmlInput);
var metadata = new PhoneMetadata.Builder();
BuildMetadataFromXml.LoadAvailableFormats(
BuildMetadataFromXml.LoadAvailableFormatsInternal(
metadata, element, "0", "($1)", false /* NP not optional */);
Assert.Equal(0, metadata.IntlNumberFormatCount);
}
Expand All @@ -345,7 +345,7 @@ public void TestLoadAvailableFormatsHandlesMultipleNumberFormats()
"</territory>";
var element = ParseXmlString(xmlInput);
var metadata = new PhoneMetadata.Builder();
BuildMetadataFromXml.LoadAvailableFormats(
BuildMetadataFromXml.LoadAvailableFormatsInternal(
metadata, element, "0", "($1)", false /* NP not optional */);
Assert.Equal("$1 $2 $3", metadata.NumberFormatList[0].Format);
Assert.Equal("$1-$2", metadata.NumberFormatList[1].Format);
Expand Down Expand Up @@ -374,7 +374,7 @@ public void TestGetNationalPrefixFormattingRuleFromElement()
var xmlInput = "<territory nationalPrefixFormattingRule='$NP$FG'/>";
var element = ParseXmlString(xmlInput);
Assert.Equal("0${1}",
BuildMetadataFromXml.GetNationalPrefixFormattingRuleFromElement(element, "0"));
BuildMetadataFromXml.GetNationalPrefixFormattingRuleFromElementInternal(element, "0"));
}

// Tests getDomesticCarrierCodeFormattingRuleFromElement().
Expand All @@ -395,7 +395,7 @@ public void TestProcessPhoneNumberDescElementWithInvalidInput()
{
var territoryElement = ParseXmlString("<territory/>");

var phoneNumberDesc = BuildMetadataFromXml.ProcessPhoneNumberDescElement(
var phoneNumberDesc = BuildMetadataFromXml.ProcessPhoneNumberDescElementInternal(
null, territoryElement, "invalidType");
Assert.False(phoneNumberDesc.HasNationalNumberPattern);
}
Expand All @@ -411,7 +411,7 @@ public void TestProcessPhoneNumberDescElementOverridesGeneralDesc()
"</fixedLine></territory>";
var territoryElement = ParseXmlString(xmlInput);

var phoneNumberDesc = BuildMetadataFromXml.ProcessPhoneNumberDescElement(
var phoneNumberDesc = BuildMetadataFromXml.ProcessPhoneNumberDescElementInternal(
generalDesc, territoryElement, "fixedLine");
Assert.Equal("\\d{6}", phoneNumberDesc.NationalNumberPattern);
}
Expand All @@ -425,7 +425,7 @@ public void TestProcessPhoneNumberDescOutputsExampleNumberByDefault()
"</fixedLine></territory>";
var territoryElement = ParseXmlString(xmlInput);

var phoneNumberDesc = BuildMetadataFromXml.ProcessPhoneNumberDescElement(
var phoneNumberDesc = BuildMetadataFromXml.ProcessPhoneNumberDescElementInternal(
null, territoryElement, "fixedLine");
Assert.Equal("01 01 01 01", phoneNumberDesc.ExampleNumber);
}
Expand All @@ -439,7 +439,7 @@ public void TestProcessPhoneNumberDescRemovesWhiteSpacesInPatterns()
"</fixedLine></territory>";
var countryElement = ParseXmlString(xmlInput);

var phoneNumberDesc = BuildMetadataFromXml.ProcessPhoneNumberDescElement(
var phoneNumberDesc = BuildMetadataFromXml.ProcessPhoneNumberDescElementInternal(
null, countryElement, "fixedLine");
Assert.Equal("\\d{6}", phoneNumberDesc.NationalNumberPattern);
}
Expand Down
Loading

0 comments on commit 6d9e5f8

Please sign in to comment.