Skip to content

Commit

Permalink
Run Code Butler
Browse files Browse the repository at this point in the history
  • Loading branch information
TrevorPilley committed Dec 2, 2024
1 parent 809a40e commit cf199c1
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 144 deletions.
6 changes: 3 additions & 3 deletions src/PhoneNumbers/CountryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ internal string ReadNationalSignificantNumber(string value)
return ReadNationalSignificantNumber(value, startIdx);
}

private static bool IsDelimiter(char charVal) =>
charVal == Chars.Comma || charVal == Chars.Semicolon;

/// <remarks>Char.IsDigit returns true for more than 0-9 so use a more restricted version.</remarks>
private static bool IsDigit(char charVal) =>
charVal is >= '0' and <= '9';

private static bool IsDelimiter(char charVal) =>
charVal == Chars.Comma || charVal == Chars.Semicolon;

private static bool IsSeparator(char charVal) =>
charVal == Chars.Hyphen || charVal == Chars.ForwardSlash;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,62 +114,6 @@ public void GetFormat_National_No_TrunkPrefix_With_Ndc(string ndc, string sn, st
SimplePhoneNumberFormatProvider.Default.GetFormat(
TestHelper.CreateNonGeographicPhoneNumber(null, ndc, sn), false));

[Theory]
[InlineData("0", "1234", "0####")]
[InlineData("0", "12345", "0#####")]
[InlineData("0", "123456", "0######")]
[InlineData("0", "1234567", "0#######")]
[InlineData("0", "12345678", "0########")]
[InlineData("0", "123456789", "0#########")]
[InlineData("0", "1234567890", "0##########")]
public void GetFormat_National_With_TrunkPrefix_No_Ndc(string trunkPrefix, string sn, string expectedMask) =>
Assert.Equal(
expectedMask,
SimplePhoneNumberFormatProvider.Default.GetFormat(
TestHelper.CreateNonGeographicPhoneNumber(trunkPrefix, null, sn), false));

[Theory]
[InlineData("0", "1", "1234", "0# ####")]
[InlineData("0", "1", "12345", "0# #####")]
[InlineData("0", "1", "123456", "0# ######")]
[InlineData("0", "1", "1234567", "0# #######")]
[InlineData("0", "1", "12345678", "0# ########")]
[InlineData("0", "1", "123456789", "0# #########")]
[InlineData("0", "1", "1234567890", "0# ##########")]
[InlineData("0", "12", "1234", "0## ####")]
[InlineData("0", "12", "12345", "0## #####")]
[InlineData("0", "12", "123456", "0## ######")]
[InlineData("0", "12", "1234567", "0## #######")]
[InlineData("0", "12", "12345678", "0## ########")]
[InlineData("0", "12", "123456789", "0## #########")]
[InlineData("0", "12", "1234567890", "0## ##########")]
[InlineData("0", "123", "1234", "0### ####")]
[InlineData("0", "123", "12345", "0### #####")]
[InlineData("0", "123", "123456", "0### ######")]
[InlineData("0", "123", "1234567", "0### #######")]
[InlineData("0", "123", "12345678", "0### ########")]
[InlineData("0", "123", "123456789", "0### #########")]
[InlineData("0", "123", "1234567890", "0### ##########")]
[InlineData("0", "1234", "1234", "0#### ####")]
[InlineData("0", "1234", "12345", "0#### #####")]
[InlineData("0", "1234", "123456", "0#### ######")]
[InlineData("0", "1234", "1234567", "0#### #######")]
[InlineData("0", "1234", "12345678", "0#### ########")]
[InlineData("0", "1234", "123456789", "0#### #########")]
[InlineData("0", "1234", "1234567890", "0#### ##########")]
[InlineData("0", "12345", "1234", "0##### ####")]
[InlineData("0", "12345", "12345", "0##### #####")]
[InlineData("0", "12345", "123456", "0##### ######")]
[InlineData("0", "12345", "1234567", "0##### #######")]
[InlineData("0", "12345", "12345678", "0##### ########")]
[InlineData("0", "12345", "123456789", "0##### #########")]
[InlineData("0", "12345", "1234567890", "0##### ##########")]
public void GetFormat_National_With_TrunkPrefix_With_Ndc(string trunkPrefix, string ndc, string sn, string expectedMask) =>
Assert.Equal(
expectedMask,
SimplePhoneNumberFormatProvider.Default.GetFormat(
TestHelper.CreateNonGeographicPhoneNumber(trunkPrefix, ndc, sn), false));

[Theory]
[InlineData("1", "1234", "(#) ####")]
[InlineData("1", "12345", "(#) #####")]
Expand Down Expand Up @@ -254,6 +198,62 @@ public void GetFormat_National_No_TrunkPrefix_With_Ndc_Required(string ndc, stri
SimplePhoneNumberFormatProvider.Default.GetFormat(
TestHelper.CreateNonGeographicPhoneNumber(null, ndc, sn, true), false));

[Theory]
[InlineData("0", "1234", "0####")]
[InlineData("0", "12345", "0#####")]
[InlineData("0", "123456", "0######")]
[InlineData("0", "1234567", "0#######")]
[InlineData("0", "12345678", "0########")]
[InlineData("0", "123456789", "0#########")]
[InlineData("0", "1234567890", "0##########")]
public void GetFormat_National_With_TrunkPrefix_No_Ndc(string trunkPrefix, string sn, string expectedMask) =>
Assert.Equal(
expectedMask,
SimplePhoneNumberFormatProvider.Default.GetFormat(
TestHelper.CreateNonGeographicPhoneNumber(trunkPrefix, null, sn), false));

[Theory]
[InlineData("0", "1", "1234", "0# ####")]
[InlineData("0", "1", "12345", "0# #####")]
[InlineData("0", "1", "123456", "0# ######")]
[InlineData("0", "1", "1234567", "0# #######")]
[InlineData("0", "1", "12345678", "0# ########")]
[InlineData("0", "1", "123456789", "0# #########")]
[InlineData("0", "1", "1234567890", "0# ##########")]
[InlineData("0", "12", "1234", "0## ####")]
[InlineData("0", "12", "12345", "0## #####")]
[InlineData("0", "12", "123456", "0## ######")]
[InlineData("0", "12", "1234567", "0## #######")]
[InlineData("0", "12", "12345678", "0## ########")]
[InlineData("0", "12", "123456789", "0## #########")]
[InlineData("0", "12", "1234567890", "0## ##########")]
[InlineData("0", "123", "1234", "0### ####")]
[InlineData("0", "123", "12345", "0### #####")]
[InlineData("0", "123", "123456", "0### ######")]
[InlineData("0", "123", "1234567", "0### #######")]
[InlineData("0", "123", "12345678", "0### ########")]
[InlineData("0", "123", "123456789", "0### #########")]
[InlineData("0", "123", "1234567890", "0### ##########")]
[InlineData("0", "1234", "1234", "0#### ####")]
[InlineData("0", "1234", "12345", "0#### #####")]
[InlineData("0", "1234", "123456", "0#### ######")]
[InlineData("0", "1234", "1234567", "0#### #######")]
[InlineData("0", "1234", "12345678", "0#### ########")]
[InlineData("0", "1234", "123456789", "0#### #########")]
[InlineData("0", "1234", "1234567890", "0#### ##########")]
[InlineData("0", "12345", "1234", "0##### ####")]
[InlineData("0", "12345", "12345", "0##### #####")]
[InlineData("0", "12345", "123456", "0##### ######")]
[InlineData("0", "12345", "1234567", "0##### #######")]
[InlineData("0", "12345", "12345678", "0##### ########")]
[InlineData("0", "12345", "123456789", "0##### #########")]
[InlineData("0", "12345", "1234567890", "0##### ##########")]
public void GetFormat_National_With_TrunkPrefix_With_Ndc(string trunkPrefix, string ndc, string sn, string expectedMask) =>
Assert.Equal(
expectedMask,
SimplePhoneNumberFormatProvider.Default.GetFormat(
TestHelper.CreateNonGeographicPhoneNumber(trunkPrefix, ndc, sn), false));

[Theory]
[InlineData("0", "1", "1234", "(0#) ####")]
[InlineData("0", "1", "12345", "(0#) #####")]
Expand Down
2 changes: 1 addition & 1 deletion test/PhoneNumbers.Tests/ParseOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void AddingCountryMultipleTimesOnlyOnceInList()

Assert.Single(parseOptions.Countries);
}

[Fact]
public void AllowAfricanCountries()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public void Parse_NonGeographicPhoneNumber_SharedCost()
Assert.Equal("28000", nonGeographicPhoneNumber.SubscriberNumber);
Assert.Equal(PhoneNumberKind.NonGeographicPhoneNumber, nonGeographicPhoneNumber.Kind);
}

[Fact] // This scenario exists within Germany
public void Parse_When_Nsn_Shorter_Than_Some_Ndc_Lengths()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,33 @@ public class GBPhoneNumberParserTests_GeographicPhoneNumber
private static readonly PhoneNumberParser s_parser = GBPhoneNumberParser.Create();

[Theory]
[InlineData("01132000000", "113", "2000000", "Leeds")]
[InlineData("01135999999", "113", "5999999", "Leeds")]
[InlineData("01137000000", "113", "7000000", "Leeds")]
[InlineData("01138999999", "113", "8999999", "Leeds")]
[InlineData("01142000000", "114", "2000000", "Sheffield")]
[InlineData("01147999999", "114", "7999999", "Sheffield")]
[InlineData("01152000000", "115", "2000000", "Nottingham")]
[InlineData("01152999999", "115", "2999999", "Nottingham")]
[InlineData("01156000000", "115", "6000000", "Nottingham")]
[InlineData("01159989999", "115", "9989999", "Nottingham")]
[InlineData("01162000000", "116", "2000000", "Leicester")]
[InlineData("01164999999", "116", "4999999", "Leicester")]
[InlineData("01172000000", "117", "2000000", "Bristol")]
[InlineData("01174999999", "117", "4999999", "Bristol")]
[InlineData("01179000000", "117", "9000000", "Bristol")]
[InlineData("01179989999", "117", "9989999", "Bristol")]
[InlineData("01182000000", "118", "2000000", "Reading")]
[InlineData("01184999999", "118", "4999999", "Reading")]
[InlineData("01189000000", "118", "9000000", "Reading")]
[InlineData("01189989999", "118", "9989999", "Reading")]
[InlineData("01212000000", "121", "2000000", "Birmingham")]
[InlineData("01217999999", "121", "7999999", "Birmingham")]
[InlineData("01312000000", "131", "2000000", "Edinburgh")]
[InlineData("01317999999", "131", "7999999", "Edinburgh")]
[InlineData("01412000000", "141", "2000000", "Glasgow")]
[InlineData("01419989999", "141", "9989999", "Glasgow")]
[InlineData("01512000000", "151", "2000000", "Liverpool")]
[InlineData("01519989999", "151", "9989999", "Liverpool")]
[InlineData("01612000000", "161", "2000000", "Manchester")]
[InlineData("01614999999", "161", "4999999", "Manchester")]
[InlineData("01616000000", "161", "6000000", "Manchester")]
[InlineData("01619989999", "161", "9989999", "Manchester")]
[InlineData("01912000000", "191", "2000000", "Tyneside")]
[InlineData("01912999999", "191", "2999999", "Tyneside")]
[InlineData("01913000000", "191", "3000000", "Durham")]
[InlineData("01913999999", "191", "3999999", "Durham")]
[InlineData("01914000000", "191", "4000000", "Tyneside")]
[InlineData("01914999999", "191", "4999999", "Tyneside")]
[InlineData("01915000000", "191", "5000000", "Sunderland")]
[InlineData("01915999999", "191", "5999999", "Sunderland")]
[InlineData("01916000000", "191", "6000000", "Tyneside")]
[InlineData("01916999999", "191", "6999999", "Tyneside")]
[InlineData("01917000000", "191", "7000000", "Sunderland")]
[InlineData("01917999999", "191", "7999999", "Sunderland")]
[InlineData("01918000000", "191", "8000000", "Tyneside")]
[InlineData("01918999999", "191", "8999999", "Tyneside")]
[InlineData("01919000000", "191", "9000000", "Durham")]
[InlineData("01919989999", "191", "9989999", "Durham")]
public void Parse_Known_GeographicPhoneNumber_1XX_NationalDestinationCode(string value, string NationalDestinationCode, string subscriberNumber, string geographicArea)
[InlineData("01387320000", "13873", "20000", "Langholm")]
[InlineData("01387399899", "13873", "99899", "Langholm")]
[InlineData("01524220000", "15242", "20000", "Hornby")]
[InlineData("01524299899", "15242", "99899", "Hornby")]
[InlineData("01539420000", "15394", "20000", "Hawkshead")]
[InlineData("01539499899", "15394", "99899", "Hawkshead")]
[InlineData("01539520000", "15395", "20000", "Grange-Over-Sands")]
[InlineData("01539599899", "15395", "99899", "Grange-Over-Sands")]
[InlineData("01539620000", "15396", "20000", "Sedbergh")]
[InlineData("01539699899", "15396", "99899", "Sedbergh")]
[InlineData("01697320000", "16973", "20000", "Wigton")]
[InlineData("01697399899", "16973", "99899", "Wigton")]
[InlineData("01697420000", "16974", "20000", "Raughton Head")]
[InlineData("01697499899", "16974", "99899", "Raughton Head")]
[InlineData("0169772000", "16977", "2000", "Brampton")]
[InlineData("0169773999", "16977", "3999", "Brampton")]
[InlineData("01697740000", "16977", "40000", "Brampton")]
[InlineData("01697798999", "16977", "98999", "Brampton")]
[InlineData("01768320000", "17683", "20000", "Appleby")]
[InlineData("01768399899", "17683", "99899", "Appleby")]
[InlineData("01768420000", "17684", "20000", "Pooley Bridge")]
[InlineData("01768499899", "17684", "99899", "Pooley Bridge")]
[InlineData("01768720000", "17687", "20000", "Keswick")]
[InlineData("01768799899", "17687", "99899", "Keswick")]
[InlineData("01946720000", "19467", "20000", "Gosforth")]
[InlineData("01946799899", "19467", "99899", "Gosforth")]
public void Parse_Known_GeographicPhoneNumber_1XXXX_NationalDestinationCode(string value, string NationalDestinationCode, string subscriberNumber, string geographicArea)
{
var parseResult = s_parser.Parse(value);
parseResult.ThrowIfFailure();
Expand Down Expand Up @@ -1524,33 +1502,55 @@ public void Parse_Known_GeographicPhoneNumber_1XXX_NationalDestinationCode(strin
}

[Theory]
[InlineData("01387320000", "13873", "20000", "Langholm")]
[InlineData("01387399899", "13873", "99899", "Langholm")]
[InlineData("01524220000", "15242", "20000", "Hornby")]
[InlineData("01524299899", "15242", "99899", "Hornby")]
[InlineData("01539420000", "15394", "20000", "Hawkshead")]
[InlineData("01539499899", "15394", "99899", "Hawkshead")]
[InlineData("01539520000", "15395", "20000", "Grange-Over-Sands")]
[InlineData("01539599899", "15395", "99899", "Grange-Over-Sands")]
[InlineData("01539620000", "15396", "20000", "Sedbergh")]
[InlineData("01539699899", "15396", "99899", "Sedbergh")]
[InlineData("01697320000", "16973", "20000", "Wigton")]
[InlineData("01697399899", "16973", "99899", "Wigton")]
[InlineData("01697420000", "16974", "20000", "Raughton Head")]
[InlineData("01697499899", "16974", "99899", "Raughton Head")]
[InlineData("0169772000", "16977", "2000", "Brampton")]
[InlineData("0169773999", "16977", "3999", "Brampton")]
[InlineData("01697740000", "16977", "40000", "Brampton")]
[InlineData("01697798999", "16977", "98999", "Brampton")]
[InlineData("01768320000", "17683", "20000", "Appleby")]
[InlineData("01768399899", "17683", "99899", "Appleby")]
[InlineData("01768420000", "17684", "20000", "Pooley Bridge")]
[InlineData("01768499899", "17684", "99899", "Pooley Bridge")]
[InlineData("01768720000", "17687", "20000", "Keswick")]
[InlineData("01768799899", "17687", "99899", "Keswick")]
[InlineData("01946720000", "19467", "20000", "Gosforth")]
[InlineData("01946799899", "19467", "99899", "Gosforth")]
public void Parse_Known_GeographicPhoneNumber_1XXXX_NationalDestinationCode(string value, string NationalDestinationCode, string subscriberNumber, string geographicArea)
[InlineData("01132000000", "113", "2000000", "Leeds")]
[InlineData("01135999999", "113", "5999999", "Leeds")]
[InlineData("01137000000", "113", "7000000", "Leeds")]
[InlineData("01138999999", "113", "8999999", "Leeds")]
[InlineData("01142000000", "114", "2000000", "Sheffield")]
[InlineData("01147999999", "114", "7999999", "Sheffield")]
[InlineData("01152000000", "115", "2000000", "Nottingham")]
[InlineData("01152999999", "115", "2999999", "Nottingham")]
[InlineData("01156000000", "115", "6000000", "Nottingham")]
[InlineData("01159989999", "115", "9989999", "Nottingham")]
[InlineData("01162000000", "116", "2000000", "Leicester")]
[InlineData("01164999999", "116", "4999999", "Leicester")]
[InlineData("01172000000", "117", "2000000", "Bristol")]
[InlineData("01174999999", "117", "4999999", "Bristol")]
[InlineData("01179000000", "117", "9000000", "Bristol")]
[InlineData("01179989999", "117", "9989999", "Bristol")]
[InlineData("01182000000", "118", "2000000", "Reading")]
[InlineData("01184999999", "118", "4999999", "Reading")]
[InlineData("01189000000", "118", "9000000", "Reading")]
[InlineData("01189989999", "118", "9989999", "Reading")]
[InlineData("01212000000", "121", "2000000", "Birmingham")]
[InlineData("01217999999", "121", "7999999", "Birmingham")]
[InlineData("01312000000", "131", "2000000", "Edinburgh")]
[InlineData("01317999999", "131", "7999999", "Edinburgh")]
[InlineData("01412000000", "141", "2000000", "Glasgow")]
[InlineData("01419989999", "141", "9989999", "Glasgow")]
[InlineData("01512000000", "151", "2000000", "Liverpool")]
[InlineData("01519989999", "151", "9989999", "Liverpool")]
[InlineData("01612000000", "161", "2000000", "Manchester")]
[InlineData("01614999999", "161", "4999999", "Manchester")]
[InlineData("01616000000", "161", "6000000", "Manchester")]
[InlineData("01619989999", "161", "9989999", "Manchester")]
[InlineData("01912000000", "191", "2000000", "Tyneside")]
[InlineData("01912999999", "191", "2999999", "Tyneside")]
[InlineData("01913000000", "191", "3000000", "Durham")]
[InlineData("01913999999", "191", "3999999", "Durham")]
[InlineData("01914000000", "191", "4000000", "Tyneside")]
[InlineData("01914999999", "191", "4999999", "Tyneside")]
[InlineData("01915000000", "191", "5000000", "Sunderland")]
[InlineData("01915999999", "191", "5999999", "Sunderland")]
[InlineData("01916000000", "191", "6000000", "Tyneside")]
[InlineData("01916999999", "191", "6999999", "Tyneside")]
[InlineData("01917000000", "191", "7000000", "Sunderland")]
[InlineData("01917999999", "191", "7999999", "Sunderland")]
[InlineData("01918000000", "191", "8000000", "Tyneside")]
[InlineData("01918999999", "191", "8999999", "Tyneside")]
[InlineData("01919000000", "191", "9000000", "Durham")]
[InlineData("01919989999", "191", "9989999", "Durham")]
public void Parse_Known_GeographicPhoneNumber_1XX_NationalDestinationCode(string value, string NationalDestinationCode, string subscriberNumber, string geographicArea)
{
var parseResult = s_parser.Parse(value);
parseResult.ThrowIfFailure();
Expand Down
14 changes: 7 additions & 7 deletions test/PhoneNumbers.Tests/PhoneNumberTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,6 @@ public void TryParse_Value_PhoneNumbers_False_If_ParseOptions_Null()
Assert.Empty(phoneNumbers);
}

[Fact]
public void TryParse_Value_To_PhoneNumber_False_If_ParseOptions_Null()
{
Assert.False(PhoneNumber.TryParse("0123456789", default(ParseOptions), out PhoneNumber phoneNumber));
Assert.Null(phoneNumber);
}

[Theory]
[InlineData(default(string))]
[InlineData("")]
Expand Down Expand Up @@ -350,4 +343,11 @@ public void TryParse_Value_PhoneNumbers_Value_Without_CallingCode()
Assert.Equal(CountryInfo.Serbia, phoneNumberResults[2].Country);
Assert.Equal(CountryInfo.UnitedKingdom, phoneNumberResults[3].Country);
}

[Fact]
public void TryParse_Value_To_PhoneNumber_False_If_ParseOptions_Null()
{
Assert.False(PhoneNumber.TryParse("0123456789", default(ParseOptions), out PhoneNumber phoneNumber));
Assert.Null(phoneNumber);
}
}

0 comments on commit cf199c1

Please sign in to comment.