def test_simple_casefold(self): """Test for simple casefolding.""" self.assertEqual(u"weiß", casefold(u"weiß", fullcasefold=False)) self.assertEqual(u"weiß", casefold(u"WEIẞ", fullcasefold=False)) # GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS self.assertEqual(u"\u0390", casefold(u"\u0390", fullcasefold=False)) # GREEK CAPITAL LETTER ALPHA WITH PSILI AND PROSGEGRAMMENI self.assertEqual(u"\u1f80", casefold(u"\u1f88", fullcasefold=False))
def test_full_casefold(self): """Test for full casefolding (explicitly specifying fullcasefold=True).""" self.assertEqual(u"weiss", casefold(u"weiß", fullcasefold=True)) self.assertEqual(u"weiss", casefold(u"WEIẞ", fullcasefold=True)) # GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS self.assertEqual(u"\u03b9\u0308\u0301", casefold(u"\u0390", fullcasefold=True)) # GREEK CAPITAL LETTER ALPHA WITH PSILI AND PROSGEGRAMMENI self.assertEqual(u"\u1f00\u03b9", casefold(u"\u1f88", fullcasefold=True))
def test_default_casefold(self): input_string = u"WEIẞ" resp = requests.post(base_url + "casefold", json={"input_string": input_string}) resp_str = self.leading_trailing_quotes.sub( '', resp.content.strip().decode('unicode-escape')) self.assertEqual(casefold(input_string), resp_str)
def test_turkic_casefold(self): input_string = u"DİYARBAKIR" resp = requests.post(base_url + "casefold", json={"input_string": input_string}) resp_str = self.leading_trailing_quotes.sub( '', resp.content.strip().decode('unicode-escape')) self.assertEqual(casefold(input_string), resp_str) resp = requests.post(base_url + "casefold", json={ "input_string": input_string, "useturkicmapping": True }) resp_str = self.leading_trailing_quotes.sub( '', resp.content.strip().decode('unicode-escape')) self.assertEqual(casefold(input_string, useturkicmapping=True), resp_str)
def test_turkic_casefold(self): """Test for casefolding with the useturkicmapping parameter.""" s1 = u"DİYARBAKIR" s2 = u"Diyarbakır" self.assertNotEqual(casefold(s1), casefold(s2)) self.assertEqual(casefold(s1, useturkicmapping=True), casefold(s2, useturkicmapping=True)) s1 = u"MISSISSIPPI" s2 = u"mississippi" self.assertEqual(casefold(s1), casefold(s2)) self.assertNotEqual(casefold(s1, useturkicmapping=True), casefold(s2, useturkicmapping=True))
def do_casefold(): fullcasefold = request.json[ 'fullcasefold'] if 'fullcasefold' in request.get_json() else True useturkicmapping = request.json[ 'useturkicmapping'] if 'useturkicmapping' in request.get_json( ) else False return jsonify( casefold(request.json['input_string'], fullcasefold=fullcasefold, useturkicmapping=useturkicmapping))
def test_default_casefold(self): """ This test is based on the str.casefold() tests for python 3. Source: https://github.com/python/cpython/blob/6f870935c2e024cbd1cc379f85e6a66d7711dcc7/Lib/test/test_unicode.py#L770 """ self.assertEqual(casefold(u"hello"), u"hello") self.assertEqual(casefold(u"hELlo"), u"hello") self.assertEqual(casefold(u"ß"), u"ss") self.assertEqual(casefold(u"fi"), u"fi") self.assertEqual(casefold(u"\u03a3"), u"\u03c3") # GREEK CAPITAL LETTER SIGMA self.assertEqual(casefold(u"A\u0345\u03a3"), u"a\u03b9\u03c3") # COMBINING GREEK YPOGEGRAMMENI self.assertEqual(casefold(u"\u00b5"), u"\u03bc") # MICRO SIGN
def test_full_casefold_surrogate_pair(self): """Test for full casefolding of a string with surrogate pairs.""" # A; B; OSAGE CAPITAL LETTER A; C; D; WARANG CITI CAPITAL LETTER NGAA; E; F self.assertEqual( u"ab\U000104D8cd\U000118C0ef", casefold(u"AB\U000104B0CD\U000118A0EF", fullcasefold=True))