Abseil Common Libraries (C++) (grcp 依赖) https://abseil.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
4.1 KiB

Export of internal Abseil changes -- f012012ef78234a6a4585321b67d7b7c92ebc266 by Laramie Leavitt <lar@google.com>: Slight restructuring of absl/random/internal randen implementation. Convert round-keys.inc into randen_round_keys.cc file. Consistently use a 128-bit pointer type for internal method parameters. This allows simpler pointer arithmetic in C++ & permits removal of some constants and casts. Remove some redundancy in comments & constexpr variables. Specifically, all references to Randen algorithm parameters use RandenTraits; duplication in RandenSlow removed. PiperOrigin-RevId: 312190313 -- dc8b42e054046741e9ed65335bfdface997c6063 by Abseil Team <absl-team@google.com>: Internal change. PiperOrigin-RevId: 312167304 -- f13d248fafaf206492c1362c3574031aea3abaf7 by Matthew Brown <matthewbr@google.com>: Cleanup StrFormat extensions a little. PiperOrigin-RevId: 312166336 -- 9d9117589667afe2332bb7ad42bc967ca7c54502 by Derek Mauro <dmauro@google.com>: Internal change PiperOrigin-RevId: 312105213 -- 9a12b9b3aa0e59b8ee6cf9408ed0029045543a9b by Abseil Team <absl-team@google.com>: Complete IGNORE_TYPE macro renaming. PiperOrigin-RevId: 311999699 -- 64756f20d61021d999bd0d4c15e9ad3857382f57 by Gennadiy Rozental <rogeeff@google.com>: Switch to fixed bytes specific default value. This fixes the Abseil Flags for big endian platforms. PiperOrigin-RevId: 311844448 -- bdbe6b5b29791dbc3816ada1828458b3010ff1e9 by Laramie Leavitt <lar@google.com>: Change many distribution tests to use pcg_engine as a deterministic source of entropy. It's reasonable to test that the BitGen itself has good entropy, however when testing the cross product of all random distributions x all the architecture variations x all submitted changes results in a large number of tests. In order to account for these failures while still using good entropy requires that our allowed sigma need to account for all of these independent tests. Our current sigma values are too restrictive, and we see a lot of failures, so we have to either relax the sigma values or convert some of the statistical tests to use deterministic values. This changelist does the latter. PiperOrigin-RevId: 311840096 GitOrigin-RevId: f012012ef78234a6a4585321b67d7b7c92ebc266 Change-Id: Ic84886f38ff30d7d72c126e9b63c9a61eb729a1a
5 years ago
// Copyright 2017 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "absl/strings/match.h"
#include "gtest/gtest.h"
namespace {
TEST(MatchTest, StartsWith) {
const std::string s1("123\0abc", 7);
const absl::string_view a("foobar");
const absl::string_view b(s1);
const absl::string_view e;
EXPECT_TRUE(absl::StartsWith(a, a));
EXPECT_TRUE(absl::StartsWith(a, "foo"));
EXPECT_TRUE(absl::StartsWith(a, e));
EXPECT_TRUE(absl::StartsWith(b, s1));
EXPECT_TRUE(absl::StartsWith(b, b));
EXPECT_TRUE(absl::StartsWith(b, e));
EXPECT_TRUE(absl::StartsWith(e, ""));
EXPECT_FALSE(absl::StartsWith(a, b));
EXPECT_FALSE(absl::StartsWith(b, a));
EXPECT_FALSE(absl::StartsWith(e, a));
}
TEST(MatchTest, EndsWith) {
const std::string s1("123\0abc", 7);
const absl::string_view a("foobar");
const absl::string_view b(s1);
const absl::string_view e;
EXPECT_TRUE(absl::EndsWith(a, a));
EXPECT_TRUE(absl::EndsWith(a, "bar"));
EXPECT_TRUE(absl::EndsWith(a, e));
EXPECT_TRUE(absl::EndsWith(b, s1));
EXPECT_TRUE(absl::EndsWith(b, b));
EXPECT_TRUE(absl::EndsWith(b, e));
EXPECT_TRUE(absl::EndsWith(e, ""));
EXPECT_FALSE(absl::EndsWith(a, b));
EXPECT_FALSE(absl::EndsWith(b, a));
EXPECT_FALSE(absl::EndsWith(e, a));
}
TEST(MatchTest, Contains) {
absl::string_view a("abcdefg");
absl::string_view b("abcd");
absl::string_view c("efg");
absl::string_view d("gh");
EXPECT_TRUE(absl::StrContains(a, a));
EXPECT_TRUE(absl::StrContains(a, b));
EXPECT_TRUE(absl::StrContains(a, c));
EXPECT_FALSE(absl::StrContains(a, d));
EXPECT_TRUE(absl::StrContains("", ""));
EXPECT_TRUE(absl::StrContains("abc", ""));
EXPECT_FALSE(absl::StrContains("", "a"));
}
Export of internal Abseil changes -- ff793052bd01e1e4fcf639f94d7c30c4855a9372 by Evan Brown <ezb@google.com>: Roll forward of btree_iterator refactoring. PiperOrigin-RevId: 346116047 -- 17984679f16e3e2139b0f14fa76f4a6ca16a3ef9 by Chris Kennelly <ckennelly@google.com>: Extend absl::StrContains to accept single character needles. Single characters are more efficient to search for. Extending this API allows the abseil-string-find-str-contains Clang Tidy to include this pattern. The C++ committee has adopted http://wg21.link/P1679 for inclusion in C++23. PiperOrigin-RevId: 346095060 -- ef20b31c501b1dcaa25e244fd8f8aa43dec09bd6 by Jorg Brown <jorg@google.com>: Internal change for cord ring PiperOrigin-RevId: 346087545 -- b70f2c1cb77fc9e733a126e790967d45c5fd1dc7 by Derek Mauro <dmauro@google.com>: Release layout_benchmark PiperOrigin-RevId: 345968909 -- 3a0eda337ee43622f92cfe14c2aa06f72dc71ee5 by Derek Mauro <dmauro@google.com>: Release raw_hash_set_probe_benchmark PiperOrigin-RevId: 345965969 -- abffdb4bb241a2264cb4e73a6262b660bb10447d by Derek Mauro <dmauro@google.com>: Internal change PiperOrigin-RevId: 345733599 -- 7c9e24a71188df945be17fe98f700bdb51f81b16 by Derek Mauro <dmauro@google.com>: Release hash_benchmark PiperOrigin-RevId: 345721635 -- d68f33f17f9a8cd3f6da8eee3870bdb46402cdc8 by Derek Mauro <dmauro@google.com>: Release raw_hash_set_benchmark PiperOrigin-RevId: 345708384 -- 6e6c547d4d1327b226c0ffe8ff34d0aa103ce24b by Abseil Team <absl-team@google.com>: Updates the implementation of InlinedVector to accurately express the value-initialization semantics of the default constructor PiperOrigin-RevId: 345548260 -- 1532424deda97d468444c217cc0fa4614099c7c1 by Evan Brown <ezb@google.com>: Rollback btree_iterator refactoring. PiperOrigin-RevId: 345543900 GitOrigin-RevId: ff793052bd01e1e4fcf639f94d7c30c4855a9372 Change-Id: I719831981fd056de41939f9addfee3d85e3b49b2
4 years ago
TEST(MatchTest, ContainsChar) {
absl::string_view a("abcdefg");
absl::string_view b("abcd");
EXPECT_TRUE(absl::StrContains(a, 'a'));
EXPECT_TRUE(absl::StrContains(a, 'b'));
EXPECT_TRUE(absl::StrContains(a, 'e'));
EXPECT_FALSE(absl::StrContains(a, 'h'));
EXPECT_TRUE(absl::StrContains(b, 'a'));
EXPECT_TRUE(absl::StrContains(b, 'b'));
EXPECT_FALSE(absl::StrContains(b, 'e'));
EXPECT_FALSE(absl::StrContains(b, 'h'));
EXPECT_FALSE(absl::StrContains("", 'a'));
EXPECT_FALSE(absl::StrContains("", 'a'));
}
Export of internal Abseil changes -- f012012ef78234a6a4585321b67d7b7c92ebc266 by Laramie Leavitt <lar@google.com>: Slight restructuring of absl/random/internal randen implementation. Convert round-keys.inc into randen_round_keys.cc file. Consistently use a 128-bit pointer type for internal method parameters. This allows simpler pointer arithmetic in C++ & permits removal of some constants and casts. Remove some redundancy in comments & constexpr variables. Specifically, all references to Randen algorithm parameters use RandenTraits; duplication in RandenSlow removed. PiperOrigin-RevId: 312190313 -- dc8b42e054046741e9ed65335bfdface997c6063 by Abseil Team <absl-team@google.com>: Internal change. PiperOrigin-RevId: 312167304 -- f13d248fafaf206492c1362c3574031aea3abaf7 by Matthew Brown <matthewbr@google.com>: Cleanup StrFormat extensions a little. PiperOrigin-RevId: 312166336 -- 9d9117589667afe2332bb7ad42bc967ca7c54502 by Derek Mauro <dmauro@google.com>: Internal change PiperOrigin-RevId: 312105213 -- 9a12b9b3aa0e59b8ee6cf9408ed0029045543a9b by Abseil Team <absl-team@google.com>: Complete IGNORE_TYPE macro renaming. PiperOrigin-RevId: 311999699 -- 64756f20d61021d999bd0d4c15e9ad3857382f57 by Gennadiy Rozental <rogeeff@google.com>: Switch to fixed bytes specific default value. This fixes the Abseil Flags for big endian platforms. PiperOrigin-RevId: 311844448 -- bdbe6b5b29791dbc3816ada1828458b3010ff1e9 by Laramie Leavitt <lar@google.com>: Change many distribution tests to use pcg_engine as a deterministic source of entropy. It's reasonable to test that the BitGen itself has good entropy, however when testing the cross product of all random distributions x all the architecture variations x all submitted changes results in a large number of tests. In order to account for these failures while still using good entropy requires that our allowed sigma need to account for all of these independent tests. Our current sigma values are too restrictive, and we see a lot of failures, so we have to either relax the sigma values or convert some of the statistical tests to use deterministic values. This changelist does the latter. PiperOrigin-RevId: 311840096 GitOrigin-RevId: f012012ef78234a6a4585321b67d7b7c92ebc266 Change-Id: Ic84886f38ff30d7d72c126e9b63c9a61eb729a1a
5 years ago
TEST(MatchTest, ContainsNull) {
const std::string s = "foo";
const char* cs = "foo";
const absl::string_view sv("foo");
const absl::string_view sv2("foo\0bar", 4);
EXPECT_EQ(s, "foo");
EXPECT_EQ(sv, "foo");
EXPECT_NE(sv2, "foo");
EXPECT_TRUE(absl::EndsWith(s, sv));
EXPECT_TRUE(absl::StartsWith(cs, sv));
EXPECT_TRUE(absl::StrContains(cs, sv));
EXPECT_FALSE(absl::StrContains(cs, sv2));
}
TEST(MatchTest, EqualsIgnoreCase) {
std::string text = "the";
absl::string_view data(text);
EXPECT_TRUE(absl::EqualsIgnoreCase(data, "The"));
EXPECT_TRUE(absl::EqualsIgnoreCase(data, "THE"));
EXPECT_TRUE(absl::EqualsIgnoreCase(data, "the"));
EXPECT_FALSE(absl::EqualsIgnoreCase(data, "Quick"));
EXPECT_FALSE(absl::EqualsIgnoreCase(data, "then"));
}
TEST(MatchTest, StartsWithIgnoreCase) {
EXPECT_TRUE(absl::StartsWithIgnoreCase("foo", "foo"));
EXPECT_TRUE(absl::StartsWithIgnoreCase("foo", "Fo"));
EXPECT_TRUE(absl::StartsWithIgnoreCase("foo", ""));
EXPECT_FALSE(absl::StartsWithIgnoreCase("foo", "fooo"));
EXPECT_FALSE(absl::StartsWithIgnoreCase("", "fo"));
}
TEST(MatchTest, EndsWithIgnoreCase) {
EXPECT_TRUE(absl::EndsWithIgnoreCase("foo", "foo"));
EXPECT_TRUE(absl::EndsWithIgnoreCase("foo", "Oo"));
EXPECT_TRUE(absl::EndsWithIgnoreCase("foo", ""));
EXPECT_FALSE(absl::EndsWithIgnoreCase("foo", "fooo"));
EXPECT_FALSE(absl::EndsWithIgnoreCase("", "fo"));
}
} // namespace