• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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/char_utils.h"
18 
19 #include <gtest/gtest.h>
20 
21 #include "defines.h"
22 
23 namespace latinime {
24 namespace {
25 
TEST(CharUtilsTest,TestIsAsciiUpper)26 TEST(CharUtilsTest, TestIsAsciiUpper) {
27     EXPECT_TRUE(CharUtils::isAsciiUpper('A'));
28     EXPECT_TRUE(CharUtils::isAsciiUpper('Z'));
29     EXPECT_FALSE(CharUtils::isAsciiUpper('a'));
30     EXPECT_FALSE(CharUtils::isAsciiUpper('z'));
31     EXPECT_FALSE(CharUtils::isAsciiUpper('@'));
32     EXPECT_FALSE(CharUtils::isAsciiUpper(' '));
33     EXPECT_FALSE(CharUtils::isAsciiUpper(0x00C0 /* LATIN CAPITAL LETTER A WITH GRAVE */));
34     EXPECT_FALSE(CharUtils::isAsciiUpper(0x00E0 /* LATIN SMALL LETTER A WITH GRAVE */));
35     EXPECT_FALSE(CharUtils::isAsciiUpper(0x03C2 /* GREEK SMALL LETTER FINAL SIGMA */));
36     EXPECT_FALSE(CharUtils::isAsciiUpper(0x0410 /* CYRILLIC CAPITAL LETTER A */));
37     EXPECT_FALSE(CharUtils::isAsciiUpper(0x0430 /* CYRILLIC SMALL LETTER A */));
38     EXPECT_FALSE(CharUtils::isAsciiUpper(0x3042 /* HIRAGANA LETTER A */));
39     EXPECT_FALSE(CharUtils::isAsciiUpper(0x1F36A /* COOKIE */));
40 }
41 
TEST(CharUtilsTest,TestToLowerCase)42 TEST(CharUtilsTest, TestToLowerCase) {
43     EXPECT_EQ('a', CharUtils::toLowerCase('A'));
44     EXPECT_EQ('z', CharUtils::toLowerCase('Z'));
45     EXPECT_EQ('a', CharUtils::toLowerCase('a'));
46     EXPECT_EQ('z', CharUtils::toLowerCase('z'));
47     EXPECT_EQ('@', CharUtils::toLowerCase('@'));
48     EXPECT_EQ(' ', CharUtils::toLowerCase(' '));
49     EXPECT_EQ(0x00E0 /* LATIN SMALL LETTER A WITH GRAVE */,
50             CharUtils::toLowerCase(0x00C0 /* LATIN CAPITAL LETTER A WITH GRAVE */));
51     EXPECT_EQ(0x00E0 /* LATIN SMALL LETTER A WITH GRAVE */,
52             CharUtils::toLowerCase(0x00E0 /* LATIN SMALL LETTER A WITH GRAVE */));
53     EXPECT_EQ(0x03C2 /* GREEK SMALL LETTER FINAL SIGMA */,
54             CharUtils::toLowerCase(0x03C2 /* GREEK SMALL LETTER FINAL SIGMA */));
55     EXPECT_EQ(0x0430 /* CYRILLIC SMALL LETTER A */,
56             CharUtils::toLowerCase(0x0410 /* CYRILLIC CAPITAL LETTER A */));
57     EXPECT_EQ(0x0430 /* CYRILLIC SMALL LETTER A */,
58             CharUtils::toLowerCase(0x0430 /* CYRILLIC SMALL LETTER A */));
59     EXPECT_EQ(0x3042 /* HIRAGANA LETTER A */,
60             CharUtils::toLowerCase(0x3042 /* HIRAGANA LETTER A */));
61     EXPECT_EQ(0x1F36A /* COOKIE */, CharUtils::toLowerCase(0x1F36A /* COOKIE */));
62 }
63 
TEST(CharUtilsTest,TestToBaseLowerCase)64 TEST(CharUtilsTest, TestToBaseLowerCase) {
65     EXPECT_EQ('a', CharUtils::toBaseLowerCase('A'));
66     EXPECT_EQ('z', CharUtils::toBaseLowerCase('Z'));
67     EXPECT_EQ('a', CharUtils::toBaseLowerCase('a'));
68     EXPECT_EQ('z', CharUtils::toBaseLowerCase('z'));
69     EXPECT_EQ('@', CharUtils::toBaseLowerCase('@'));
70     EXPECT_EQ(' ', CharUtils::toBaseLowerCase(' '));
71     EXPECT_EQ('a', CharUtils::toBaseLowerCase(0x00C0 /* LATIN CAPITAL LETTER A WITH GRAVE */));
72     EXPECT_EQ('a', CharUtils::toBaseLowerCase(0x00E0 /* LATIN SMALL LETTER A WITH GRAVE */));
73     EXPECT_EQ(0x03C2 /* GREEK SMALL LETTER FINAL SIGMA */,
74             CharUtils::toBaseLowerCase(0x03C2 /* GREEK SMALL LETTER FINAL SIGMA */));
75     EXPECT_EQ(0x0430 /* CYRILLIC SMALL LETTER A */,
76             CharUtils::toBaseLowerCase(0x0410 /* CYRILLIC CAPITAL LETTER A */));
77     EXPECT_EQ(0x0430 /* CYRILLIC SMALL LETTER A */,
78             CharUtils::toBaseLowerCase(0x0430 /* CYRILLIC SMALL LETTER A */));
79     EXPECT_EQ(0x3042 /* HIRAGANA LETTER A */,
80             CharUtils::toBaseLowerCase(0x3042 /* HIRAGANA LETTER A */));
81     EXPECT_EQ(0x1F36A /* COOKIE */, CharUtils::toBaseLowerCase(0x1F36A /* COOKIE */));
82 }
83 
TEST(CharUtilsTest,TestToBaseCodePoint)84 TEST(CharUtilsTest, TestToBaseCodePoint) {
85     EXPECT_EQ('A', CharUtils::toBaseCodePoint('A'));
86     EXPECT_EQ('Z', CharUtils::toBaseCodePoint('Z'));
87     EXPECT_EQ('a', CharUtils::toBaseCodePoint('a'));
88     EXPECT_EQ('z', CharUtils::toBaseCodePoint('z'));
89     EXPECT_EQ('@', CharUtils::toBaseCodePoint('@'));
90     EXPECT_EQ(' ', CharUtils::toBaseCodePoint(' '));
91     EXPECT_EQ('A', CharUtils::toBaseCodePoint(0x00C0 /* LATIN CAPITAL LETTER A WITH GRAVE */));
92     EXPECT_EQ('a', CharUtils::toBaseCodePoint(0x00E0 /* LATIN SMALL LETTER A WITH GRAVE */));
93     EXPECT_EQ(0x03C2 /* GREEK SMALL LETTER FINAL SIGMA */,
94             CharUtils::toBaseLowerCase(0x03C2 /* GREEK SMALL LETTER FINAL SIGMA */));
95     EXPECT_EQ(0x0410 /* CYRILLIC CAPITAL LETTER A */,
96             CharUtils::toBaseCodePoint(0x0410 /* CYRILLIC CAPITAL LETTER A */));
97     EXPECT_EQ(0x0430 /* CYRILLIC SMALL LETTER A */,
98             CharUtils::toBaseCodePoint(0x0430 /* CYRILLIC SMALL LETTER A */));
99     EXPECT_EQ(0x3042 /* HIRAGANA LETTER A */,
100             CharUtils::toBaseCodePoint(0x3042 /* HIRAGANA LETTER A */));
101     EXPECT_EQ(0x1F36A /* COOKIE */, CharUtils::toBaseCodePoint(0x1F36A /* COOKIE */));
102 }
103 
TEST(CharUtilsTest,TestIsIntentionalOmissionCodePoint)104 TEST(CharUtilsTest, TestIsIntentionalOmissionCodePoint) {
105     EXPECT_TRUE(CharUtils::isIntentionalOmissionCodePoint('\''));
106     EXPECT_TRUE(CharUtils::isIntentionalOmissionCodePoint('-'));
107     EXPECT_FALSE(CharUtils::isIntentionalOmissionCodePoint('a'));
108     EXPECT_FALSE(CharUtils::isIntentionalOmissionCodePoint('?'));
109     EXPECT_FALSE(CharUtils::isIntentionalOmissionCodePoint('/'));
110 }
111 
TEST(CharUtilsTest,TestIsInUnicodeSpace)112 TEST(CharUtilsTest, TestIsInUnicodeSpace) {
113     EXPECT_FALSE(CharUtils::isInUnicodeSpace(NOT_A_CODE_POINT));
114     EXPECT_FALSE(CharUtils::isInUnicodeSpace(CODE_POINT_BEGINNING_OF_SENTENCE));
115     EXPECT_TRUE(CharUtils::isInUnicodeSpace('a'));
116     EXPECT_TRUE(CharUtils::isInUnicodeSpace(0x0410 /* CYRILLIC CAPITAL LETTER A */));
117     EXPECT_TRUE(CharUtils::isInUnicodeSpace(0x3042 /* HIRAGANA LETTER A */));
118     EXPECT_TRUE(CharUtils::isInUnicodeSpace(0x1F36A /* COOKIE */));
119 }
120 
121 }  // namespace
122 }  // namespace latinime
123