Add ICU dorting test

This commit is contained in:
Kovid Goyal 2010-12-04 00:30:42 -07:00
parent 0b70f40709
commit fc9ac1d715

View File

@ -51,3 +51,110 @@ load_collator()
sort_key = py_sort_key if _icu is None or _collator is None else \
partial(icu_sort_key, _collator)
def test(): # {{{
# Data {{{
german = '''
Sonntag
Montag
Dienstag
Januar
Februar
März
Fuße
Fluße
Flusse
flusse
fluße
flüße
flüsse
'''
german_good = '''
Dienstag
Februar
flusse
Flusse
fluße
Fluße
flüsse
flüße
Fuße
Januar
März
Montag
Sonntag'''
french = '''
dimanche
lundi
mardi
janvier
février
mars
déjà
Meme
deja
même
dejà
bpef
bœg
Boef
Mémé
bœf
boef
bnef
pêche
pèché
pêché
pêche
pêché'''
french_good = '''
bnef
boef
Boef
bœf
bœg
bpef
deja
dejà
déjà
dimanche
février
janvier
lundi
mardi
mars
Meme
Mémé
même
pèché
pêche
pêche
pêché
pêché'''
# }}}
def create(l):
l = l.decode('utf-8').splitlines()
return [x.strip() for x in l if x.strip()]
german = create(german)
c = _icu.Collator('de')
print 'Sorted german:: (%s)'%c.actual_locale
gs = list(sorted(german, key=c.sort_key))
for x in gs:
print '\t', x.encode('utf-8')
if gs != create(german_good):
print 'German failed'
return
print
french = create(french)
c = _icu.Collator('fr')
print 'Sorted french:: (%s)'%c.actual_locale
fs = list(sorted(french, key=c.sort_key))
for x in fs:
print '\t', x.encode('utf-8')
if fs != create(french_good):
print 'French failed'
return
# }}}