diff --git a/lib/src/parsers/_national_number_parser.dart b/lib/src/parsers/_national_number_parser.dart index 461950e..3458bcd 100644 --- a/lib/src/parsers/_national_number_parser.dart +++ b/lib/src/parsers/_national_number_parser.dart @@ -73,9 +73,7 @@ abstract class NationalNumberParser { var transformed = transformRule; bool shouldContinueLoop(int i) => - match.groupCount >= i && - match.group(i) != null && - transformed.contains('\$$i'); + match.groupCount >= i && match.group(i) != null; for (var i = 1; shouldContinueLoop(i); i++) { transformed = transformed.replaceFirst('\$$i', match.group(i)!); } diff --git a/test/phone_number_test.dart b/test/phone_number_test.dart index d6296b4..9748f0c 100644 --- a/test/phone_number_test.dart +++ b/test/phone_number_test.dart @@ -407,4 +407,50 @@ void main() { expect(zero.isSequentialTo(two), isFalse); }); }); + group( + 'format national phone number if transformRule does not start with \$1. example: (\$2 15-\$3-\$4)(AR)', + () { + test('should format argentinian phone numbers', () { + String format(String phoneNumber) => + PhoneNumber.parse(phoneNumber, destinationCountry: IsoCode.AR) + .formatNsn(); + var testNumber = ''; + expect(format(testNumber), equals('')); + testNumber = '5'; + expect(format(testNumber), equals('5')); + testNumber = '54'; + expect(format(testNumber), equals('54')); + testNumber = '549'; + expect(format(testNumber), equals('549')); + testNumber = '5492'; + expect(format(testNumber), equals('5492')); + testNumber = '54926'; + expect(format(testNumber), equals('54926')); + testNumber = '549261'; + expect(format(testNumber), equals('549261')); + testNumber = '5492615'; + expect(format(testNumber), equals('5492615')); + testNumber = '54926153'; + expect(format(testNumber), equals('54926153')); + testNumber = '549261532'; + expect(format(testNumber), equals('549261532')); + testNumber = '5492615325'; + expect(format(testNumber), equals('5492615325')); + + testNumber = '54926153256'; + expect(format(testNumber), equals('54926153256')); + testNumber = '549261532565'; + expect(format(testNumber), equals('549261532565')); + testNumber = '5492615325656'; + expect(format(testNumber), equals('261 15-532-5656')); + testNumber = '+5492615325656'; + expect(format(testNumber), equals('261 15-532-5656')); + testNumber = '54 9 261-5325 656'; + expect(format(testNumber), equals('261 15-532-5656')); + testNumber = '54-9-261-5325-656'; + expect(format(testNumber), equals('261 15-532-5656')); + testNumber = '54.9.261.5325.656'; + expect(format(testNumber), equals('261 15-532-5656')); + }); + }); }