1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51

base / i18n / transliterator_unittest.cc [blame]

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "build/build_config.h"
#include "base/i18n/unicodestring.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/icu/source/common/unicode/ustring.h"
#include "third_party/icu/source/i18n/unicode/translit.h"

namespace base {
namespace i18n {

TEST(TransliteratorTest, LowerCorrect) {
  UParseError parseErr;
  UErrorCode err = U_ZERO_ERROR;
  std::unique_ptr<icu::Transliterator> transliterator(
      icu::Transliterator::createInstance("Lower", UTRANS_FORWARD,
                                          parseErr, err));
  ASSERT_TRUE(U_SUCCESS(err));
  icu::UnicodeString text(u"ÎÑŢÉRÑÅŢÎÖÑÅĻÎŽÅŢÎÖÑ");
  transliterator->transliterate(text);
  EXPECT_EQ(base::i18n::UnicodeStringToString16(text), u"îñţérñåţîöñåļîžåţîöñ");
}

TEST(TransliteratorTest, LatinASCIICorrect) {
  UParseError parseErr;
  UErrorCode err = U_ZERO_ERROR;
  std::unique_ptr<icu::Transliterator> transliterator(
      icu::Transliterator::createInstance("Latin-ASCII", UTRANS_FORWARD,
                                          parseErr, err));
  ASSERT_TRUE(U_SUCCESS(err));
  icu::UnicodeString text(u"ÎÑŢÉRÑÅŢÎÖÑÅĻÎŽÅŢÎÖÑ");
  transliterator->transliterate(text);
  EXPECT_EQ(base::i18n::UnicodeStringToString16(text), u"INTERNATIONALIZATION");
}

TEST(TransliteratorTest, LowerLatinASCIICorrect) {
  UParseError parseErr;
  UErrorCode err = U_ZERO_ERROR;
  std::unique_ptr<icu::Transliterator> transliterator(
      icu::Transliterator::createInstance("Lower;Latin-ASCII", UTRANS_FORWARD,
                                          parseErr, err));
  ASSERT_TRUE(U_SUCCESS(err));
  icu::UnicodeString text(u"ÎÑŢÉRÑÅŢÎÖÑÅĻÎŽÅŢÎÖÑ");
  transliterator->transliterate(text);
  EXPECT_EQ(base::i18n::UnicodeStringToString16(text), u"internationalization");
}

}  // namespace i18n
}  // namespace base