def testAYTFShortNumberFormatting_AR(self): # Python version extra test: use real metadata so that the check for accrued digits already # matching a format fires. formatter = AsYouTypeFormatter("AR") self.assertEqual("1", formatter.input_digit('1')) self.assertEqual("10", formatter.input_digit('0')) self.assertEqual("101", formatter.input_digit('1'))
class PhoneInput(TextInput): text_validate_unfocus = False def __init__(self, **kwargs): super().__init__(**kwargs) self.formatter = AsYouTypeFormatter('US') def format_number_field(self): # get the text left of the cursor position, # filter out non-digits, and store the length digits_before_cursor = len( re.sub(r'\D', '', self.text[:self.cursor_index()])) # reset the formatter's stored result self.formatter.clear() # input all digits from the text field to the formatter # this is inefficient and not how the formatter is meant # to be used, but it works. number = re.sub(r'\D', '', self.text) for d in number: self.formatter.input_digit(d) self.text = self.formatter._current_output # modifying self.text resets cursor position, so here # we correct the cursor position by ensuring the same # number of digits are to the left of the cursor digit_count = 0 for i, c in enumerate(self.text): if digit_count == digits_before_cursor: self.cursor = (i, 0) break elif c.isdigit(): digit_count += 1 def insert_text(self, substring, from_undo=False): # limit text length to 16 characters substring = substring[:16 - len(self.text)] # remove non-digits from user input substring = re.sub(r'\D', '', substring) # insert the text super().insert_text(substring, from_undo) # reformat the field self.format_number_field() def keyboard_on_key_up(self, window, keycode): super().keyboard_on_key_up(window, keycode) # if the text field was modified, we need to reformat it if keycode[1] == 'backspace': self.format_number_field()
def testAYTFNZMobile(self): formatter = AsYouTypeFormatter("NZ") self.assertEquals("0", formatter.input_digit("0")) self.assertEquals("02", formatter.input_digit("2")) self.assertEquals("021", formatter.input_digit("1")) self.assertEquals("02-11", formatter.input_digit("1")) self.assertEquals("02-112", formatter.input_digit("2")) # Note the unittest is using fake metadata which might produce non-ideal results. self.assertEquals("02-112 3", formatter.input_digit("3")) self.assertEquals("02-112 34", formatter.input_digit("4")) self.assertEquals("02-112 345", formatter.input_digit("5")) self.assertEquals("02-112 3456", formatter.input_digit("6"))
def testEdgeCases(self): # Python version extra tests for coverage metadataXX = PhoneMetadata( id='XX', country_code=384, international_prefix='011', general_desc=PhoneNumberDesc(national_number_pattern='\\d{10}', possible_number_pattern='\\d{6,10}'), fixed_line=PhoneNumberDesc(national_number_pattern='NA', possible_number_pattern='NA'), mobile=PhoneNumberDesc(national_number_pattern='NA', possible_number_pattern='NA'), national_prefix=u'0', national_prefix_for_parsing=u'0', number_format=[ NumberFormat(pattern='([135][246]|[246][123])(\\d{4})(\\d{4})', format=u'\\1 \\2 \\3', leading_digits_pattern=['[1-59]|[78]0'], national_prefix_formatting_rule=u'(0\\1)') ]) PhoneMetadata.region_metadata['XX'] = metadataXX phonenumberutil.SUPPORTED_REGIONS.add("XX") phonenumberutil.COUNTRY_CODE_TO_REGION_CODE[384] = ("XX", ) formatter = AsYouTypeFormatter('XX') # A pattern with "|" in it doesn't get formatting self.assertEquals('1', formatter.input_digit('1')) self.assertEquals('12', formatter.input_digit('2')) self.assertEquals('123', formatter.input_digit('3')) self.assertEquals('1234', formatter.input_digit('4')) del phonenumberutil.COUNTRY_CODE_TO_REGION_CODE[384] phonenumberutil.SUPPORTED_REGIONS.remove('XX') del PhoneMetadata.region_metadata['XX'] # Hit internal error arm formatter._national_number = "" self.assertEquals("", formatter._input_accrued_national_number())
def testAYTFUSMobileShortCode(self): formatter = AsYouTypeFormatter("US") self.assertEquals("*", formatter.input_digit('*')) self.assertEquals("*1", formatter.input_digit('1')) self.assertEquals("*12", formatter.input_digit('2')) self.assertEquals("*121", formatter.input_digit('1')) self.assertEquals("*121#", formatter.input_digit('#'))
def testAYTFUSMobileShortCode(self): formatter = AsYouTypeFormatter("US") self.assertEquals("*", formatter.input_digit("*")) self.assertEquals("*1", formatter.input_digit("1")) self.assertEquals("*12", formatter.input_digit("2")) self.assertEquals("*121", formatter.input_digit("1")) self.assertEquals("*121#", formatter.input_digit("#"))
def _input_phone_number(self, prompt, color=(TextFormats.CYAN + TextFormats.UNDERLINE)): formatter = AsYouTypeFormatter("US") c = 'x' print(colorize("${}:$".format(prompt), color)) while not c.isdigit(): c = getch() while c != '\r': while not c.isdigit() and c != '\r': c = getch() if c == '\r': break phone_number = formatter.input_digit(c) print(phone_number, end='\r') c = 'x' sys.stdout.write('\n') try: parse(phone_number, "US") except NumberParseException: phone_number = self._input_phone_number( "Enter valid geographical" + " phone number", TextFormats.YELLOW) return phone_number
def testEdgeCases(self): # Python version extra tests for coverage metadataXX = PhoneMetadata(id='XX', country_code=384, international_prefix='011', general_desc=PhoneNumberDesc(national_number_pattern='\\d{10}', possible_number_pattern='\\d{6,10}'), fixed_line=PhoneNumberDesc(national_number_pattern='NA', possible_number_pattern='NA'), mobile=PhoneNumberDesc(national_number_pattern='NA', possible_number_pattern='NA'), national_prefix=u'0', national_prefix_for_parsing=u'0', number_format=[NumberFormat(pattern='([135][246]|[246][123])(\\d{4})(\\d{4})', format=u'\\1 \\2 \\3', leading_digits_pattern=['[1-59]|[78]0'], national_prefix_formatting_rule=u'(0\\1)')]) PhoneMetadata.region_metadata['XX'] = metadataXX phonenumberutil.SUPPORTED_REGIONS.add("XX") phonenumberutil.COUNTRY_CODE_TO_REGION_CODE[384] = ("XX",) formatter = AsYouTypeFormatter('XX') # A pattern with "|" in it doesn't get formatting self.assertEquals('1', formatter.input_digit('1')) self.assertEquals('12', formatter.input_digit('2')) self.assertEquals('123', formatter.input_digit('3')) self.assertEquals('1234', formatter.input_digit('4')) del phonenumberutil.COUNTRY_CODE_TO_REGION_CODE[384] phonenumberutil.SUPPORTED_REGIONS.remove('XX') del PhoneMetadata.region_metadata['XX'] # Hit internal error arm formatter._national_number = "" self.assertEquals("", formatter._input_accrued_national_number())
def testAYTFARMobile(self): formatter = AsYouTypeFormatter("AR") self.assertEquals("+", formatter.input_digit("+")) self.assertEquals("+5", formatter.input_digit("5")) self.assertEquals("+54 ", formatter.input_digit("4")) self.assertEquals("+54 9", formatter.input_digit("9")) self.assertEquals("+54 91", formatter.input_digit("1")) self.assertEquals("+54 9 11", formatter.input_digit("1")) self.assertEquals("+54 9 11 2", formatter.input_digit("2")) self.assertEquals("+54 9 11 23", formatter.input_digit("3")) self.assertEquals("+54 9 11 231", formatter.input_digit("1")) self.assertEquals("+54 9 11 2312", formatter.input_digit("2")) self.assertEquals("+54 9 11 2312 1", formatter.input_digit("1")) self.assertEquals("+54 9 11 2312 12", formatter.input_digit("2")) self.assertEquals("+54 9 11 2312 123", formatter.input_digit("3")) self.assertEquals("+54 9 11 2312 1234", formatter.input_digit("4"))
def testInvalidRegion(self): formatter = AsYouTypeFormatter("ZZ") self.assertEquals("+", formatter.input_digit("+")) self.assertEquals("+4", formatter.input_digit("4")) self.assertEquals("+48 ", formatter.input_digit("8")) self.assertEquals("+48 8", formatter.input_digit("8")) self.assertEquals("+48 88", formatter.input_digit("8")) self.assertEquals("+48 88 1", formatter.input_digit("1")) self.assertEquals("+48 88 12", formatter.input_digit("2")) self.assertEquals("+48 88 123", formatter.input_digit("3")) self.assertEquals("+48 88 123 1", formatter.input_digit("1")) self.assertEquals("+48 88 123 12", formatter.input_digit("2")) formatter.clear() self.assertEquals("6", formatter.input_digit("6")) self.assertEquals("65", formatter.input_digit("5")) self.assertEquals("650", formatter.input_digit("0")) self.assertEquals("6502", formatter.input_digit("2")) self.assertEquals("65025", formatter.input_digit("5")) self.assertEquals("650253", formatter.input_digit("3"))
def testTooLongNumberMatchingMultipleLeadingDigits(self): # See http://code.google.com/p/libphonenumber/issues/detail?id=36 # The bug occurred last time for countries which have two # formatting rules with exactly the same leading digits pattern # but differ in length. formatter = AsYouTypeFormatter("ZZ") self.assertEquals("+", formatter.input_digit('+')) self.assertEquals("+8", formatter.input_digit('8')) self.assertEquals("+81 ", formatter.input_digit('1')) self.assertEquals("+81 9", formatter.input_digit('9')) self.assertEquals("+81 90", formatter.input_digit('0')) self.assertEquals("+81 90 1", formatter.input_digit('1')) self.assertEquals("+81 90 12", formatter.input_digit('2')) self.assertEquals("+81 90 123", formatter.input_digit('3')) self.assertEquals("+81 90 1234", formatter.input_digit('4')) self.assertEquals("+81 90 1234 5", formatter.input_digit('5')) self.assertEquals("+81 90 1234 56", formatter.input_digit('6')) self.assertEquals("+81 90 1234 567", formatter.input_digit('7')) self.assertEquals("+81 90 1234 5678", formatter.input_digit('8')) self.assertEquals("+81 90 12 345 6789", formatter.input_digit('9')) self.assertEquals("+81901234567890", formatter.input_digit('0'))
def __init__(self, **kwargs): super().__init__(**kwargs) self.formatter = AsYouTypeFormatter('US')
def testAYTFUS(self): formatter = AsYouTypeFormatter("US") self.assertEquals("6", formatter.input_digit('6')) self.assertEquals("65", formatter.input_digit('5')) self.assertEquals("650", formatter.input_digit('0')) self.assertEquals("650 2", formatter.input_digit('2')) self.assertEquals("650 25", formatter.input_digit('5')) self.assertEquals("650 253", formatter.input_digit('3')) # Note this is how a US local number (without area code) should be formatted. self.assertEquals("650 2532", formatter.input_digit('2')) self.assertEquals("650 253 22", formatter.input_digit('2')) self.assertEquals("650 253 222", formatter.input_digit('2')) self.assertEquals("650 253 2222", formatter.input_digit('2')) formatter.clear() self.assertEquals("1", formatter.input_digit('1')) self.assertEquals("16", formatter.input_digit('6')) self.assertEquals("1 65", formatter.input_digit('5')) self.assertEquals("1 650", formatter.input_digit('0')) self.assertEquals("1 650 2", formatter.input_digit('2')) self.assertEquals("1 650 25", formatter.input_digit('5')) self.assertEquals("1 650 253", formatter.input_digit('3')) self.assertEquals("1 650 253 2", formatter.input_digit('2')) self.assertEquals("1 650 253 22", formatter.input_digit('2')) self.assertEquals("1 650 253 222", formatter.input_digit('2')) self.assertEquals("1 650 253 2222", formatter.input_digit('2')) formatter.clear() self.assertEquals("0", formatter.input_digit('0')) self.assertEquals("01", formatter.input_digit('1')) self.assertEquals("011 ", formatter.input_digit('1')) self.assertEquals("011 4", formatter.input_digit('4')) self.assertEquals("011 44 ", formatter.input_digit('4')) self.assertEquals("011 44 6", formatter.input_digit('6')) self.assertEquals("011 44 61", formatter.input_digit('1')) self.assertEquals("011 44 6 12", formatter.input_digit('2')) self.assertEquals("011 44 6 123", formatter.input_digit('3')) self.assertEquals("011 44 6 123 1", formatter.input_digit('1')) self.assertEquals("011 44 6 123 12", formatter.input_digit('2')) self.assertEquals("011 44 6 123 123", formatter.input_digit('3')) self.assertEquals("011 44 6 123 123 1", formatter.input_digit('1')) self.assertEquals("011 44 6 123 123 12", formatter.input_digit('2')) self.assertEquals("011 44 6 123 123 123", formatter.input_digit('3')) formatter.clear() self.assertEquals("0", formatter.input_digit('0')) self.assertEquals("01", formatter.input_digit('1')) self.assertEquals("011 ", formatter.input_digit('1')) self.assertEquals("011 5", formatter.input_digit('5')) self.assertEquals("011 54 ", formatter.input_digit('4')) self.assertEquals("011 54 9", formatter.input_digit('9')) self.assertEquals("011 54 91", formatter.input_digit('1')) self.assertEquals("011 54 9 11", formatter.input_digit('1')) self.assertEquals("011 54 9 11 2", formatter.input_digit('2')) self.assertEquals("011 54 9 11 23", formatter.input_digit('3')) self.assertEquals("011 54 9 11 231", formatter.input_digit('1')) self.assertEquals("011 54 9 11 2312", formatter.input_digit('2')) self.assertEquals("011 54 9 11 2312 1", formatter.input_digit('1')) self.assertEquals("011 54 9 11 2312 12", formatter.input_digit('2')) self.assertEquals("011 54 9 11 2312 123", formatter.input_digit('3')) self.assertEquals("011 54 9 11 2312 1234", formatter.input_digit('4')) formatter.clear() self.assertEquals("0", formatter.input_digit('0')) self.assertEquals("01", formatter.input_digit('1')) self.assertEquals("011 ", formatter.input_digit('1')) self.assertEquals("011 2", formatter.input_digit('2')) self.assertEquals("011 24", formatter.input_digit('4')) self.assertEquals("011 244 ", formatter.input_digit('4')) self.assertEquals("011 244 2", formatter.input_digit('2')) self.assertEquals("011 244 28", formatter.input_digit('8')) self.assertEquals("011 244 280", formatter.input_digit('0')) self.assertEquals("011 244 280 0", formatter.input_digit('0')) self.assertEquals("011 244 280 00", formatter.input_digit('0')) self.assertEquals("011 244 280 000", formatter.input_digit('0')) self.assertEquals("011 244 280 000 0", formatter.input_digit('0')) self.assertEquals("011 244 280 000 00", formatter.input_digit('0')) self.assertEquals("011 244 280 000 000", formatter.input_digit('0')) formatter.clear() self.assertEquals("+", formatter.input_digit('+')) self.assertEquals("+4", formatter.input_digit('4')) self.assertEquals("+48 ", formatter.input_digit('8')) self.assertEquals("+48 8", formatter.input_digit('8')) self.assertEquals("+48 88", formatter.input_digit('8')) self.assertEquals("+48 88 1", formatter.input_digit('1')) self.assertEquals("+48 88 12", formatter.input_digit('2')) self.assertEquals("+48 88 123", formatter.input_digit('3')) self.assertEquals("+48 88 123 1", formatter.input_digit('1')) self.assertEquals("+48 88 123 12", formatter.input_digit('2')) self.assertEquals("+48 88 123 12 1", formatter.input_digit('1')) self.assertEquals("+48 88 123 12 12", formatter.input_digit('2')) # Python version extra test: invalid country code after IDD formatter.clear() self.assertEquals('0', formatter.input_digit('0')) self.assertEquals('01', formatter.input_digit('1')) self.assertEquals('011 ', formatter.input_digit('1')) self.assertEquals('011 4', formatter.input_digit('4')) self.assertEquals('011 42', formatter.input_digit('2')) self.assertEquals('011422', formatter.input_digit('2')) self.assertEquals('0114221', formatter.input_digit('1')) self.assertEquals('01142212', formatter.input_digit('2')) self.assertEquals('011422123', formatter.input_digit('3'))
def testAYTFMultipleLeadingDigitPatterns(self): # +81 50 2345 6789 formatter = AsYouTypeFormatter("JP") self.assertEquals("+", formatter.input_digit('+')) self.assertEquals("+8", formatter.input_digit('8')) self.assertEquals("+81 ", formatter.input_digit('1')) self.assertEquals("+81 5", formatter.input_digit('5')) self.assertEquals("+81 50", formatter.input_digit('0')) self.assertEquals("+81 50 2", formatter.input_digit('2')) self.assertEquals("+81 50 23", formatter.input_digit('3')) self.assertEquals("+81 50 234", formatter.input_digit('4')) self.assertEquals("+81 50 2345", formatter.input_digit('5')) self.assertEquals("+81 50 2345 6", formatter.input_digit('6')) self.assertEquals("+81 50 2345 67", formatter.input_digit('7')) self.assertEquals("+81 50 2345 678", formatter.input_digit('8')) self.assertEquals("+81 50 2345 6789", formatter.input_digit('9')) # +81 222 12 5678 formatter.clear() self.assertEquals("+", formatter.input_digit('+')) self.assertEquals("+8", formatter.input_digit('8')) self.assertEquals("+81 ", formatter.input_digit('1')) self.assertEquals("+81 2", formatter.input_digit('2')) self.assertEquals("+81 22", formatter.input_digit('2')) self.assertEquals("+81 22 2", formatter.input_digit('2')) self.assertEquals("+81 22 21", formatter.input_digit('1')) self.assertEquals("+81 2221 2", formatter.input_digit('2')) self.assertEquals("+81 222 12 5", formatter.input_digit('5')) self.assertEquals("+81 222 12 56", formatter.input_digit('6')) self.assertEquals("+81 222 12 567", formatter.input_digit('7')) self.assertEquals("+81 222 12 5678", formatter.input_digit('8')) # +81 3332 2 5678 formatter.clear() self.assertEquals("+", formatter.input_digit('+')) self.assertEquals("+8", formatter.input_digit('8')) self.assertEquals("+81 ", formatter.input_digit('1')) self.assertEquals("+81 3", formatter.input_digit('3')) self.assertEquals("+81 33", formatter.input_digit('3')) self.assertEquals("+81 33 3", formatter.input_digit('3')) self.assertEquals("+81 3332", formatter.input_digit('2')) self.assertEquals("+81 3332 2", formatter.input_digit('2')) self.assertEquals("+81 3332 2 5", formatter.input_digit('5')) self.assertEquals("+81 3332 2 56", formatter.input_digit('6')) self.assertEquals("+81 3332 2 567", formatter.input_digit('7')) self.assertEquals("+81 3332 2 5678", formatter.input_digit('8'))
def testAYTF_MX(self): formatter = AsYouTypeFormatter("MX") # +52 800 123 4567 self.assertEquals("+", formatter.input_digit('+')) self.assertEquals("+5", formatter.input_digit('5')) self.assertEquals("+52 ", formatter.input_digit('2')) self.assertEquals("+52 8", formatter.input_digit('8')) self.assertEquals("+52 80", formatter.input_digit('0')) self.assertEquals("+52 800", formatter.input_digit('0')) self.assertEquals("+52 800 1", formatter.input_digit('1')) self.assertEquals("+52 800 12", formatter.input_digit('2')) self.assertEquals("+52 800 123", formatter.input_digit('3')) self.assertEquals("+52 800 123 4", formatter.input_digit('4')) self.assertEquals("+52 800 123 45", formatter.input_digit('5')) self.assertEquals("+52 800 123 456", formatter.input_digit('6')) self.assertEquals("+52 800 123 4567", formatter.input_digit('7')) # +52 55 1234 5678 formatter.clear() self.assertEquals("+", formatter.input_digit('+')) self.assertEquals("+5", formatter.input_digit('5')) self.assertEquals("+52 ", formatter.input_digit('2')) self.assertEquals("+52 5", formatter.input_digit('5')) self.assertEquals("+52 55", formatter.input_digit('5')) self.assertEquals("+52 55 1", formatter.input_digit('1')) self.assertEquals("+52 55 12", formatter.input_digit('2')) self.assertEquals("+52 55 123", formatter.input_digit('3')) self.assertEquals("+52 55 1234", formatter.input_digit('4')) self.assertEquals("+52 55 1234 5", formatter.input_digit('5')) self.assertEquals("+52 55 1234 56", formatter.input_digit('6')) self.assertEquals("+52 55 1234 567", formatter.input_digit('7')) self.assertEquals("+52 55 1234 5678", formatter.input_digit('8')) # +52 212 345 6789 formatter.clear() self.assertEquals("+", formatter.input_digit('+')) self.assertEquals("+5", formatter.input_digit('5')) self.assertEquals("+52 ", formatter.input_digit('2')) self.assertEquals("+52 2", formatter.input_digit('2')) self.assertEquals("+52 21", formatter.input_digit('1')) self.assertEquals("+52 212", formatter.input_digit('2')) self.assertEquals("+52 212 3", formatter.input_digit('3')) self.assertEquals("+52 212 34", formatter.input_digit('4')) self.assertEquals("+52 212 345", formatter.input_digit('5')) self.assertEquals("+52 212 345 6", formatter.input_digit('6')) self.assertEquals("+52 212 345 67", formatter.input_digit('7')) self.assertEquals("+52 212 345 678", formatter.input_digit('8')) self.assertEquals("+52 212 345 6789", formatter.input_digit('9')) # +52 1 55 1234 5678 formatter.clear() self.assertEquals("+", formatter.input_digit('+')) self.assertEquals("+5", formatter.input_digit('5')) self.assertEquals("+52 ", formatter.input_digit('2')) self.assertEquals("+52 1", formatter.input_digit('1')) self.assertEquals("+52 15", formatter.input_digit('5')) self.assertEquals("+52 1 55", formatter.input_digit('5')) self.assertEquals("+52 1 55 1", formatter.input_digit('1')) self.assertEquals("+52 1 55 12", formatter.input_digit('2')) self.assertEquals("+52 1 55 123", formatter.input_digit('3')) self.assertEquals("+52 1 55 1234", formatter.input_digit('4')) self.assertEquals("+52 1 55 1234 5", formatter.input_digit('5')) self.assertEquals("+52 1 55 1234 56", formatter.input_digit('6')) self.assertEquals("+52 1 55 1234 567", formatter.input_digit('7')) self.assertEquals("+52 1 55 1234 5678", formatter.input_digit('8')) # +52 1 541 234 5678 formatter.clear() self.assertEquals("+", formatter.input_digit('+')) self.assertEquals("+5", formatter.input_digit('5')) self.assertEquals("+52 ", formatter.input_digit('2')) self.assertEquals("+52 1", formatter.input_digit('1')) self.assertEquals("+52 15", formatter.input_digit('5')) self.assertEquals("+52 1 54", formatter.input_digit('4')) self.assertEquals("+52 1 541", formatter.input_digit('1')) self.assertEquals("+52 1 541 2", formatter.input_digit('2')) self.assertEquals("+52 1 541 23", formatter.input_digit('3')) self.assertEquals("+52 1 541 234", formatter.input_digit('4')) self.assertEquals("+52 1 541 234 5", formatter.input_digit('5')) self.assertEquals("+52 1 541 234 56", formatter.input_digit('6')) self.assertEquals("+52 1 541 234 567", formatter.input_digit('7')) self.assertEquals("+52 1 541 234 5678", formatter.input_digit('8'))
def testAYTFAndRememberPositionUS(self): formatter = AsYouTypeFormatter("US") self.assertEquals("1", formatter.input_digit('1', remember_position=True)) self.assertEquals(1, formatter.get_remembered_position()) self.assertEquals("16", formatter.input_digit('6')) self.assertEquals("1 65", formatter.input_digit('5')) self.assertEquals(1, formatter.get_remembered_position()) self.assertEquals("1 650", formatter.input_digit('0', remember_position=True)) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("1 650 2", formatter.input_digit('2')) self.assertEquals("1 650 25", formatter.input_digit('5')) # Note the remembered position for digit "0" changes from 4 to 5, because a space is now # inserted in the front. self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("1 650 253", formatter.input_digit('3')) self.assertEquals("1 650 253 2", formatter.input_digit('2')) self.assertEquals("1 650 253 22", formatter.input_digit('2')) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("1 650 253 222", formatter.input_digit('2', remember_position=True)) self.assertEquals(13, formatter.get_remembered_position()) self.assertEquals("1 650 253 2222", formatter.input_digit('2')) self.assertEquals(13, formatter.get_remembered_position()) self.assertEquals("165025322222", formatter.input_digit('2')) self.assertEquals(10, formatter.get_remembered_position()) self.assertEquals("1650253222222", formatter.input_digit('2')) self.assertEquals(10, formatter.get_remembered_position()) formatter.clear() self.assertEquals("1", formatter.input_digit('1')) self.assertEquals("16", formatter.input_digit('6', remember_position=True)) self.assertEquals(2, formatter.get_remembered_position()) self.assertEquals("1 65", formatter.input_digit('5')) self.assertEquals("1 650", formatter.input_digit('0')) self.assertEquals(3, formatter.get_remembered_position()) self.assertEquals("1 650 2", formatter.input_digit('2')) self.assertEquals("1 650 25", formatter.input_digit('5')) self.assertEquals(3, formatter.get_remembered_position()) self.assertEquals("1 650 253", formatter.input_digit('3')) self.assertEquals("1 650 253 2", formatter.input_digit('2')) self.assertEquals("1 650 253 22", formatter.input_digit('2')) self.assertEquals(3, formatter.get_remembered_position()) self.assertEquals("1 650 253 222", formatter.input_digit('2')) self.assertEquals("1 650 253 2222", formatter.input_digit('2')) self.assertEquals("165025322222", formatter.input_digit('2')) self.assertEquals(2, formatter.get_remembered_position()) self.assertEquals("1650253222222", formatter.input_digit('2')) self.assertEquals(2, formatter.get_remembered_position()) formatter.clear() self.assertEquals("6", formatter.input_digit('6')) self.assertEquals("65", formatter.input_digit('5')) self.assertEquals("650", formatter.input_digit('0')) self.assertEquals("650 2", formatter.input_digit('2')) self.assertEquals("650 25", formatter.input_digit('5')) self.assertEquals("650 253", formatter.input_digit('3')) self.assertEquals("650 2532", formatter.input_digit('2', remember_position=True)) self.assertEquals(8, formatter.get_remembered_position()) self.assertEquals("650 253 22", formatter.input_digit('2')) self.assertEquals(9, formatter.get_remembered_position()) self.assertEquals("650 253 222", formatter.input_digit('2')) # No more formatting when semicolon is entered. self.assertEquals("650253222;", formatter.input_digit(';')) self.assertEquals(7, formatter.get_remembered_position()) self.assertEquals("650253222;2", formatter.input_digit('2')) formatter.clear() self.assertEquals("6", formatter.input_digit('6')) self.assertEquals("65", formatter.input_digit('5')) self.assertEquals("650", formatter.input_digit('0')) # No more formatting when users choose to do their own formatting. self.assertEquals("650-", formatter.input_digit('-')) self.assertEquals("650-2", formatter.input_digit('2', remember_position=True)) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("650-25", formatter.input_digit('5')) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("650-253", formatter.input_digit('3')) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("650-253-", formatter.input_digit('-')) self.assertEquals("650-253-2", formatter.input_digit('2')) self.assertEquals("650-253-22", formatter.input_digit('2')) self.assertEquals("650-253-222", formatter.input_digit('2')) self.assertEquals("650-253-2222", formatter.input_digit('2')) formatter.clear() self.assertEquals("0", formatter.input_digit('0')) self.assertEquals("01", formatter.input_digit('1')) self.assertEquals("011 ", formatter.input_digit('1')) self.assertEquals("011 4", formatter.input_digit('4', remember_position=True)) self.assertEquals("011 48 ", formatter.input_digit('8')) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("011 48 8", formatter.input_digit('8')) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("011 48 88", formatter.input_digit('8')) self.assertEquals("011 48 88 1", formatter.input_digit('1')) self.assertEquals("011 48 88 12", formatter.input_digit('2')) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("011 48 88 123", formatter.input_digit('3')) self.assertEquals("011 48 88 123 1", formatter.input_digit('1')) self.assertEquals("011 48 88 123 12", formatter.input_digit('2')) self.assertEquals("011 48 88 123 12 1", formatter.input_digit('1')) self.assertEquals("011 48 88 123 12 12", formatter.input_digit('2')) formatter.clear() self.assertEquals("+", formatter.input_digit('+')) self.assertEquals("+1", formatter.input_digit('1')) self.assertEquals("+1 6", formatter.input_digit('6', remember_position=True)) self.assertEquals("+1 65", formatter.input_digit('5')) self.assertEquals("+1 650", formatter.input_digit('0')) self.assertEquals(4, formatter.get_remembered_position()) self.assertEquals("+1 650 2", formatter.input_digit('2')) self.assertEquals(4, formatter.get_remembered_position()) self.assertEquals("+1 650 25", formatter.input_digit('5')) self.assertEquals("+1 650 253", formatter.input_digit('3', remember_position=True)) self.assertEquals("+1 650 253 2", formatter.input_digit('2')) self.assertEquals("+1 650 253 22", formatter.input_digit('2')) self.assertEquals("+1 650 253 222", formatter.input_digit('2')) self.assertEquals(10, formatter.get_remembered_position()) formatter.clear() self.assertEquals("+", formatter.input_digit('+')) self.assertEquals("+1", formatter.input_digit('1')) self.assertEquals("+1 6", formatter.input_digit('6', remember_position=True)) self.assertEquals("+1 65", formatter.input_digit('5')) self.assertEquals("+1 650", formatter.input_digit('0')) self.assertEquals(4, formatter.get_remembered_position()) self.assertEquals("+1 650 2", formatter.input_digit('2')) self.assertEquals(4, formatter.get_remembered_position()) self.assertEquals("+1 650 25", formatter.input_digit('5')) self.assertEquals("+1 650 253", formatter.input_digit('3')) self.assertEquals("+1 650 253 2", formatter.input_digit('2')) self.assertEquals("+1 650 253 22", formatter.input_digit('2')) self.assertEquals("+1 650 253 222", formatter.input_digit('2')) self.assertEquals("+1650253222;", formatter.input_digit(';')) self.assertEquals(3, formatter.get_remembered_position())
def testAYTFUSVanityNumber(self): formatter = AsYouTypeFormatter("US") self.assertEquals("8", formatter.input_digit('8')) self.assertEquals("80", formatter.input_digit('0')) self.assertEquals("800", formatter.input_digit('0')) self.assertEquals("800 ", formatter.input_digit(' ')) self.assertEquals("800 M", formatter.input_digit('M')) self.assertEquals("800 MY", formatter.input_digit('Y')) self.assertEquals("800 MY ", formatter.input_digit(' ')) self.assertEquals("800 MY A", formatter.input_digit('A')) self.assertEquals("800 MY AP", formatter.input_digit('P')) self.assertEquals("800 MY APP", formatter.input_digit('P')) self.assertEquals("800 MY APPL", formatter.input_digit('L')) self.assertEquals("800 MY APPLE", formatter.input_digit('E'))
def testAYTFKR(self): # +82 51 234 5678 formatter = AsYouTypeFormatter("KR") self.assertEquals("+", formatter.input_digit('+')) self.assertEquals("+8", formatter.input_digit('8')) self.assertEquals("+82 ", formatter.input_digit('2')) self.assertEquals("+82 5", formatter.input_digit('5')) self.assertEquals("+82 51", formatter.input_digit('1')) self.assertEquals("+82 51-2", formatter.input_digit('2')) self.assertEquals("+82 51-23", formatter.input_digit('3')) self.assertEquals("+82 51-234", formatter.input_digit('4')) self.assertEquals("+82 51-234-5", formatter.input_digit('5')) self.assertEquals("+82 51-234-56", formatter.input_digit('6')) self.assertEquals("+82 51-234-567", formatter.input_digit('7')) self.assertEquals("+82 51-234-5678", formatter.input_digit('8')) # +82 2 531 5678 formatter.clear() self.assertEquals("+", formatter.input_digit('+')) self.assertEquals("+8", formatter.input_digit('8')) self.assertEquals("+82 ", formatter.input_digit('2')) self.assertEquals("+82 2", formatter.input_digit('2')) self.assertEquals("+82 25", formatter.input_digit('5')) self.assertEquals("+82 2-53", formatter.input_digit('3')) self.assertEquals("+82 2-531", formatter.input_digit('1')) self.assertEquals("+82 2-531-5", formatter.input_digit('5')) self.assertEquals("+82 2-531-56", formatter.input_digit('6')) self.assertEquals("+82 2-531-567", formatter.input_digit('7')) self.assertEquals("+82 2-531-5678", formatter.input_digit('8')) # +82 2 3665 5678 formatter.clear() self.assertEquals("+", formatter.input_digit('+')) self.assertEquals("+8", formatter.input_digit('8')) self.assertEquals("+82 ", formatter.input_digit('2')) self.assertEquals("+82 2", formatter.input_digit('2')) self.assertEquals("+82 23", formatter.input_digit('3')) self.assertEquals("+82 2-36", formatter.input_digit('6')) self.assertEquals("+82 2-366", formatter.input_digit('6')) self.assertEquals("+82 2-3665", formatter.input_digit('5')) self.assertEquals("+82 2-3665-5", formatter.input_digit('5')) self.assertEquals("+82 2-3665-56", formatter.input_digit('6')) self.assertEquals("+82 2-3665-567", formatter.input_digit('7')) self.assertEquals("+82 2-3665-5678", formatter.input_digit('8')) # 02-114 formatter.clear() self.assertEquals("0", formatter.input_digit('0')) self.assertEquals("02", formatter.input_digit('2')) self.assertEquals("021", formatter.input_digit('1')) self.assertEquals("02-11", formatter.input_digit('1')) self.assertEquals("02-114", formatter.input_digit('4')) # 02-1300 formatter.clear() self.assertEquals("0", formatter.input_digit('0')) self.assertEquals("02", formatter.input_digit('2')) self.assertEquals("021", formatter.input_digit('1')) self.assertEquals("02-13", formatter.input_digit('3')) self.assertEquals("02-130", formatter.input_digit('0')) self.assertEquals("02-1300", formatter.input_digit('0')) # 011-456-7890 formatter.clear() self.assertEquals("0", formatter.input_digit('0')) self.assertEquals("01", formatter.input_digit('1')) self.assertEquals("011", formatter.input_digit('1')) self.assertEquals("011-4", formatter.input_digit('4')) self.assertEquals("011-45", formatter.input_digit('5')) self.assertEquals("011-456", formatter.input_digit('6')) self.assertEquals("011-456-7", formatter.input_digit('7')) self.assertEquals("011-456-78", formatter.input_digit('8')) self.assertEquals("011-456-789", formatter.input_digit('9')) self.assertEquals("011-456-7890", formatter.input_digit('0')) # 011-9876-7890 formatter.clear() self.assertEquals("0", formatter.input_digit('0')) self.assertEquals("01", formatter.input_digit('1')) self.assertEquals("011", formatter.input_digit('1')) self.assertEquals("011-9", formatter.input_digit('9')) self.assertEquals("011-98", formatter.input_digit('8')) self.assertEquals("011-987", formatter.input_digit('7')) self.assertEquals("011-9876", formatter.input_digit('6')) self.assertEquals("011-9876-7", formatter.input_digit('7')) self.assertEquals("011-9876-78", formatter.input_digit('8')) self.assertEquals("011-9876-789", formatter.input_digit('9')) self.assertEquals("011-9876-7890", formatter.input_digit('0'))
def testAYTFUSFullWidthCharacters(self): formatter = AsYouTypeFormatter("US") self.assertEquals(u"\uFF16", formatter.input_digit(u'\uFF16')) self.assertEquals(u"\uFF16\uFF15", formatter.input_digit(u'\uFF15')) self.assertEquals("650", formatter.input_digit(u'\uFF10')) self.assertEquals("650 2", formatter.input_digit(u'\uFF12')) self.assertEquals("650 25", formatter.input_digit(u'\uFF15')) self.assertEquals("650 253", formatter.input_digit(u'\uFF13')) self.assertEquals("650 2532", formatter.input_digit(u'\uFF12')) self.assertEquals("650 253 22", formatter.input_digit(u'\uFF12')) self.assertEquals("650 253 222", formatter.input_digit(u'\uFF12')) self.assertEquals("650 253 2222", formatter.input_digit(u'\uFF12'))
def testAYTFMultipleLeadingDigitPatterns(self): # +81 50 2345 6789 formatter = AsYouTypeFormatter("JP") self.assertEquals("+", formatter.input_digit("+")) self.assertEquals("+8", formatter.input_digit("8")) self.assertEquals("+81 ", formatter.input_digit("1")) self.assertEquals("+81 5", formatter.input_digit("5")) self.assertEquals("+81 50", formatter.input_digit("0")) self.assertEquals("+81 50 2", formatter.input_digit("2")) self.assertEquals("+81 50 23", formatter.input_digit("3")) self.assertEquals("+81 50 234", formatter.input_digit("4")) self.assertEquals("+81 50 2345", formatter.input_digit("5")) self.assertEquals("+81 50 2345 6", formatter.input_digit("6")) self.assertEquals("+81 50 2345 67", formatter.input_digit("7")) self.assertEquals("+81 50 2345 678", formatter.input_digit("8")) self.assertEquals("+81 50 2345 6789", formatter.input_digit("9")) # +81 222 12 5678 formatter.clear() self.assertEquals("+", formatter.input_digit("+")) self.assertEquals("+8", formatter.input_digit("8")) self.assertEquals("+81 ", formatter.input_digit("1")) self.assertEquals("+81 2", formatter.input_digit("2")) self.assertEquals("+81 22", formatter.input_digit("2")) self.assertEquals("+81 22 2", formatter.input_digit("2")) self.assertEquals("+81 22 21", formatter.input_digit("1")) self.assertEquals("+81 2221 2", formatter.input_digit("2")) self.assertEquals("+81 222 12 5", formatter.input_digit("5")) self.assertEquals("+81 222 12 56", formatter.input_digit("6")) self.assertEquals("+81 222 12 567", formatter.input_digit("7")) self.assertEquals("+81 222 12 5678", formatter.input_digit("8")) # +81 3332 2 5678 formatter.clear() self.assertEquals("+", formatter.input_digit("+")) self.assertEquals("+8", formatter.input_digit("8")) self.assertEquals("+81 ", formatter.input_digit("1")) self.assertEquals("+81 3", formatter.input_digit("3")) self.assertEquals("+81 33", formatter.input_digit("3")) self.assertEquals("+81 33 3", formatter.input_digit("3")) self.assertEquals("+81 3332", formatter.input_digit("2")) self.assertEquals("+81 3332 2", formatter.input_digit("2")) self.assertEquals("+81 3332 2 5", formatter.input_digit("5")) self.assertEquals("+81 3332 2 56", formatter.input_digit("6")) self.assertEquals("+81 3332 2 567", formatter.input_digit("7")) self.assertEquals("+81 3332 2 5678", formatter.input_digit("8"))
def testAYTFARMobile(self): formatter = AsYouTypeFormatter("AR") self.assertEquals("+", formatter.input_digit('+')) self.assertEquals("+5", formatter.input_digit('5')) self.assertEquals("+54 ", formatter.input_digit('4')) self.assertEquals("+54 9", formatter.input_digit('9')) self.assertEquals("+54 91", formatter.input_digit('1')) self.assertEquals("+54 9 11", formatter.input_digit('1')) self.assertEquals("+54 9 11 2", formatter.input_digit('2')) self.assertEquals("+54 9 11 23", formatter.input_digit('3')) self.assertEquals("+54 9 11 231", formatter.input_digit('1')) self.assertEquals("+54 9 11 2312", formatter.input_digit('2')) self.assertEquals("+54 9 11 2312 1", formatter.input_digit('1')) self.assertEquals("+54 9 11 2312 12", formatter.input_digit('2')) self.assertEquals("+54 9 11 2312 123", formatter.input_digit('3')) self.assertEquals("+54 9 11 2312 1234", formatter.input_digit('4'))
def testInvalidRegion(self): formatter = AsYouTypeFormatter("ZZ") self.assertEquals("+", formatter.input_digit('+')) self.assertEquals("+4", formatter.input_digit('4')) self.assertEquals("+48 ", formatter.input_digit('8')) self.assertEquals("+48 8", formatter.input_digit('8')) self.assertEquals("+48 88", formatter.input_digit('8')) self.assertEquals("+48 88 1", formatter.input_digit('1')) self.assertEquals("+48 88 12", formatter.input_digit('2')) self.assertEquals("+48 88 123", formatter.input_digit('3')) self.assertEquals("+48 88 123 1", formatter.input_digit('1')) self.assertEquals("+48 88 123 12", formatter.input_digit('2')) formatter.clear() self.assertEquals("6", formatter.input_digit('6')) self.assertEquals("65", formatter.input_digit('5')) self.assertEquals("650", formatter.input_digit('0')) self.assertEquals("6502", formatter.input_digit('2')) self.assertEquals("65025", formatter.input_digit('5')) self.assertEquals("650253", formatter.input_digit('3'))
def testAYTFAndRememberPositionUS(self): formatter = AsYouTypeFormatter("US") self.assertEquals("1", formatter.input_digit("1", remember_position=True)) self.assertEquals(1, formatter.get_remembered_position()) self.assertEquals("16", formatter.input_digit("6")) self.assertEquals("1 65", formatter.input_digit("5")) self.assertEquals(1, formatter.get_remembered_position()) self.assertEquals("1 650", formatter.input_digit("0", remember_position=True)) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("1 650 2", formatter.input_digit("2")) self.assertEquals("1 650 25", formatter.input_digit("5")) # Note the remembered position for digit "0" changes from 4 to 5, because a space is now # inserted in the front. self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("1 650 253", formatter.input_digit("3")) self.assertEquals("1 650 253 2", formatter.input_digit("2")) self.assertEquals("1 650 253 22", formatter.input_digit("2")) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("1 650 253 222", formatter.input_digit("2", remember_position=True)) self.assertEquals(13, formatter.get_remembered_position()) self.assertEquals("1 650 253 2222", formatter.input_digit("2")) self.assertEquals(13, formatter.get_remembered_position()) self.assertEquals("165025322222", formatter.input_digit("2")) self.assertEquals(10, formatter.get_remembered_position()) self.assertEquals("1650253222222", formatter.input_digit("2")) self.assertEquals(10, formatter.get_remembered_position()) formatter.clear() self.assertEquals("1", formatter.input_digit("1")) self.assertEquals("16", formatter.input_digit("6", remember_position=True)) self.assertEquals(2, formatter.get_remembered_position()) self.assertEquals("1 65", formatter.input_digit("5")) self.assertEquals("1 650", formatter.input_digit("0")) self.assertEquals(3, formatter.get_remembered_position()) self.assertEquals("1 650 2", formatter.input_digit("2")) self.assertEquals("1 650 25", formatter.input_digit("5")) self.assertEquals(3, formatter.get_remembered_position()) self.assertEquals("1 650 253", formatter.input_digit("3")) self.assertEquals("1 650 253 2", formatter.input_digit("2")) self.assertEquals("1 650 253 22", formatter.input_digit("2")) self.assertEquals(3, formatter.get_remembered_position()) self.assertEquals("1 650 253 222", formatter.input_digit("2")) self.assertEquals("1 650 253 2222", formatter.input_digit("2")) self.assertEquals("165025322222", formatter.input_digit("2")) self.assertEquals(2, formatter.get_remembered_position()) self.assertEquals("1650253222222", formatter.input_digit("2")) self.assertEquals(2, formatter.get_remembered_position()) formatter.clear() self.assertEquals("6", formatter.input_digit("6")) self.assertEquals("65", formatter.input_digit("5")) self.assertEquals("650", formatter.input_digit("0")) self.assertEquals("650 2", formatter.input_digit("2")) self.assertEquals("650 25", formatter.input_digit("5")) self.assertEquals("650 253", formatter.input_digit("3")) self.assertEquals("650 2532", formatter.input_digit("2", remember_position=True)) self.assertEquals(8, formatter.get_remembered_position()) self.assertEquals("650 253 22", formatter.input_digit("2")) self.assertEquals(9, formatter.get_remembered_position()) self.assertEquals("650 253 222", formatter.input_digit("2")) # No more formatting when semicolon is entered. self.assertEquals("650253222;", formatter.input_digit(";")) self.assertEquals(7, formatter.get_remembered_position()) self.assertEquals("650253222;2", formatter.input_digit("2")) formatter.clear() self.assertEquals("6", formatter.input_digit("6")) self.assertEquals("65", formatter.input_digit("5")) self.assertEquals("650", formatter.input_digit("0")) # No more formatting when users choose to do their own formatting. self.assertEquals("650-", formatter.input_digit("-")) self.assertEquals("650-2", formatter.input_digit("2", remember_position=True)) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("650-25", formatter.input_digit("5")) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("650-253", formatter.input_digit("3")) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("650-253-", formatter.input_digit("-")) self.assertEquals("650-253-2", formatter.input_digit("2")) self.assertEquals("650-253-22", formatter.input_digit("2")) self.assertEquals("650-253-222", formatter.input_digit("2")) self.assertEquals("650-253-2222", formatter.input_digit("2")) formatter.clear() self.assertEquals("0", formatter.input_digit("0")) self.assertEquals("01", formatter.input_digit("1")) self.assertEquals("011 ", formatter.input_digit("1")) self.assertEquals("011 4", formatter.input_digit("4", remember_position=True)) self.assertEquals("011 48 ", formatter.input_digit("8")) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("011 48 8", formatter.input_digit("8")) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("011 48 88", formatter.input_digit("8")) self.assertEquals("011 48 88 1", formatter.input_digit("1")) self.assertEquals("011 48 88 12", formatter.input_digit("2")) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("011 48 88 123", formatter.input_digit("3")) self.assertEquals("011 48 88 123 1", formatter.input_digit("1")) self.assertEquals("011 48 88 123 12", formatter.input_digit("2")) self.assertEquals("011 48 88 123 12 1", formatter.input_digit("1")) self.assertEquals("011 48 88 123 12 12", formatter.input_digit("2")) formatter.clear() self.assertEquals("+", formatter.input_digit("+")) self.assertEquals("+1", formatter.input_digit("1")) self.assertEquals("+1 6", formatter.input_digit("6", remember_position=True)) self.assertEquals("+1 65", formatter.input_digit("5")) self.assertEquals("+1 650", formatter.input_digit("0")) self.assertEquals(4, formatter.get_remembered_position()) self.assertEquals("+1 650 2", formatter.input_digit("2")) self.assertEquals(4, formatter.get_remembered_position()) self.assertEquals("+1 650 25", formatter.input_digit("5")) self.assertEquals("+1 650 253", formatter.input_digit("3", remember_position=True)) self.assertEquals("+1 650 253 2", formatter.input_digit("2")) self.assertEquals("+1 650 253 22", formatter.input_digit("2")) self.assertEquals("+1 650 253 222", formatter.input_digit("2")) self.assertEquals(10, formatter.get_remembered_position()) formatter.clear() self.assertEquals("+", formatter.input_digit("+")) self.assertEquals("+1", formatter.input_digit("1")) self.assertEquals("+1 6", formatter.input_digit("6", remember_position=True)) self.assertEquals("+1 65", formatter.input_digit("5")) self.assertEquals("+1 650", formatter.input_digit("0")) self.assertEquals(4, formatter.get_remembered_position()) self.assertEquals("+1 650 2", formatter.input_digit("2")) self.assertEquals(4, formatter.get_remembered_position()) self.assertEquals("+1 650 25", formatter.input_digit("5")) self.assertEquals("+1 650 253", formatter.input_digit("3")) self.assertEquals("+1 650 253 2", formatter.input_digit("2")) self.assertEquals("+1 650 253 22", formatter.input_digit("2")) self.assertEquals("+1 650 253 222", formatter.input_digit("2")) self.assertEquals("+1650253222;", formatter.input_digit(";")) self.assertEquals(3, formatter.get_remembered_position())
def testAYTFGBPremiumRate(self): formatter = AsYouTypeFormatter("GB") self.assertEquals("0", formatter.input_digit('0')) self.assertEquals("09", formatter.input_digit('9')) self.assertEquals("090", formatter.input_digit('0')) self.assertEquals("090 7", formatter.input_digit('7')) self.assertEquals("090 70", formatter.input_digit('0')) self.assertEquals("090 703", formatter.input_digit('3')) self.assertEquals("090 7031", formatter.input_digit('1')) self.assertEquals("090 7031 3", formatter.input_digit('3')) self.assertEquals("090 7031 30", formatter.input_digit('0')) self.assertEquals("090 7031 300", formatter.input_digit('0')) self.assertEquals("090 7031 3000", formatter.input_digit('0'))
def testAYTFGBTollFree(self): formatter = AsYouTypeFormatter("gb") self.assertEquals("0", formatter.input_digit("0")) self.assertEquals("08", formatter.input_digit("8")) self.assertEquals("080", formatter.input_digit("0")) self.assertEquals("080 7", formatter.input_digit("7")) self.assertEquals("080 70", formatter.input_digit("0")) self.assertEquals("080 703", formatter.input_digit("3")) self.assertEquals("080 7031", formatter.input_digit("1")) self.assertEquals("080 7031 3", formatter.input_digit("3")) self.assertEquals("080 7031 30", formatter.input_digit("0")) self.assertEquals("080 7031 300", formatter.input_digit("0")) self.assertEquals("080 7031 3000", formatter.input_digit("0"))
def testAYTFGBTollFree(self): formatter = AsYouTypeFormatter("GB") self.assertEquals("0", formatter.input_digit('0')) self.assertEquals("08", formatter.input_digit('8')) self.assertEquals("080", formatter.input_digit('0')) self.assertEquals("080 7", formatter.input_digit('7')) self.assertEquals("080 70", formatter.input_digit('0')) self.assertEquals("080 703", formatter.input_digit('3')) self.assertEquals("080 7031", formatter.input_digit('1')) self.assertEquals("080 7031 3", formatter.input_digit('3')) self.assertEquals("080 7031 30", formatter.input_digit('0')) self.assertEquals("080 7031 300", formatter.input_digit('0')) self.assertEquals("080 7031 3000", formatter.input_digit('0'))
def testAYTFDE(self): formatter = AsYouTypeFormatter("DE") self.assertEquals("0", formatter.input_digit('0')) self.assertEquals("03", formatter.input_digit('3')) self.assertEquals("030", formatter.input_digit('0')) self.assertEquals("030/1", formatter.input_digit('1')) self.assertEquals("030/12", formatter.input_digit('2')) self.assertEquals("030/123", formatter.input_digit('3')) self.assertEquals("030/1234", formatter.input_digit('4')) # 04134 1234 formatter.clear() self.assertEquals("0", formatter.input_digit('0')) self.assertEquals("04", formatter.input_digit('4')) self.assertEquals("041", formatter.input_digit('1')) self.assertEquals("041 3", formatter.input_digit('3')) self.assertEquals("041 34", formatter.input_digit('4')) self.assertEquals("04134 1", formatter.input_digit('1')) self.assertEquals("04134 12", formatter.input_digit('2')) self.assertEquals("04134 123", formatter.input_digit('3')) self.assertEquals("04134 1234", formatter.input_digit('4')) # 08021 2345 formatter.clear() self.assertEquals("0", formatter.input_digit('0')) self.assertEquals("08", formatter.input_digit('8')) self.assertEquals("080", formatter.input_digit('0')) self.assertEquals("080 2", formatter.input_digit('2')) self.assertEquals("080 21", formatter.input_digit('1')) self.assertEquals("08021 2", formatter.input_digit('2')) self.assertEquals("08021 23", formatter.input_digit('3')) self.assertEquals("08021 234", formatter.input_digit('4')) self.assertEquals("08021 2345", formatter.input_digit('5')) # 00 1 650 253 2250 formatter.clear() self.assertEquals("0", formatter.input_digit('0')) self.assertEquals("00", formatter.input_digit('0')) self.assertEquals("00 1 ", formatter.input_digit('1')) self.assertEquals("00 1 6", formatter.input_digit('6')) self.assertEquals("00 1 65", formatter.input_digit('5')) self.assertEquals("00 1 650", formatter.input_digit('0')) self.assertEquals("00 1 650 2", formatter.input_digit('2')) self.assertEquals("00 1 650 25", formatter.input_digit('5')) self.assertEquals("00 1 650 253", formatter.input_digit('3')) self.assertEquals("00 1 650 253 2", formatter.input_digit('2')) self.assertEquals("00 1 650 253 22", formatter.input_digit('2')) self.assertEquals("00 1 650 253 222", formatter.input_digit('2')) self.assertEquals("00 1 650 253 2222", formatter.input_digit('2'))
def testAYTFGBFixedLine(self): formatter = AsYouTypeFormatter("GB") self.assertEquals("0", formatter.input_digit('0')) self.assertEquals("02", formatter.input_digit('2')) self.assertEquals("020", formatter.input_digit('0')) self.assertEquals("020 7", formatter.input_digit('7', remember_position=True)) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("020 70", formatter.input_digit('0')) self.assertEquals("020 703", formatter.input_digit('3')) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("020 7031", formatter.input_digit('1')) self.assertEquals("020 7031 3", formatter.input_digit('3')) self.assertEquals("020 7031 30", formatter.input_digit('0')) self.assertEquals("020 7031 300", formatter.input_digit('0')) self.assertEquals("020 7031 3000", formatter.input_digit('0'))
def testAYTFUSFullWidthCharacters(self): formatter = AsYouTypeFormatter("US") self.assertEquals(u"\uFF16", formatter.input_digit(u"\uFF16")) self.assertEquals(u"\uFF16\uFF15", formatter.input_digit(u"\uFF15")) self.assertEquals("650", formatter.input_digit(u"\uFF10")) self.assertEquals("650 2", formatter.input_digit(u"\uFF12")) self.assertEquals("650 25", formatter.input_digit(u"\uFF15")) self.assertEquals("650 253", formatter.input_digit(u"\uFF13")) self.assertEquals("650 2532", formatter.input_digit(u"\uFF12")) self.assertEquals("650 253 22", formatter.input_digit(u"\uFF12")) self.assertEquals("650 253 222", formatter.input_digit(u"\uFF12")) self.assertEquals("650 253 2222", formatter.input_digit(u"\uFF12"))
def testAYTFUSVanityNumber(self): formatter = AsYouTypeFormatter("US") self.assertEquals("8", formatter.input_digit("8")) self.assertEquals("80", formatter.input_digit("0")) self.assertEquals("800", formatter.input_digit("0")) self.assertEquals("800 ", formatter.input_digit(" ")) self.assertEquals("800 M", formatter.input_digit("M")) self.assertEquals("800 MY", formatter.input_digit("Y")) self.assertEquals("800 MY ", formatter.input_digit(" ")) self.assertEquals("800 MY A", formatter.input_digit("A")) self.assertEquals("800 MY AP", formatter.input_digit("P")) self.assertEquals("800 MY APP", formatter.input_digit("P")) self.assertEquals("800 MY APPL", formatter.input_digit("L")) self.assertEquals("800 MY APPLE", formatter.input_digit("E"))
def testAYTFGBFixedLine(self): formatter = AsYouTypeFormatter("GB") self.assertEquals("0", formatter.input_digit("0")) self.assertEquals("02", formatter.input_digit("2")) self.assertEquals("020", formatter.input_digit("0")) self.assertEquals("020 7", formatter.input_digit("7", remember_position=True)) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("020 70", formatter.input_digit("0")) self.assertEquals("020 703", formatter.input_digit("3")) self.assertEquals(5, formatter.get_remembered_position()) self.assertEquals("020 7031", formatter.input_digit("1")) self.assertEquals("020 7031 3", formatter.input_digit("3")) self.assertEquals("020 7031 30", formatter.input_digit("0")) self.assertEquals("020 7031 300", formatter.input_digit("0")) self.assertEquals("020 7031 3000", formatter.input_digit("0"))
def testAYTFNZMobile(self): formatter = AsYouTypeFormatter("NZ") self.assertEquals("0", formatter.input_digit('0')) self.assertEquals("02", formatter.input_digit('2')) self.assertEquals("021", formatter.input_digit('1')) self.assertEquals("02-11", formatter.input_digit('1')) self.assertEquals("02-112", formatter.input_digit('2')) # Note the unittest is using fake metadata which might produce non-ideal results. self.assertEquals("02-112 3", formatter.input_digit('3')) self.assertEquals("02-112 34", formatter.input_digit('4')) self.assertEquals("02-112 345", formatter.input_digit('5')) self.assertEquals("02-112 3456", formatter.input_digit('6'))
def testAYTFGBPremiumRate(self): formatter = AsYouTypeFormatter("GB") self.assertEquals("0", formatter.input_digit("0")) self.assertEquals("09", formatter.input_digit("9")) self.assertEquals("090", formatter.input_digit("0")) self.assertEquals("090 7", formatter.input_digit("7")) self.assertEquals("090 70", formatter.input_digit("0")) self.assertEquals("090 703", formatter.input_digit("3")) self.assertEquals("090 7031", formatter.input_digit("1")) self.assertEquals("090 7031 3", formatter.input_digit("3")) self.assertEquals("090 7031 30", formatter.input_digit("0")) self.assertEquals("090 7031 300", formatter.input_digit("0")) self.assertEquals("090 7031 3000", formatter.input_digit("0"))
def testAYTFDE(self): formatter = AsYouTypeFormatter("DE") self.assertEquals("0", formatter.input_digit("0")) self.assertEquals("03", formatter.input_digit("3")) self.assertEquals("030", formatter.input_digit("0")) self.assertEquals("030/1", formatter.input_digit("1")) self.assertEquals("030/12", formatter.input_digit("2")) self.assertEquals("030/123", formatter.input_digit("3")) self.assertEquals("030/1234", formatter.input_digit("4")) # 04134 1234 formatter.clear() self.assertEquals("0", formatter.input_digit("0")) self.assertEquals("04", formatter.input_digit("4")) self.assertEquals("041", formatter.input_digit("1")) self.assertEquals("041 3", formatter.input_digit("3")) self.assertEquals("041 34", formatter.input_digit("4")) self.assertEquals("04134 1", formatter.input_digit("1")) self.assertEquals("04134 12", formatter.input_digit("2")) self.assertEquals("04134 123", formatter.input_digit("3")) self.assertEquals("04134 1234", formatter.input_digit("4")) # 08021 2345 formatter.clear() self.assertEquals("0", formatter.input_digit("0")) self.assertEquals("08", formatter.input_digit("8")) self.assertEquals("080", formatter.input_digit("0")) self.assertEquals("080 2", formatter.input_digit("2")) self.assertEquals("080 21", formatter.input_digit("1")) self.assertEquals("08021 2", formatter.input_digit("2")) self.assertEquals("08021 23", formatter.input_digit("3")) self.assertEquals("08021 234", formatter.input_digit("4")) self.assertEquals("08021 2345", formatter.input_digit("5")) # 00 1 650 253 2250 formatter.clear() self.assertEquals("0", formatter.input_digit("0")) self.assertEquals("00", formatter.input_digit("0")) self.assertEquals("00 1 ", formatter.input_digit("1")) self.assertEquals("00 1 6", formatter.input_digit("6")) self.assertEquals("00 1 65", formatter.input_digit("5")) self.assertEquals("00 1 650", formatter.input_digit("0")) self.assertEquals("00 1 650 2", formatter.input_digit("2")) self.assertEquals("00 1 650 25", formatter.input_digit("5")) self.assertEquals("00 1 650 253", formatter.input_digit("3")) self.assertEquals("00 1 650 253 2", formatter.input_digit("2")) self.assertEquals("00 1 650 253 22", formatter.input_digit("2")) self.assertEquals("00 1 650 253 222", formatter.input_digit("2")) self.assertEquals("00 1 650 253 2222", formatter.input_digit("2"))
def testAYTFAR(self): formatter = AsYouTypeFormatter("AR") self.assertEquals("0", formatter.input_digit("0")) self.assertEquals("01", formatter.input_digit("1")) self.assertEquals("011", formatter.input_digit("1")) self.assertEquals("011 7", formatter.input_digit("7")) self.assertEquals("011 70", formatter.input_digit("0")) self.assertEquals("011 703", formatter.input_digit("3")) self.assertEquals("011 7031", formatter.input_digit("1")) self.assertEquals("011 7031-3", formatter.input_digit("3")) self.assertEquals("011 7031-30", formatter.input_digit("0")) self.assertEquals("011 7031-300", formatter.input_digit("0")) self.assertEquals("011 7031-3000", formatter.input_digit("0"))
def testAYTFAR(self): formatter = AsYouTypeFormatter("AR") self.assertEquals("0", formatter.input_digit('0')) self.assertEquals("01", formatter.input_digit('1')) self.assertEquals("011", formatter.input_digit('1')) self.assertEquals("011 7", formatter.input_digit('7')) self.assertEquals("011 70", formatter.input_digit('0')) self.assertEquals("011 703", formatter.input_digit('3')) self.assertEquals("011 7031", formatter.input_digit('1')) self.assertEquals("011 7031-3", formatter.input_digit('3')) self.assertEquals("011 7031-30", formatter.input_digit('0')) self.assertEquals("011 7031-300", formatter.input_digit('0')) self.assertEquals("011 7031-3000", formatter.input_digit('0'))
def testAYTFKR(self): # +82 51 234 5678 formatter = AsYouTypeFormatter("KR") self.assertEquals("+", formatter.input_digit("+")) self.assertEquals("+8", formatter.input_digit("8")) self.assertEquals("+82 ", formatter.input_digit("2")) self.assertEquals("+82 5", formatter.input_digit("5")) self.assertEquals("+82 51", formatter.input_digit("1")) self.assertEquals("+82 51-2", formatter.input_digit("2")) self.assertEquals("+82 51-23", formatter.input_digit("3")) self.assertEquals("+82 51-234", formatter.input_digit("4")) self.assertEquals("+82 51-234-5", formatter.input_digit("5")) self.assertEquals("+82 51-234-56", formatter.input_digit("6")) self.assertEquals("+82 51-234-567", formatter.input_digit("7")) self.assertEquals("+82 51-234-5678", formatter.input_digit("8")) # +82 2 531 5678 formatter.clear() self.assertEquals("+", formatter.input_digit("+")) self.assertEquals("+8", formatter.input_digit("8")) self.assertEquals("+82 ", formatter.input_digit("2")) self.assertEquals("+82 2", formatter.input_digit("2")) self.assertEquals("+82 25", formatter.input_digit("5")) self.assertEquals("+82 2-53", formatter.input_digit("3")) self.assertEquals("+82 2-531", formatter.input_digit("1")) self.assertEquals("+82 2-531-5", formatter.input_digit("5")) self.assertEquals("+82 2-531-56", formatter.input_digit("6")) self.assertEquals("+82 2-531-567", formatter.input_digit("7")) self.assertEquals("+82 2-531-5678", formatter.input_digit("8")) # +82 2 3665 5678 formatter.clear() self.assertEquals("+", formatter.input_digit("+")) self.assertEquals("+8", formatter.input_digit("8")) self.assertEquals("+82 ", formatter.input_digit("2")) self.assertEquals("+82 2", formatter.input_digit("2")) self.assertEquals("+82 23", formatter.input_digit("3")) self.assertEquals("+82 2-36", formatter.input_digit("6")) self.assertEquals("+82 2-366", formatter.input_digit("6")) self.assertEquals("+82 2-3665", formatter.input_digit("5")) self.assertEquals("+82 2-3665-5", formatter.input_digit("5")) self.assertEquals("+82 2-3665-56", formatter.input_digit("6")) self.assertEquals("+82 2-3665-567", formatter.input_digit("7")) self.assertEquals("+82 2-3665-5678", formatter.input_digit("8")) # 02-114 formatter.clear() self.assertEquals("0", formatter.input_digit("0")) self.assertEquals("02", formatter.input_digit("2")) self.assertEquals("021", formatter.input_digit("1")) self.assertEquals("02-11", formatter.input_digit("1")) self.assertEquals("02-114", formatter.input_digit("4")) # 02-1300 formatter.clear() self.assertEquals("0", formatter.input_digit("0")) self.assertEquals("02", formatter.input_digit("2")) self.assertEquals("021", formatter.input_digit("1")) self.assertEquals("02-13", formatter.input_digit("3")) self.assertEquals("02-130", formatter.input_digit("0")) self.assertEquals("02-1300", formatter.input_digit("0")) # 011-456-7890 formatter.clear() self.assertEquals("0", formatter.input_digit("0")) self.assertEquals("01", formatter.input_digit("1")) self.assertEquals("011", formatter.input_digit("1")) self.assertEquals("011-4", formatter.input_digit("4")) self.assertEquals("011-45", formatter.input_digit("5")) self.assertEquals("011-456", formatter.input_digit("6")) self.assertEquals("011-456-7", formatter.input_digit("7")) self.assertEquals("011-456-78", formatter.input_digit("8")) self.assertEquals("011-456-789", formatter.input_digit("9")) self.assertEquals("011-456-7890", formatter.input_digit("0")) # 011-9876-7890 formatter.clear() self.assertEquals("0", formatter.input_digit("0")) self.assertEquals("01", formatter.input_digit("1")) self.assertEquals("011", formatter.input_digit("1")) self.assertEquals("011-9", formatter.input_digit("9")) self.assertEquals("011-98", formatter.input_digit("8")) self.assertEquals("011-987", formatter.input_digit("7")) self.assertEquals("011-9876", formatter.input_digit("6")) self.assertEquals("011-9876-7", formatter.input_digit("7")) self.assertEquals("011-9876-78", formatter.input_digit("8")) self.assertEquals("011-9876-789", formatter.input_digit("9")) self.assertEquals("011-9876-7890", formatter.input_digit("0"))
def testAYTFUS(self): formatter = AsYouTypeFormatter("US") self.assertEquals("6", formatter.input_digit("6")) self.assertEquals("65", formatter.input_digit("5")) self.assertEquals("650", formatter.input_digit("0")) self.assertEquals("650 2", formatter.input_digit("2")) self.assertEquals("650 25", formatter.input_digit("5")) self.assertEquals("650 253", formatter.input_digit("3")) # Note this is how a US local number (without area code) should be formatted. self.assertEquals("650 2532", formatter.input_digit("2")) self.assertEquals("650 253 22", formatter.input_digit("2")) self.assertEquals("650 253 222", formatter.input_digit("2")) self.assertEquals("650 253 2222", formatter.input_digit("2")) formatter.clear() self.assertEquals("1", formatter.input_digit("1")) self.assertEquals("16", formatter.input_digit("6")) self.assertEquals("1 65", formatter.input_digit("5")) self.assertEquals("1 650", formatter.input_digit("0")) self.assertEquals("1 650 2", formatter.input_digit("2")) self.assertEquals("1 650 25", formatter.input_digit("5")) self.assertEquals("1 650 253", formatter.input_digit("3")) self.assertEquals("1 650 253 2", formatter.input_digit("2")) self.assertEquals("1 650 253 22", formatter.input_digit("2")) self.assertEquals("1 650 253 222", formatter.input_digit("2")) self.assertEquals("1 650 253 2222", formatter.input_digit("2")) formatter.clear() self.assertEquals("0", formatter.input_digit("0")) self.assertEquals("01", formatter.input_digit("1")) self.assertEquals("011 ", formatter.input_digit("1")) self.assertEquals("011 4", formatter.input_digit("4")) self.assertEquals("011 44 ", formatter.input_digit("4")) self.assertEquals("011 44 6", formatter.input_digit("6")) self.assertEquals("011 44 61", formatter.input_digit("1")) self.assertEquals("011 44 6 12", formatter.input_digit("2")) self.assertEquals("011 44 6 123", formatter.input_digit("3")) self.assertEquals("011 44 6 123 1", formatter.input_digit("1")) self.assertEquals("011 44 6 123 12", formatter.input_digit("2")) self.assertEquals("011 44 6 123 123", formatter.input_digit("3")) self.assertEquals("011 44 6 123 123 1", formatter.input_digit("1")) self.assertEquals("011 44 6 123 123 12", formatter.input_digit("2")) self.assertEquals("011 44 6 123 123 123", formatter.input_digit("3")) formatter.clear() self.assertEquals("0", formatter.input_digit("0")) self.assertEquals("01", formatter.input_digit("1")) self.assertEquals("011 ", formatter.input_digit("1")) self.assertEquals("011 5", formatter.input_digit("5")) self.assertEquals("011 54 ", formatter.input_digit("4")) self.assertEquals("011 54 9", formatter.input_digit("9")) self.assertEquals("011 54 91", formatter.input_digit("1")) self.assertEquals("011 54 9 11", formatter.input_digit("1")) self.assertEquals("011 54 9 11 2", formatter.input_digit("2")) self.assertEquals("011 54 9 11 23", formatter.input_digit("3")) self.assertEquals("011 54 9 11 231", formatter.input_digit("1")) self.assertEquals("011 54 9 11 2312", formatter.input_digit("2")) self.assertEquals("011 54 9 11 2312 1", formatter.input_digit("1")) self.assertEquals("011 54 9 11 2312 12", formatter.input_digit("2")) self.assertEquals("011 54 9 11 2312 123", formatter.input_digit("3")) self.assertEquals("011 54 9 11 2312 1234", formatter.input_digit("4")) formatter.clear() self.assertEquals("0", formatter.input_digit("0")) self.assertEquals("01", formatter.input_digit("1")) self.assertEquals("011 ", formatter.input_digit("1")) self.assertEquals("011 2", formatter.input_digit("2")) self.assertEquals("011 24", formatter.input_digit("4")) self.assertEquals("011 244 ", formatter.input_digit("4")) self.assertEquals("011 244 2", formatter.input_digit("2")) self.assertEquals("011 244 28", formatter.input_digit("8")) self.assertEquals("011 244 280", formatter.input_digit("0")) self.assertEquals("011 244 280 0", formatter.input_digit("0")) self.assertEquals("011 244 280 00", formatter.input_digit("0")) self.assertEquals("011 244 280 000", formatter.input_digit("0")) self.assertEquals("011 244 280 000 0", formatter.input_digit("0")) self.assertEquals("011 244 280 000 00", formatter.input_digit("0")) self.assertEquals("011 244 280 000 000", formatter.input_digit("0")) formatter.clear() self.assertEquals("+", formatter.input_digit("+")) self.assertEquals("+4", formatter.input_digit("4")) self.assertEquals("+48 ", formatter.input_digit("8")) self.assertEquals("+48 8", formatter.input_digit("8")) self.assertEquals("+48 88", formatter.input_digit("8")) self.assertEquals("+48 88 1", formatter.input_digit("1")) self.assertEquals("+48 88 12", formatter.input_digit("2")) self.assertEquals("+48 88 123", formatter.input_digit("3")) self.assertEquals("+48 88 123 1", formatter.input_digit("1")) self.assertEquals("+48 88 123 12", formatter.input_digit("2")) self.assertEquals("+48 88 123 12 1", formatter.input_digit("1")) self.assertEquals("+48 88 123 12 12", formatter.input_digit("2"))