'Test the various sorting APIs'

def test_sorting(self):

    german = u'Sonntag    Montag    Dienstag    Januar    Februar    M\xe4rz    Fu\xdfe    Flu\xdfe    Flusse    flusse    flu\xdfe    fl\xfc\xdfe    fl\xfcsse'.split()
    german_good = u'Dienstag    Februar    flusse    Flusse    flu\xdfe    Flu\xdfe    fl\xfcsse    fl\xfc\xdfe    Fu\xdfe    Januar    M\xe4rz    Montag    Sonntag'.split()
    french = u'dimanche    lundi    mardi    janvier    f\xe9vrier    mars    d\xe9j\xe0    Meme    deja    m\xeame    dej\xe0    bpef    b\u0153g    Boef    M\xe9m\xe9    b\u0153f    boef    bnef    p\xeache    p\xe8ch\xe9    p\xeach\xe9    p\xeache    p\xeach\xe9'.split()
    french_good = u'bnef    boef    Boef    b\u0153f    b\u0153g    bpef    deja    dej\xe0    d\xe9j\xe0    dimanche    f\xe9vrier    janvier    lundi    mardi    mars    Meme    M\xe9m\xe9    m\xeame    p\xe8ch\xe9    p\xeache    p\xeache    p\xeach\xe9    p\xeach\xe9'.split()
    sort_key = icu.sort_key
    s = u'\U0001f431'
    self.ae(sort_key(s), sort_key(s.encode(sys.getdefaultencoding())), u'UTF-8    encoded    object    not    correctly    decoded    to    generate    sort    key')
    self.ae(s.encode(u'utf-16'), s.encode(u'utf-16'), u'Undecodable    bytestring    not    returned    as    itself')
    self.ae('', sort_key(None))
    self.ae(0, icu.strcmp(None, ''))
    self.ae(0, icu.strcmp(s, s.encode(sys.getdefaultencoding())))
    with make_collation_func(u'dsk', u'de', func=u'sort_key') as dsk:
        self.ae(german_good, sorted(german, key=dsk))
        with make_collation_func(u'dcmp', u'de', template=u'_strcmp_template') as dcmp:
            for x in german:
                for y in german:
                    self.ae(cmp(dsk(x), dsk(y)), dcmp(x, y))
    with make_collation_func(u'fsk', u'fr', func=u'sort_key') as fsk:
        self.ae(french_good, sorted(french, key=fsk))
        with make_collation_func(u'fcmp', u'fr', template=u'_strcmp_template') as fcmp:
            for x in french:
                for y in french:
                    self.ae(cmp(fsk(x), fsk(y)), fcmp(x, y))
    with make_collation_func(u'ssk', u'es', func=u'sort_key') as ssk:
        self.assertNotEqual(ssk(u'pe\xf1a'), ssk(u'pena'))
        with make_collation_func(u'scmp', u'es', template=u'_strcmp_template') as scmp:
            self.assertNotEqual(0, scmp(u'pena', u'pe\xf1a'))
    for (k, v) in {u'p\xe8ch\xe9': u'peche', u'fl\xfc\xdfe': u'Flusse', u'\u0160tep\xe1nek': u'\u0160tepaneK'}.iteritems():
        self.ae(0, icu.primary_strcmp(k, v))
    self.ae(icu.primary_sort_key(u'A\xe4'), icu.primary_sort_key(u'aa'))
    self.assertLess(icu.numeric_sort_key(u'something    2'), icu.numeric_sort_key(u'something    11'))
    self.assertLess(icu.case_sensitive_sort_key(u'A'), icu.case_sensitive_sort_key(u'a'))
    self.ae(0, icu.strcmp(u'a', u'A'))
    self.ae(cmp(u'a', u'A'), icu.case_sensitive_strcmp(u'a', u'A'))
    self.ae(0, icu.primary_strcmp(u'\xe4', u'A'))
