1 // Copyright (C) 2011 The Libphonenumber Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may
4 // not use this file except in compliance with the License. You may obtain
5 // a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations
13 // under the License.
14 //
15 // Author: Ben Gertzfield
16
17 #include <gtest/gtest.h>
18
19 #include "phonenumbers/utf/unicodetext.h"
20
21 namespace i18n {
22 namespace phonenumbers {
23
TEST(UnicodeTextTest,Iterator)24 TEST(UnicodeTextTest, Iterator) {
25 struct value {
26 const char* utf8;
27 char32 code_point;
28 } values[] = {
29 { "\x31", 0x31 }, // U+0031 DIGIT ONE
30 { "\xC2\xBD", 0x00BD }, // U+00BD VULGAR FRACTION ONE HALF
31 { "\xEF\xBC\x91", 0xFF11 }, // U+FF11 FULLWIDTH DIGIT ONE
32 { "\xF0\x9F\x80\x80", 0x1F000 }, // U+1F000 MAHJONG TILE EAST WIND
33 };
34
35 for (size_t i = 0; i < sizeof values / sizeof values[0]; i++) {
36 string number(values[i].utf8);
37 UnicodeText number_as_unicode;
38 number_as_unicode.PointToUTF8(number.data(), number.size());
39 EXPECT_TRUE(number_as_unicode.UTF8WasValid());
40 UnicodeText::const_iterator it = number_as_unicode.begin();
41 EXPECT_EQ(values[i].code_point, *it);
42 }
43 }
44
45 } // namespace phonenumbers
46 } // namespace i18n
47