test: Use std::string::starts_with/ends_with instead of Boost (#7992)

This commit is contained in:
Mayukha Vadari
2026-08-10 13:22:40 -04:00
committed by GitHub
parent 4f8819565a
commit 07aa97fda4
4 changed files with 26 additions and 33 deletions

View File

@@ -6,7 +6,6 @@
#include <xrpl/config/Constants.h>
#include <xrpl/rdb/SociDB.h>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/optional/optional.hpp> // IWYU pragma: keep
@@ -108,7 +107,7 @@ public:
for (auto const& i : d)
{
DBConfig const sc(c, i.first);
BEAST_EXPECT(boost::ends_with(sc.connectionString(), i.first + i.second));
BEAST_EXPECT(sc.connectionString().ends_with(i.first + i.second));
}
}
void

View File

@@ -16,7 +16,6 @@
#include <xrpl/protocol/Serializer.h>
#include <xrpl/protocol/Sign.h>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/asio.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ssl/stream.hpp>
@@ -549,7 +548,7 @@ private:
res.keep_alive(req.keep_alive());
bool prepare = true;
if (boost::starts_with(path, "/validators2"))
if (path.starts_with("/validators2"))
{
res.result(http::status::ok);
res.insert("Content-Type", "application/json");
@@ -565,7 +564,7 @@ private:
{
int refresh = 5;
static constexpr char const* kRefreshPrefix = "/validators2/refresh/";
if (boost::starts_with(path, kRefreshPrefix))
if (path.starts_with(kRefreshPrefix))
{
refresh = boost::lexical_cast<unsigned int>(
path.substr(strlen(kRefreshPrefix)));
@@ -573,7 +572,7 @@ private:
res.body() = getList2_(refresh);
}
}
else if (boost::starts_with(path, "/validators"))
else if (path.starts_with("/validators"))
{
res.result(http::status::ok);
res.insert("Content-Type", "application/json");
@@ -589,7 +588,7 @@ private:
{
int refresh = 5;
static constexpr char const* kRefreshPrefix = "/validators/refresh/";
if (boost::starts_with(path, kRefreshPrefix))
if (path.starts_with(kRefreshPrefix))
{
refresh = boost::lexical_cast<unsigned int>(
path.substr(strlen(kRefreshPrefix)));
@@ -597,13 +596,13 @@ private:
res.body() = getList_(refresh);
}
}
else if (boost::starts_with(path, "/textfile"))
else if (path.starts_with("/textfile"))
{
prepare = false;
res.result(http::status::ok);
res.insert("Content-Type", "text/example");
// if huge was requested, lie about content length
std::uint64_t const cl = boost::starts_with(path, "/textfile/huge")
std::uint64_t const cl = path.starts_with("/textfile/huge")
? std::numeric_limits<uint64_t>::max()
: 1024;
res.content_length(cl);
@@ -617,41 +616,39 @@ private:
}
}
}
else if (boost::starts_with(path, "/sleep/"))
else if (path.starts_with("/sleep/"))
{
auto const sleepSec = boost::lexical_cast<unsigned int>(path.substr(7));
std::this_thread::sleep_for(std::chrono::seconds(sleepSec));
}
else if (boost::starts_with(path, "/redirect"))
else if (path.starts_with("/redirect"))
{
if (boost::ends_with(path, "/301"))
if (path.ends_with("/301"))
{
res.result(http::status::moved_permanently);
}
else if (boost::ends_with(path, "/302"))
else if (path.ends_with("/302"))
{
res.result(http::status::found);
}
else if (boost::ends_with(path, "/307"))
else if (path.ends_with("/307"))
{
res.result(http::status::temporary_redirect);
}
else if (boost::ends_with(path, "/308"))
else if (path.ends_with("/308"))
{
res.result(http::status::permanent_redirect);
}
std::stringstream location;
if (boost::starts_with(path, "/redirect_to/"))
if (path.starts_with("/redirect_to/"))
{
location << path.substr(13);
}
else if (!boost::starts_with(path, "/redirect_nolo"))
else if (!path.starts_with("/redirect_nolo"))
{
location << (ssl ? "https://" : "http://") << localEndpoint()
<< (boost::starts_with(path, "/redirect_forever/")
? path
: "/validators");
<< (path.starts_with("/redirect_forever/") ? path : "/validators");
}
if (!location.str().empty())
res.insert("Location", location.str());

View File

@@ -27,8 +27,6 @@
#include <xrpl/resource/detail/Entry.h>
#include <xrpl/resource/detail/Tuning.h>
#include <boost/algorithm/string/predicate.hpp>
#include <chrono>
#include <string>
@@ -203,13 +201,13 @@ class NoRippleCheck_test : public beast::unit_test::Suite
if (user)
{
BEAST_EXPECT(boost::starts_with(pa[0u].asString(), "You appear to have set"));
BEAST_EXPECT(boost::starts_with(pa[1u].asString(), "You should probably set"));
BEAST_EXPECT(pa[0u].asString().starts_with("You appear to have set"));
BEAST_EXPECT(pa[1u].asString().starts_with("You should probably set"));
}
else
{
BEAST_EXPECT(boost::starts_with(pa[0u].asString(), "You should immediately set"));
BEAST_EXPECT(boost::starts_with(pa[1u].asString(), "You should clear"));
BEAST_EXPECT(pa[0u].asString().starts_with("You should immediately set"));
BEAST_EXPECT(pa[1u].asString().starts_with("You should clear"));
}
}
else

View File

@@ -56,8 +56,7 @@ class ServerStatus_test : public beast::unit_test::Suite, public beast::test::En
static auto
makeConfig(std::string const& proto, bool admin = true, bool credentials = false)
{
auto const sectionName =
boost::starts_with(proto, "h") ? Sections::kPortRpc : Sections::kPortWs;
auto const sectionName = proto.starts_with("h") ? Sections::kPortRpc : Sections::kPortWs;
auto p = jtx::envconfig();
p->overwrite(sectionName, Keys::kProtocol, proto);
@@ -71,9 +70,9 @@ class ServerStatus_test : public beast::unit_test::Suite, public beast::test::En
}
p->overwrite(
boost::starts_with(proto, "h") ? Sections::kPortWs : Sections::kPortRpc,
proto.starts_with("h") ? Sections::kPortWs : Sections::kPortRpc,
Keys::kProtocol,
boost::starts_with(proto, "h") ? "ws" : "http");
proto.starts_with("h") ? "ws" : "http");
if (proto == "https")
{
@@ -261,7 +260,7 @@ class ServerStatus_test : public beast::unit_test::Suite, public beast::test::En
}
}
if (boost::starts_with(proto, "h"))
if (proto.starts_with("h"))
{
auto jrc = makeJSONRPCClient(env.app().config());
jrr = jrc->invoke("ledger_accept", jp);
@@ -289,7 +288,7 @@ class ServerStatus_test : public beast::unit_test::Suite, public beast::test::En
Env env{*this, makeConfig(proto, admin, credentials)};
json::Value jrr;
auto const protoWs = boost::starts_with(proto, "w");
auto const protoWs = proto.starts_with("w");
// the set of checks we do are different depending
// on how the admin config options are set
@@ -485,7 +484,7 @@ class ServerStatus_test : public beast::unit_test::Suite, public beast::test::En
boost::beast::http::response<boost::beast::http::string_body> resp;
boost::system::error_code ec;
if (boost::starts_with(clientProtocol, "h"))
if (clientProtocol.starts_with("h"))
{
doHTTPRequest(env, yield, clientProtocol == "https", resp, ec);
BEAST_EXPECT(ec);