proxygen
UTF8StringTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2012-present Facebook, Inc.
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 <folly/UTF8String.h>
18 
19 #include <folly/Range.h>
21 #include <folly/test/TestUtils.h>
22 
23 using namespace folly;
24 using namespace std;
25 
26 const folly::StringPiece kTestUTF8 = u8"This is \U0001F602 stuff!";
27 
28 TEST(UTF8StringPiece, valid_utf8) {
30  UTF8StringPiece utf8 = sp;
31  // utf8.size() not available since it's not a random-access range
32  EXPECT_EQ(16, utf8.walk_size());
33 }
34 
35 TEST(UTF8StringPiece, valid_suffix) {
36  UTF8StringPiece utf8 = kTestUTF8.subpiece(8);
37  EXPECT_EQ(8, utf8.walk_size());
38 }
39 
40 TEST(UTF8StringPiece, empty_mid_codepoint) {
41  UTF8StringPiece utf8 = kTestUTF8.subpiece(9, 0); // okay since it's empty
42  EXPECT_EQ(0, utf8.walk_size());
43 }
44 
45 TEST(UTF8StringPiece, invalid_mid_codepoint) {
46  EXPECT_THROW(UTF8StringPiece(kTestUTF8.subpiece(9, 1)), std::out_of_range);
47 }
48 
49 TEST(UTF8StringPiece, valid_implicit_conversion) {
50  std::string input = u8"\U0001F602\U0001F602\U0001F602";
51  auto checkImplicitCtor = [](UTF8StringPiece implicitCtor) {
52  return implicitCtor.walk_size();
53  };
54  EXPECT_EQ(3, checkImplicitCtor(input));
55 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
UTF8Range< const char * > UTF8StringPiece
Definition: UTF8String.h:46
STL namespace.
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
const folly::StringPiece kTestUTF8
Range subpiece(size_type first, size_type length=npos) const
Definition: Range.h:686
const char * string
Definition: Conv.cpp:212
TEST(SequencedExecutor, CPUThreadPoolExecutor)