diff options
Diffstat (limited to 'utils/i18n/locale_test.cc')
-rw-r--r-- | utils/i18n/locale_test.cc | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/utils/i18n/locale_test.cc b/utils/i18n/locale_test.cc new file mode 100644 index 0000000..3722727 --- /dev/null +++ b/utils/i18n/locale_test.cc @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "utils/i18n/locale.h" + +#include "gtest/gtest.h" + +namespace libtextclassifier3 { +namespace { + +TEST(LocaleTest, ParseUnknown) { + Locale locale = Locale::Invalid(); + EXPECT_FALSE(locale.IsValid()); +} + +TEST(LocaleTest, ParseSwissEnglish) { + Locale locale = Locale::FromBCP47("en-CH"); + EXPECT_TRUE(locale.IsValid()); + EXPECT_EQ(locale.Language(), "en"); + EXPECT_EQ(locale.Script(), ""); + EXPECT_EQ(locale.Region(), "CH"); +} + +TEST(LocaleTest, ParseChineseChina) { + Locale locale = Locale::FromBCP47("zh-CN"); + EXPECT_TRUE(locale.IsValid()); + EXPECT_EQ(locale.Language(), "zh"); + EXPECT_EQ(locale.Script(), ""); + EXPECT_EQ(locale.Region(), "CN"); +} + +TEST(LocaleTest, ParseChineseTaiwan) { + Locale locale = Locale::FromBCP47("zh-Hant-TW"); + EXPECT_TRUE(locale.IsValid()); + EXPECT_EQ(locale.Language(), "zh"); + EXPECT_EQ(locale.Script(), "Hant"); + EXPECT_EQ(locale.Region(), "TW"); +} + +TEST(LocaleTest, ParseEnglish) { + Locale locale = Locale::FromBCP47("en"); + EXPECT_TRUE(locale.IsValid()); + EXPECT_EQ(locale.Language(), "en"); + EXPECT_EQ(locale.Script(), ""); + EXPECT_EQ(locale.Region(), ""); +} + +TEST(LocaleTest, ParseCineseTraditional) { + Locale locale = Locale::FromBCP47("zh-Hant"); + EXPECT_TRUE(locale.IsValid()); + EXPECT_EQ(locale.Language(), "zh"); + EXPECT_EQ(locale.Script(), "Hant"); + EXPECT_EQ(locale.Region(), ""); +} + +} // namespace +} // namespace libtextclassifier3 |