Ninja
string_piece_util_test.cc
Go to the documentation of this file.
1 // Copyright 2017 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain 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,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "string_piece_util.h"
16 
17 #include "test.h"
18 
19 TEST(StringPieceUtilTest, SplitStringPiece) {
20  {
21  string input("a:b:c");
22  vector<StringPiece> list = SplitStringPiece(input, ':');
23 
24  EXPECT_EQ(list.size(), 3);
25 
26  EXPECT_EQ(list[0], "a");
27  EXPECT_EQ(list[1], "b");
28  EXPECT_EQ(list[2], "c");
29  }
30 
31  {
32  string empty("");
33  vector<StringPiece> list = SplitStringPiece(empty, ':');
34 
35  EXPECT_EQ(list.size(), 1);
36 
37  EXPECT_EQ(list[0], "");
38  }
39 
40  {
41  string one("a");
42  vector<StringPiece> list = SplitStringPiece(one, ':');
43 
44  EXPECT_EQ(list.size(), 1);
45 
46  EXPECT_EQ(list[0], "a");
47  }
48 
49  {
50  string sep_only(":");
51  vector<StringPiece> list = SplitStringPiece(sep_only, ':');
52 
53  EXPECT_EQ(list.size(), 2);
54 
55  EXPECT_EQ(list[0], "");
56  EXPECT_EQ(list[1], "");
57  }
58 
59  {
60  string sep(":a:b:c:");
61  vector<StringPiece> list = SplitStringPiece(sep, ':');
62 
63  EXPECT_EQ(list.size(), 5);
64 
65  EXPECT_EQ(list[0], "");
66  EXPECT_EQ(list[1], "a");
67  EXPECT_EQ(list[2], "b");
68  EXPECT_EQ(list[3], "c");
69  EXPECT_EQ(list[4], "");
70  }
71 }
72 
73 TEST(StringPieceUtilTest, JoinStringPiece) {
74  {
75  string input("a:b:c");
76  vector<StringPiece> list = SplitStringPiece(input, ':');
77 
78  EXPECT_EQ("a:b:c", JoinStringPiece(list, ':'));
79  EXPECT_EQ("a/b/c", JoinStringPiece(list, '/'));
80  }
81 
82  {
83  string empty("");
84  vector<StringPiece> list = SplitStringPiece(empty, ':');
85 
86  EXPECT_EQ("", JoinStringPiece(list, ':'));
87  }
88 
89  {
90  vector<StringPiece> empty_list;
91 
92  EXPECT_EQ("", JoinStringPiece(empty_list, ':'));
93  }
94 
95  {
96  string one("a");
97  vector<StringPiece> single_list = SplitStringPiece(one, ':');
98 
99  EXPECT_EQ("a", JoinStringPiece(single_list, ':'));
100  }
101 
102  {
103  string sep(":a:b:c:");
104  vector<StringPiece> list = SplitStringPiece(sep, ':');
105 
106  EXPECT_EQ(":a:b:c:", JoinStringPiece(list, ':'));
107  }
108 }
109 
110 TEST(StringPieceUtilTest, ToLowerASCII) {
111  EXPECT_EQ('a', ToLowerASCII('A'));
112  EXPECT_EQ('z', ToLowerASCII('Z'));
113  EXPECT_EQ('a', ToLowerASCII('a'));
114  EXPECT_EQ('z', ToLowerASCII('z'));
115  EXPECT_EQ('/', ToLowerASCII('/'));
116  EXPECT_EQ('1', ToLowerASCII('1'));
117 }
118 
119 TEST(StringPieceUtilTest, EqualsCaseInsensitiveASCII) {
125 
129 }
vector< StringPiece > SplitStringPiece(StringPiece input, char sep)
TEST(StringPieceUtilTest, SplitStringPiece)
#define EXPECT_TRUE(a)
Definition: test.h:76
#define EXPECT_FALSE(a)
Definition: test.h:78
#define EXPECT_EQ(a, b)
Definition: test.h:64
string JoinStringPiece(const vector< StringPiece > &list, char sep)
char ToLowerASCII(char c)
bool EqualsCaseInsensitiveASCII(StringPiece a, StringPiece b)