22 #include "gtest/gtest.h" 28 TEST(AsciiIsFoo, All) {
29 for (
int i = 0;
i < 256;
i++) {
30 if ((
i >=
'a' &&
i <=
'z') || (
i >=
'A' &&
i <=
'Z'))
35 for (
int i = 0;
i < 256;
i++) {
36 if ((
i >=
'0' &&
i <=
'9'))
41 for (
int i = 0;
i < 256;
i++) {
47 for (
int i = 0;
i < 256;
i++) {
48 if (
i !=
'\0' && strchr(
" \r\n\t\v\f",
i))
53 for (
int i = 0;
i < 256;
i++) {
54 if (
i >= 32 &&
i < 127)
59 for (
int i = 0;
i < 256;
i++) {
66 for (
int i = 0;
i < 256;
i++) {
67 if (
i ==
' ' ||
i ==
'\t')
72 for (
int i = 0;
i < 256;
i++) {
73 if (
i < 32 ||
i == 127)
78 for (
int i = 0;
i < 256;
i++) {
80 (
i >=
'a' &&
i <=
'f'))
85 for (
int i = 0;
i < 256;
i++) {
86 if (
i > 32 &&
i < 127)
91 for (
int i = 0;
i < 256;
i++) {
92 if (
i >=
'A' &&
i <=
'Z')
97 for (
int i = 0;
i < 256;
i++) {
98 if (
i >=
'a' &&
i <=
'z')
103 for (
int i = 0;
i < 128;
i++) {
106 for (
int i = 128;
i < 256;
i++) {
112 for (
int i = 0;
i < 256;
i++) {
113 signed char sc =
static_cast<signed char>(
static_cast<unsigned char>(
i));
132 TEST(AsciiIsFoo, SameAsIsFoo) {
135 const char* old_locale = setlocale(LC_CTYPE,
"C");
136 ASSERT_TRUE(old_locale !=
nullptr);
139 for (
int i = 0;
i < 256;
i++) {
157 ASSERT_TRUE(setlocale(LC_CTYPE, old_locale));
161 TEST(AsciiToFoo, All) {
164 const char* old_locale = setlocale(LC_CTYPE,
"C");
165 ASSERT_TRUE(old_locale !=
nullptr);
168 for (
int i = 0;
i < 256;
i++) {
185 signed char sc =
static_cast<signed char>(
static_cast<unsigned char>(
i));
191 ASSERT_TRUE(setlocale(LC_CTYPE, old_locale));
195 TEST(AsciiStrTo, Lower) {
196 const char buf[] =
"ABCDEF";
197 const std::string str(
"GHIJKL");
198 const std::string str2(
"MNOPQR");
205 char mutable_buf[] =
"Mutable";
206 std::transform(mutable_buf, mutable_buf + strlen(mutable_buf),
208 EXPECT_STREQ(
"mutable", mutable_buf);
211 TEST(AsciiStrTo, Upper) {
212 const char buf[] =
"abcdef";
213 const std::string str(
"ghijkl");
214 const std::string str2(
"mnopqr");
221 char mutable_buf[] =
"Mutable";
222 std::transform(mutable_buf, mutable_buf + strlen(mutable_buf),
224 EXPECT_STREQ(
"MUTABLE", mutable_buf);
232 EXPECT_EQ(
"foo foo\n ",
235 {
"\t \n\f\r\v\n\t \n\f\r\v\n"}));
246 EXPECT_EQ(
"foo", str);
248 str =
"\t \n\f\r\n\vfoo";
250 EXPECT_EQ(
"foo", str);
252 str =
"\t \n\f\r\n\vfoo foo\n ";
254 EXPECT_EQ(
"foo foo\n ", str);
256 str =
"\t \n\f\r\v\n\t \n\f\r\v\n";
266 EXPECT_EQ(
" \nfoo foo",
269 {
"\t \n\f\r\v\n\t \n\f\r\v\n"}));
280 EXPECT_EQ(
"foo", str);
282 str =
"foo\t \n\f\r\n\v";
284 EXPECT_EQ(
"foo", str);
286 str =
" \nfoo foo\t \n\f\r\n\v";
288 EXPECT_EQ(
" \nfoo foo", str);
290 str =
"\t \n\f\r\v\n\t \n\f\r\v\n";
302 {
"\t \n\f\r\n\vfoo foo\t \n\f\r\n\v"}));
315 EXPECT_EQ(
"foo", str);
317 str =
"\t \n\f\r\n\vfoo\t \n\f\r\n\v";
319 EXPECT_EQ(
"foo", str);
321 str =
"\t \n\f\r\n\vfoo foo\t \n\f\r\n\v";
323 EXPECT_EQ(
"foo foo", str);
325 str =
"\t \n\f\r\v\n\t \n\f\r\v\n";
331 const char* inputs[] = {
"No extra space",
332 " Leading whitespace",
333 "Trailing whitespace ",
334 " Leading and trailing ",
335 " Whitespace \t in\v middle ",
336 "'Eeeeep! \n Newlines!\n",
339 "\n\t a\t\n\nb \t\n"};
341 const char* outputs[] = {
343 "Leading whitespace",
344 "Trailing whitespace",
345 "Leading and trailing",
346 "Whitespace in middle",
347 "'Eeeeep! Newlines!",
354 for (
int i = 0;
i < NUM_TESTS;
i++) {
355 std::string s(inputs[
i]);
357 EXPECT_EQ(outputs[
i], s);
bool ascii_isalnum(unsigned char c)
void AsciiStrToLower(std::string *s)
bool ascii_isblank(unsigned char c)
bool ascii_isgraph(unsigned char c)
bool ascii_isprint(unsigned char c)
bool ascii_isspace(unsigned char c)
bool ascii_isalpha(unsigned char c)
void AsciiStrToUpper(std::string *s)
void RemoveExtraAsciiWhitespace(std::string *str)
char ascii_toupper(unsigned char c)
bool ascii_isupper(unsigned char c)
ABSL_MUST_USE_RESULT absl::string_view StripAsciiWhitespace(absl::string_view str)
ABSL_MUST_USE_RESULT absl::string_view StripLeadingAsciiWhitespace(absl::string_view str)
bool ascii_islower(unsigned char c)
bool ascii_ispunct(unsigned char c)
bool ascii_isascii(unsigned char c)
bool ascii_isxdigit(unsigned char c)
#define ABSL_ARRAYSIZE(array)
bool ascii_isdigit(unsigned char c)
TEST(Symbolize, Unimplemented)
char ascii_tolower(unsigned char c)
bool ascii_iscntrl(unsigned char c)
ABSL_MUST_USE_RESULT absl::string_view StripTrailingAsciiWhitespace(absl::string_view str)