Re-sync with internal repository
[hiphop-php.git] / third-party / proxygen / src / proxygen / lib / utils / test / UtilTest.cpp
blob66bea591c1c4cba14909e9a274e2dcfa8ca565f7
1 /*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 * All rights reserved.
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
9 #include <folly/portability/GTest.h>
10 #include <proxygen/lib/utils/UtilInl.h>
12 using namespace proxygen;
14 TEST(UtilTest, CaseInsensitiveEqual) {
15 ASSERT_TRUE(caseInsensitiveEqual("foo", "FOO"));
16 ASSERT_TRUE(caseInsensitiveEqual(std::string("foo"), "FOO"));
17 ASSERT_FALSE(caseInsensitiveEqual(std::string("foo"), "FOO2"));
18 ASSERT_FALSE(caseInsensitiveEqual("fo", "FOO"));
19 ASSERT_FALSE(caseInsensitiveEqual("FO", "FOO"));
22 TEST(UtilTest, findLastOf) {
23 folly::StringPiece p1("");
24 folly::StringPiece p2(".");
25 folly::StringPiece p3("..");
26 folly::StringPiece p4("abc");
27 folly::StringPiece p5("abc.def");
29 EXPECT_EQ(findLastOf(p1, '.'), std::string::npos);
30 EXPECT_EQ(findLastOf(p2, '.'), 0);
31 EXPECT_EQ(findLastOf(p3, '.'), 1);
32 EXPECT_EQ(findLastOf(p4, '.'), std::string::npos);
33 EXPECT_EQ(findLastOf(p5, '.'), 3);
36 folly::ByteRange input(const char *str) {
37 return folly::ByteRange(reinterpret_cast<const uint8_t *>(str), strlen(str));
40 TEST(UtilTest, validateURL) {
41 EXPECT_TRUE(validateURL(input("/foo\xff"), URLValidateMode::STRICT_COMPAT));
42 EXPECT_FALSE(validateURL(input("/foo\xff"), URLValidateMode::STRICT));