21 #include "gmock/gmock.h" 22 #include "gtest/gtest.h" 27 ~
absl::strings_internal::Charmap();
30 TEST(Charmap, AllTests) {
32 ASSERT_TRUE(everything_map.contains(
'\0'));
33 ASSERT_TRUE(!nothing_map.contains(
'\0'));
34 ASSERT_TRUE(!also_nothing_map.contains(
'\0'));
35 for (
unsigned char ch = 1; ch != 0; ++ch) {
36 ASSERT_TRUE(everything_map.contains(ch));
37 ASSERT_TRUE(!nothing_map.contains(ch));
38 ASSERT_TRUE(!also_nothing_map.contains(ch));
42 ASSERT_TRUE(symbols.contains(
'&'));
43 ASSERT_TRUE(symbols.contains(
'@'));
44 ASSERT_TRUE(symbols.contains(
'#'));
45 ASSERT_TRUE(symbols.contains(
'^'));
46 ASSERT_TRUE(!symbols.contains(
'!'));
47 ASSERT_TRUE(!symbols.contains(
'?'));
49 for (
unsigned char ch = 1; ch != 0; ++ch)
50 cnt += symbols.contains(ch);
56 ASSERT_TRUE(lets2.contains(
'k'));
57 ASSERT_TRUE(!lets3.contains(
'k'));
59 ASSERT_TRUE(symbols.IntersectsWith(lets));
60 ASSERT_TRUE(!lets2.IntersectsWith(lets));
61 ASSERT_TRUE(lets.IntersectsWith(symbols));
62 ASSERT_TRUE(!lets.IntersectsWith(lets2));
64 ASSERT_TRUE(nothing_map.IsZero());
65 ASSERT_TRUE(!lets.IsZero());
71 for (
size_t i = 0;
i < 256; ++
i)
76 std::string ClosedRangeString(
unsigned char lo,
unsigned char hi) {
89 TEST(Charmap, Constexpr) {
91 EXPECT_THAT(Members(kEmpty),
"");
94 EXPECT_THAT(Members(kA),
"A");
97 EXPECT_THAT(Members(kAZ),
"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
103 EXPECT_THAT(Members(kIdentifier),
105 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 107 "abcdefghijklmnopqrstuvwxyz");
109 for (
size_t i = 0;
i < 256; ++
i) {
110 EXPECT_TRUE(kAll.contains(
i)) <<
i;
114 EXPECT_THAT(Members(kHello),
" !,Hdelorw");
119 ~
absl::strings_internal::Charmap::Range(
'D',
'Z');
120 EXPECT_THAT(Members(kABC),
"ABC");
123 TEST(Charmap, Range) {
126 std::vector<size_t> poi = {0, 1, 2, 3, 4, 7, 8, 9, 15,
127 16, 17, 30, 31, 32, 33, 63, 64, 65,
128 127, 128, 129, 223, 224, 225, 254, 255};
129 for (
auto lo = poi.begin(); lo != poi.end(); ++lo) {
131 for (
auto hi = lo; hi != poi.end(); ++hi) {
134 ClosedRangeString(*lo, *hi));
139 bool AsBool(
int x) {
return static_cast<bool>(x); }
141 TEST(CharmapCtype, Match) {
142 for (
int c = 0; c < 256; ++c) {
144 SCOPED_TRACE(static_cast<char>(c));
145 EXPECT_EQ(AsBool(std::isupper(c)),
147 EXPECT_EQ(AsBool(std::islower(c)),
149 EXPECT_EQ(AsBool(std::isdigit(c)),
151 EXPECT_EQ(AsBool(std::isalpha(c)),
153 EXPECT_EQ(AsBool(std::isalnum(c)),
155 EXPECT_EQ(AsBool(std::isxdigit(c)),
157 EXPECT_EQ(AsBool(std::isprint(c)),
159 EXPECT_EQ(AsBool(std::isspace(c)),
161 EXPECT_EQ(AsBool(std::iscntrl(c)),
163 EXPECT_EQ(AsBool(std::isblank(c)),
165 EXPECT_EQ(AsBool(std::isgraph(c)),
167 EXPECT_EQ(AsBool(std::ispunct(c)),
constexpr Charmap AlphaCharmap()
constexpr bool contains(unsigned char c) const
constexpr Charmap XDigitCharmap()
constexpr Charmap PunctCharmap()
constexpr Charmap PrintCharmap()
constexpr Charmap SpaceCharmap()
constexpr Charmap BlankCharmap()
constexpr Charmap AlnumCharmap()
static constexpr Charmap Range(char lo, char hi)
constexpr Charmap GraphCharmap()
constexpr Charmap UpperCharmap()
static constexpr Charmap Char(char x)
constexpr Charmap LowerCharmap()
TEST(Symbolize, Unimplemented)
static constexpr Charmap FromString(const char *s)
constexpr Charmap DigitCharmap()
constexpr Charmap CntrlCharmap()