Exemple #1
0
 def test_find(self):
     ' Test searching for substrings '
     self.ae((1, 1), icu.find(b'a', b'1ab'))
     self.ae((1, 1 if sys.maxunicode >= 0x10ffff else 2),
             icu.find('\U0001f431', 'x\U0001f431x'))
     self.ae((1 if sys.maxunicode >= 0x10ffff else 2, 1),
             icu.find('y', '\U0001f431y'))
     self.ae((0, 4), icu.primary_find('pena', 'peña'))
     for k, v in {
             u'pèché': u'peche',
             u'flüße': u'Flusse',
             u'Štepánek': u'ŠtepaneK'
     }.iteritems():
         self.ae((1, len(k)), icu.primary_find(v, ' ' + k),
                 'Failed to find %s in %s' % (v, k))
     self.assertTrue(icu.startswith(b'abc', b'ab'))
     self.assertTrue(icu.startswith('abc', 'abc'))
     self.assertFalse(icu.startswith('xyz', 'a'))
     self.assertTrue(icu.startswith('xxx', ''))
     self.assertTrue(icu.primary_startswith('pena', 'peña'))
     self.assertTrue(icu.contains('\U0001f431', '\U0001f431'))
     self.assertTrue(icu.contains('something', 'some other something else'))
     self.assertTrue(icu.contains('', 'a'))
     self.assertTrue(icu.contains('', ''))
     self.assertFalse(icu.contains('xxx', 'xx'))
     self.assertTrue(icu.primary_contains('pena', 'peña'))
Exemple #2
0
 def test_find(self):
     ' Test searching for substrings '
     self.ae((1, 1), icu.find(b'a', b'1ab'))
     self.ae((1, 1), icu.find('\U0001f431', 'x\U0001f431x'))
     self.ae((1, 1), icu.find('y', '\U0001f431y'))
     self.ae((0, 4), icu.primary_find('pena', 'peña'))
     for k, v in iteritems({'pèché': 'peche', 'flüße':'Flusse', 'Štepánek':'ŠtepaneK'}):
         self.ae((1, len(k)), icu.primary_find(v, ' ' + k), f'Failed to find {v} in {k}')
     self.assertTrue(icu.startswith(b'abc', b'ab'))
     self.assertTrue(icu.startswith('abc', 'abc'))
     self.assertFalse(icu.startswith('xyz', 'a'))
     self.assertTrue(icu.startswith('xxx', ''))
     self.assertTrue(icu.primary_startswith('pena', 'peña'))
     self.assertTrue(icu.contains('\U0001f431', '\U0001f431'))
     self.assertTrue(icu.contains('something', 'some other something else'))
     self.assertTrue(icu.contains('', 'a'))
     self.assertTrue(icu.contains('', ''))
     self.assertFalse(icu.contains('xxx', 'xx'))
     self.assertTrue(icu.primary_contains('pena', 'peña'))
     x = icu.primary_collator()
     self.ae(x.get_attribute(icu._icu.UCOL_STRENGTH), icu._icu.UCOL_PRIMARY),
     self.ae((0, 4), icu.primary_no_punc_find('pena"', 'peña'))
     self.ae((0, 13), icu.primary_no_punc_find("typographers", 'typographer’s'))
     self.ae((0, 7), icu.primary_no_punc_find('abcd', 'a\u00adb\u200cc\u200dd'))
     self.ae((0, 5), icu.primary_no_punc_find('abcd', 'ab cd'))
     # test find all
     m = []
     a = lambda p,l : m.append((p, l))
     icu.primary_collator_without_punctuation().find_all('a', 'a a🐱a', a)
     self.ae(m, [(0, 1), (2, 1), (5, 1)])
     # test find whole words
     c = icu.primary_collator_without_punctuation()
     self.ae(c.find('a', 'abc a bc'), (0, 1))
     self.ae(c.find('a', 'abc a bc', True), (4, 1))
     self.ae(c.find('pena', 'a peñaabc peña', True), (10, 4))
Exemple #3
0
 def test_find(self):
     ' Test searching for substrings '
     self.ae((1, 1), icu.find(b'a', b'1ab'))
     self.ae((1, 1 if sys.maxunicode >= 0x10ffff else 2), icu.find('\U0001f431', 'x\U0001f431x'))
     self.ae((1 if sys.maxunicode >= 0x10ffff else 2, 1), icu.find('y', '\U0001f431y'))
     self.ae((0, 4), icu.primary_find('pena', 'peña'))
     for k, v in {u'pèché': u'peche', u'flüße':u'Flusse', u'Štepánek':u'ŠtepaneK'}.iteritems():
         self.ae((1, len(k)), icu.primary_find(v, ' ' + k), 'Failed to find %s in %s' % (v, k))
     self.assertTrue(icu.startswith(b'abc', b'ab'))
     self.assertTrue(icu.startswith('abc', 'abc'))
     self.assertFalse(icu.startswith('xyz', 'a'))
     self.assertTrue(icu.startswith('xxx', ''))
     self.assertTrue(icu.primary_startswith('pena', 'peña'))
     self.assertTrue(icu.contains('\U0001f431', '\U0001f431'))
     self.assertTrue(icu.contains('something', 'some other something else'))
     self.assertTrue(icu.contains('', 'a'))
     self.assertTrue(icu.contains('', ''))
     self.assertFalse(icu.contains('xxx', 'xx'))
     self.assertTrue(icu.primary_contains('pena', 'peña'))
Exemple #4
0
 def test_find(self):
     " Test searching for substrings "
     self.ae((1, 1), icu.find(b"a", b"1ab"))
     self.ae((1, 1 if sys.maxunicode >= 0x10FFFF else 2), icu.find("\U0001f431", "x\U0001f431x"))
     self.ae((1 if sys.maxunicode >= 0x10FFFF else 2, 1), icu.find("y", "\U0001f431y"))
     self.ae((0, 4), icu.primary_find("pena", "peña"))
     for k, v in {"pèché": "peche", "flüße": "Flusse", "Štepánek": "ŠtepaneK"}.iteritems():
         self.ae((1, len(k)), icu.primary_find(v, " " + k), "Failed to find %s in %s" % (v, k))
     self.assertTrue(icu.startswith(b"abc", b"ab"))
     self.assertTrue(icu.startswith("abc", "abc"))
     self.assertFalse(icu.startswith("xyz", "a"))
     self.assertTrue(icu.startswith("xxx", ""))
     self.assertTrue(icu.primary_startswith("pena", "peña"))
     self.assertTrue(icu.contains("\U0001f431", "\U0001f431"))
     self.assertTrue(icu.contains("something", "some other something else"))
     self.assertTrue(icu.contains("", "a"))
     self.assertTrue(icu.contains("", ""))
     self.assertFalse(icu.contains("xxx", "xx"))
     self.assertTrue(icu.primary_contains("pena", "peña"))
Exemple #5
0
 def test_find(self):
     ' Test searching for substrings '
     self.ae((1, 1), icu.find(b'a', b'1ab'))
     self.ae((1, 1), icu.find('\U0001f431', 'x\U0001f431x'))
     self.ae((1, 1), icu.find('y', '\U0001f431y'))
     self.ae((0, 4), icu.primary_find('pena', 'peña'))
     for k, v in iteritems({
             'pèché': 'peche',
             'flüße': 'Flusse',
             'Štepánek': 'ŠtepaneK'
     }):
         self.ae((1, len(k)), icu.primary_find(v, ' ' + k),
                 f'Failed to find {v} in {k}')
     self.assertTrue(icu.startswith(b'abc', b'ab'))
     self.assertTrue(icu.startswith('abc', 'abc'))
     self.assertFalse(icu.startswith('xyz', 'a'))
     self.assertTrue(icu.startswith('xxx', ''))
     self.assertTrue(icu.primary_startswith('pena', 'peña'))
     self.assertTrue(icu.contains('\U0001f431', '\U0001f431'))
     self.assertTrue(icu.contains('something', 'some other something else'))
     self.assertTrue(icu.contains('', 'a'))
     self.assertTrue(icu.contains('', ''))
     self.assertFalse(icu.contains('xxx', 'xx'))
     self.assertTrue(icu.primary_contains('pena', 'peña'))