-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Liechtenstein phone numbers
- Loading branch information
1 parent
ea181fe
commit 06a8abe
Showing
10 changed files
with
242 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Reference: https://archiv.llv.li/files/ak/pdf-llv-ak-liechtenstein_numbering_plan.pdf via https://www.llv.li/en/national-administration/office-for-communications/electronic-communication/numbering/liechtenstein-numbering-plan-itu-t-e.164- | ||
# Reference Date: 01/03/2017 | ||
N|||2000000-3999999| | ||
M|||600000000-689999999| | ||
M|||690000000-699999999| | ||
M|||7000000-7999999| | ||
N|||8000000-8099999|F | ||
N|||8400000-8499999|S | ||
N|||8700000-8799999| | ||
M|||8900000-8999999|V | ||
N|||9000000-9019999,9060000-9069999|R |
21 changes: 21 additions & 0 deletions
21
src/PhoneNumbers/Formatters/FormatProviders/LIPhoneNumberFormatProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace PhoneNumbers.Formatters.FormatProviders; | ||
|
||
/// <summary> | ||
/// A <see cref="PhoneNumberFormatProvider"/> for Liechtenstein numbers. | ||
/// </summary> | ||
internal sealed class LIPhoneNumberFormatProvider : SimplePhoneNumberFormatProvider | ||
{ | ||
private LIPhoneNumberFormatProvider() | ||
{ | ||
} | ||
|
||
internal static PhoneNumberFormatProvider Instance { get; } = new LIPhoneNumberFormatProvider(); | ||
|
||
protected override string ProvideFormat(PhoneNumber phoneNumber, bool international) => | ||
phoneNumber.NationalSignificantNumber.Length switch | ||
{ | ||
7 => "### ## ##", | ||
9 => "### ### ###", | ||
_ => base.ProvideFormat(phoneNumber, international), | ||
}; | ||
} |
55 changes: 55 additions & 0 deletions
55
test/PhoneNumbers.Data.Tests/Parsers/DefaultPhoneNumberParserTests_LI_MobilePhoneNumber.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
namespace PhoneNumbers.Tests.Parsers; | ||
|
||
/// <summary> | ||
/// Contains unit tests for the <see cref="DefaultPhoneNumberParser"/> class for Liechtenstein <see cref="PhoneNumber"/>s. | ||
/// </summary> | ||
public class DefaultPhoneNumberParserTests_LI_MobilePhoneNumber | ||
{ | ||
private static readonly PhoneNumberParser s_parser = DefaultPhoneNumberParser.Create(CountryInfo.Liechtenstein); | ||
|
||
[Theory] | ||
[InlineData("7000000", "7000000")] | ||
[InlineData("7999999", "7999999")] | ||
[InlineData("600000000", "600000000")] | ||
[InlineData("689999999", "689999999")] | ||
[InlineData("690000000", "690000000")] | ||
[InlineData("699999999", "699999999")] | ||
public void Parse_Known_MobilePhoneNumber(string value, string subscriberNumber) | ||
{ | ||
var parseResult = s_parser.Parse(value); | ||
parseResult.ThrowIfFailure(); | ||
|
||
var phoneNumber = parseResult.PhoneNumber; | ||
|
||
Assert.NotNull(phoneNumber); | ||
Assert.IsType<MobilePhoneNumber>(phoneNumber); | ||
|
||
var mobilePhoneNumber = (MobilePhoneNumber)phoneNumber; | ||
Assert.Equal(CountryInfo.Liechtenstein, mobilePhoneNumber.Country); | ||
Assert.False(mobilePhoneNumber.IsPager); | ||
Assert.False(mobilePhoneNumber.IsVirtual); | ||
Assert.Null(mobilePhoneNumber.NationalDestinationCode); | ||
Assert.Equal(subscriberNumber, mobilePhoneNumber.SubscriberNumber); | ||
} | ||
|
||
[Theory] | ||
[InlineData("8900000", "8900000")] | ||
[InlineData("8999999", "8999999")] | ||
public void Parse_Known_MobilePhoneNumber_Virtual(string value, string subscriberNumber) | ||
{ | ||
var parseResult = s_parser.Parse(value); | ||
parseResult.ThrowIfFailure(); | ||
|
||
var phoneNumber = parseResult.PhoneNumber; | ||
|
||
Assert.NotNull(phoneNumber); | ||
Assert.IsType<MobilePhoneNumber>(phoneNumber); | ||
|
||
var mobilePhoneNumber = (MobilePhoneNumber)phoneNumber; | ||
Assert.Equal(CountryInfo.Liechtenstein, mobilePhoneNumber.Country); | ||
Assert.False(mobilePhoneNumber.IsPager); | ||
Assert.True(mobilePhoneNumber.IsVirtual); | ||
Assert.Null(mobilePhoneNumber.NationalDestinationCode); | ||
Assert.Equal(subscriberNumber, mobilePhoneNumber.SubscriberNumber); | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
...neNumbers.Data.Tests/Parsers/DefaultPhoneNumberParserTests_LI_NonGeographicPhoneNumber.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
namespace PhoneNumbers.Tests.Parsers; | ||
|
||
/// <summary> | ||
/// Contains unit tests for the <see cref="DefaultPhoneNumberParser"/> class for Liechtenstein <see cref="PhoneNumber"/>s. | ||
/// </summary> | ||
public class DefaultPhoneNumberParserTests_LI_NonGeographicPhoneNumber | ||
{ | ||
private static readonly PhoneNumberParser s_parser = DefaultPhoneNumberParser.Create(CountryInfo.Liechtenstein); | ||
|
||
[Theory] | ||
[InlineData("2000000", "2000000")] | ||
[InlineData("3999999", "3999999")] | ||
[InlineData("8700000", "8700000")] | ||
[InlineData("8799999", "8799999")] | ||
public void Parse_Known_NonGeographicPhoneNumber(string value, string subscriberNumber) | ||
{ | ||
var parseResult = s_parser.Parse(value); | ||
parseResult.ThrowIfFailure(); | ||
|
||
var phoneNumber = parseResult.PhoneNumber; | ||
|
||
Assert.NotNull(phoneNumber); | ||
Assert.IsType<NonGeographicPhoneNumber>(phoneNumber); | ||
|
||
var nonGeographicPhoneNumber = (NonGeographicPhoneNumber)phoneNumber; | ||
Assert.Equal(CountryInfo.Liechtenstein, nonGeographicPhoneNumber.Country); | ||
Assert.False(nonGeographicPhoneNumber.IsFreephone); | ||
Assert.False(nonGeographicPhoneNumber.IsMachineToMachine); | ||
Assert.False(nonGeographicPhoneNumber.IsPremiumRate); | ||
Assert.False(nonGeographicPhoneNumber.IsSharedCost); | ||
Assert.Null(nonGeographicPhoneNumber.NationalDestinationCode); | ||
Assert.Equal(subscriberNumber, nonGeographicPhoneNumber.SubscriberNumber); | ||
} | ||
|
||
[Theory] | ||
[InlineData("8000000", "8000000")] | ||
[InlineData("8099999", "8099999")] | ||
public void Parse_Known_NonGeographicPhoneNumber_Freephone(string value, string subscriberNumber) | ||
{ | ||
var parseResult = s_parser.Parse(value); | ||
parseResult.ThrowIfFailure(); | ||
|
||
var phoneNumber = parseResult.PhoneNumber; | ||
|
||
Assert.NotNull(phoneNumber); | ||
Assert.IsType<NonGeographicPhoneNumber>(phoneNumber); | ||
|
||
var nonGeographicPhoneNumber = (NonGeographicPhoneNumber)phoneNumber; | ||
Assert.Equal(CountryInfo.Liechtenstein, nonGeographicPhoneNumber.Country); | ||
Assert.True(nonGeographicPhoneNumber.IsFreephone); | ||
Assert.False(nonGeographicPhoneNumber.IsMachineToMachine); | ||
Assert.False(nonGeographicPhoneNumber.IsPremiumRate); | ||
Assert.False(nonGeographicPhoneNumber.IsSharedCost); | ||
Assert.Null(nonGeographicPhoneNumber.NationalDestinationCode); | ||
Assert.Equal(subscriberNumber, nonGeographicPhoneNumber.SubscriberNumber); | ||
} | ||
|
||
[Theory] | ||
[InlineData("9000000", "9000000")] | ||
[InlineData("9019999", "9019999")] | ||
[InlineData("9060000", "9060000")] | ||
[InlineData("9069999", "9069999")] | ||
public void Parse_Known_NonGeographicPhoneNumber_PremiumRate(string value, string subscriberNumber) | ||
{ | ||
var parseResult = s_parser.Parse(value); | ||
parseResult.ThrowIfFailure(); | ||
|
||
var phoneNumber = parseResult.PhoneNumber; | ||
|
||
Assert.NotNull(phoneNumber); | ||
Assert.IsType<NonGeographicPhoneNumber>(phoneNumber); | ||
|
||
var nonGeographicPhoneNumber = (NonGeographicPhoneNumber)phoneNumber; | ||
Assert.Equal(CountryInfo.Liechtenstein, nonGeographicPhoneNumber.Country); | ||
Assert.False(nonGeographicPhoneNumber.IsFreephone); | ||
Assert.False(nonGeographicPhoneNumber.IsMachineToMachine); | ||
Assert.True(nonGeographicPhoneNumber.IsPremiumRate); | ||
Assert.False(nonGeographicPhoneNumber.IsSharedCost); | ||
Assert.Null(nonGeographicPhoneNumber.NationalDestinationCode); | ||
Assert.Equal(subscriberNumber, nonGeographicPhoneNumber.SubscriberNumber); | ||
} | ||
|
||
[Theory] | ||
[InlineData("8400000", "8400000")] | ||
[InlineData("8499999", "8499999")] | ||
public void Parse_Known_NonGeographicPhoneNumber_SharedCost(string value, string subscriberNumber) | ||
{ | ||
var parseResult = s_parser.Parse(value); | ||
parseResult.ThrowIfFailure(); | ||
|
||
var phoneNumber = parseResult.PhoneNumber; | ||
|
||
Assert.NotNull(phoneNumber); | ||
Assert.IsType<NonGeographicPhoneNumber>(phoneNumber); | ||
|
||
var nonGeographicPhoneNumber = (NonGeographicPhoneNumber)phoneNumber; | ||
Assert.Equal(CountryInfo.Liechtenstein, nonGeographicPhoneNumber.Country); | ||
Assert.False(nonGeographicPhoneNumber.IsFreephone); | ||
Assert.False(nonGeographicPhoneNumber.IsMachineToMachine); | ||
Assert.False(nonGeographicPhoneNumber.IsPremiumRate); | ||
Assert.True(nonGeographicPhoneNumber.IsSharedCost); | ||
Assert.Null(nonGeographicPhoneNumber.NationalDestinationCode); | ||
Assert.Equal(subscriberNumber, nonGeographicPhoneNumber.SubscriberNumber); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule phone-number-utilities-testgenerator
updated
1 files
+1 −0 | src/PhoneNumbers.Utilities.TestGenerator/TestFileWriter.cs |