2017-11-17 12:10:16 +00:00
|
|
|
// Copyright (C) 2017 The Syncthing Authors.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
package fs
|
|
|
|
|
2020-09-11 07:16:10 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var caseCases = [][2]string{
|
|
|
|
{"", ""},
|
|
|
|
{"hej", "hej"},
|
|
|
|
{"HeJ!@#", "hej!@#"},
|
|
|
|
// Western Europe diacritical stuff is trivial.
|
|
|
|
{"ÜBERRÄKSMÖRGÅS", "überräksmörgås"},
|
|
|
|
// As are ligatures.
|
|
|
|
{"Æglefinus", "æglefinus"},
|
|
|
|
{"IJssel", "ijssel"},
|
|
|
|
// Cyrillic seems regular as well.
|
|
|
|
{"Привет", "привет"},
|
|
|
|
// Greek has multiple lower case characters for things depending on
|
|
|
|
// context; we should always choose the same one.
|
|
|
|
{"Ὀδυσσεύς", "ὀδυσσεύσ"},
|
|
|
|
{"ὈΔΥΣΣΕΎΣ", "ὀδυσσεύσ"},
|
|
|
|
// German ß doesn't really have an upper case variant, and we
|
|
|
|
// shouldn't mess things up when lower casing it either. We don't
|
|
|
|
// attempt to make ß equivalent to "ss".
|
|
|
|
{"Reichwaldstraße", "reichwaldstraße"},
|
|
|
|
// The Turks do their thing with the Is.... Like the Greek example
|
|
|
|
// we pick just the one canonicalized "i" although you can argue
|
|
|
|
// with this... From what I understand most operating systems don't
|
|
|
|
// get this right anyway.
|
|
|
|
{"İI", "ii"},
|
|
|
|
// Arabic doesn't do case folding.
|
|
|
|
{"العَرَبِيَّة", "العَرَبِيَّة"},
|
|
|
|
// Neither does Hebrew.
|
|
|
|
{"עברית", "עברית"},
|
|
|
|
// Nor Chinese, in any variant.
|
|
|
|
{"汉语/漢語 or 中文", "汉语/漢語 or 中文"},
|
|
|
|
// Nor katakana, as far as I can tell.
|
|
|
|
{"チャーハン", "チャーハン"},
|
|
|
|
// Some special Unicode characters, however, are folded by OSes.
|
|
|
|
{"\u212A", "k"},
|
2021-05-17 10:35:03 +00:00
|
|
|
// Folding renormalizes to NFC
|
|
|
|
{"A\xCC\x88", "\xC3\xA4"}, // ä
|
2021-05-17 18:43:07 +00:00
|
|
|
{"a\xCC\x88", "\xC3\xA4"}, // ä
|
2020-09-11 07:16:10 +00:00
|
|
|
}
|
2017-11-17 12:10:16 +00:00
|
|
|
|
2021-05-17 10:35:03 +00:00
|
|
|
func TestUnicodeLowercaseNormalized(t *testing.T) {
|
2020-09-11 07:16:10 +00:00
|
|
|
for _, tc := range caseCases {
|
2021-05-17 10:35:03 +00:00
|
|
|
res := UnicodeLowercaseNormalized(tc[0])
|
2017-11-17 12:10:16 +00:00
|
|
|
if res != tc[1] {
|
2021-05-17 10:35:03 +00:00
|
|
|
t.Errorf("UnicodeLowercaseNormalized(%q) => %q, expected %q", tc[0], res, tc[1])
|
2017-11-17 12:10:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-11 07:16:10 +00:00
|
|
|
|
|
|
|
func BenchmarkUnicodeLowercaseMaybeChange(b *testing.B) {
|
|
|
|
b.ReportAllocs()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
for _, s := range caseCases {
|
2021-05-17 10:35:03 +00:00
|
|
|
UnicodeLowercaseNormalized(s[0])
|
2020-09-11 07:16:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkUnicodeLowercaseNoChange(b *testing.B) {
|
|
|
|
b.ReportAllocs()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
for _, s := range caseCases {
|
2021-05-17 10:35:03 +00:00
|
|
|
UnicodeLowercaseNormalized(s[1])
|
2020-09-11 07:16:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|