1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "utils/i18n/locale-list.h"
18
19 #include "gmock/gmock.h"
20 #include "gtest/gtest.h"
21
22 using ::testing::SizeIs;
23
24 namespace libtextclassifier3 {
25 namespace {
26
TEST(LocaleTest,ParsedLocalesSanityCheck)27 TEST(LocaleTest, ParsedLocalesSanityCheck) {
28 LocaleList locale_list = LocaleList::ParseFrom("en-US,zh-CN,ar,en");
29 EXPECT_THAT(locale_list.GetLocales(), SizeIs(4));
30 EXPECT_THAT(locale_list.GetLocaleTags(), SizeIs(4));
31 EXPECT_EQ(locale_list.GetReferenceLocale(), "en-US");
32 }
33
TEST(LocaleTest,ParsedLocalesEmpty)34 TEST(LocaleTest, ParsedLocalesEmpty) {
35 LocaleList locale_list = LocaleList::ParseFrom("");
36 EXPECT_THAT(locale_list.GetLocales(), SizeIs(0));
37 EXPECT_THAT(locale_list.GetLocaleTags(), SizeIs(0));
38 EXPECT_EQ(locale_list.GetReferenceLocale(), "");
39 }
40
TEST(LocaleTest,ParsedLocalesIvalid)41 TEST(LocaleTest, ParsedLocalesIvalid) {
42 LocaleList locale_list = LocaleList::ParseFrom("en,invalid");
43 EXPECT_THAT(locale_list.GetLocales(), SizeIs(2));
44 EXPECT_THAT(locale_list.GetLocaleTags(), SizeIs(2));
45 EXPECT_EQ(locale_list.GetReferenceLocale(), "en");
46 EXPECT_TRUE(locale_list.GetLocales()[0].IsValid());
47 EXPECT_FALSE(locale_list.GetLocales()[1].IsValid());
48 }
49
50 } // namespace
51 } // namespace libtextclassifier3
52