style: Mark JSON literal strings with R"JSON (#2169)

This commit is contained in:
Ayaz Salikhov
2025-05-30 15:50:39 +01:00
committed by GitHub
parent 7588e9d5bf
commit ecdea015b9
76 changed files with 2811 additions and 2748 deletions

View File

@@ -69,7 +69,7 @@ TEST_F(CacheLoaderSettingsTest, DefaultSettingsParsedCorrectly)
TEST_F(CacheLoaderSettingsTest, NumThreadsCorrectlyPropagatedThroughConfig)
{
auto const cfg = getParseCacheConfig(json::parse(R"({"io_threads": 42})"));
auto const cfg = getParseCacheConfig(json::parse(R"JSON({"io_threads": 42})JSON"));
auto const settings = makeCacheLoaderSettings(cfg);
EXPECT_EQ(settings.numThreads, 42);
@@ -77,7 +77,7 @@ TEST_F(CacheLoaderSettingsTest, NumThreadsCorrectlyPropagatedThroughConfig)
TEST_F(CacheLoaderSettingsTest, NumDiffsCorrectlyPropagatedThroughConfig)
{
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"num_diffs": 42}})"));
auto const cfg = getParseCacheConfig(json::parse(R"JSON({"cache": {"num_diffs": 42}})JSON"));
auto const settings = makeCacheLoaderSettings(cfg);
EXPECT_EQ(settings.numCacheDiffs, 42);
@@ -85,7 +85,7 @@ TEST_F(CacheLoaderSettingsTest, NumDiffsCorrectlyPropagatedThroughConfig)
TEST_F(CacheLoaderSettingsTest, NumMarkersCorrectlyPropagatedThroughConfig)
{
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"num_markers": 42}})"));
auto const cfg = getParseCacheConfig(json::parse(R"JSON({"cache": {"num_markers": 42}})JSON"));
auto const settings = makeCacheLoaderSettings(cfg);
EXPECT_EQ(settings.numCacheMarkers, 42);
@@ -93,7 +93,7 @@ TEST_F(CacheLoaderSettingsTest, NumMarkersCorrectlyPropagatedThroughConfig)
TEST_F(CacheLoaderSettingsTest, PageFetchSizeCorrectlyPropagatedThroughConfig)
{
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"page_fetch_size": 42}})"));
auto const cfg = getParseCacheConfig(json::parse(R"JSON({"cache": {"page_fetch_size": 42}})JSON"));
auto const settings = makeCacheLoaderSettings(cfg);
EXPECT_EQ(settings.cachePageFetchSize, 42);
@@ -101,7 +101,7 @@ TEST_F(CacheLoaderSettingsTest, PageFetchSizeCorrectlyPropagatedThroughConfig)
TEST_F(CacheLoaderSettingsTest, SyncLoadStyleCorrectlyPropagatedThroughConfig)
{
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"load": "sYNC"}})"));
auto const cfg = getParseCacheConfig(json::parse(R"JSON({"cache": {"load": "sYNC"}})JSON"));
auto const settings = makeCacheLoaderSettings(cfg);
EXPECT_EQ(settings.loadStyle, CacheLoaderSettings::LoadStyle::SYNC);
@@ -110,7 +110,7 @@ TEST_F(CacheLoaderSettingsTest, SyncLoadStyleCorrectlyPropagatedThroughConfig)
TEST_F(CacheLoaderSettingsTest, AsyncLoadStyleCorrectlyPropagatedThroughConfig)
{
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"load": "aSynC"}})"));
auto const cfg = getParseCacheConfig(json::parse(R"JSON({"cache": {"load": "aSynC"}})JSON"));
auto const settings = makeCacheLoaderSettings(cfg);
EXPECT_EQ(settings.loadStyle, CacheLoaderSettings::LoadStyle::ASYNC);
@@ -120,14 +120,14 @@ TEST_F(CacheLoaderSettingsTest, AsyncLoadStyleCorrectlyPropagatedThroughConfig)
TEST_F(CacheLoaderSettingsTest, NoLoadStyleCorrectlyPropagatedThroughConfig)
{
{
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"load": "nONe"}})"));
auto const cfg = getParseCacheConfig(json::parse(R"JSON({"cache": {"load": "nONe"}})JSON"));
auto const settings = makeCacheLoaderSettings(cfg);
EXPECT_EQ(settings.loadStyle, CacheLoaderSettings::LoadStyle::NONE);
EXPECT_TRUE(settings.isDisabled());
}
{
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"load": "nO"}})"));
auto const cfg = getParseCacheConfig(json::parse(R"JSON({"cache": {"load": "nO"}})JSON"));
auto const settings = makeCacheLoaderSettings(cfg);
EXPECT_EQ(settings.loadStyle, CacheLoaderSettings::LoadStyle::NONE);

View File

@@ -207,7 +207,7 @@ TEST_P(ParametrizedCacheLoaderTest, CacheDisabledLeadsToCancellation)
//
TEST_F(CacheLoaderTest, SyncCacheLoaderWaitsTillFullyLoaded)
{
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"load": "sync"}})"));
auto const cfg = getParseCacheConfig(json::parse(R"JSON({"cache": {"load": "sync"}})JSON"));
CacheLoader<> loader{cfg, backend_, cache};
auto const diffs = diffProvider.getLatestDiff();
@@ -233,7 +233,7 @@ TEST_F(CacheLoaderTest, SyncCacheLoaderWaitsTillFullyLoaded)
TEST_F(CacheLoaderTest, AsyncCacheLoaderCanBeStopped)
{
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"load": "async"}})"));
auto const cfg = getParseCacheConfig(json::parse(R"JSON({"cache": {"load": "async"}})JSON"));
CacheLoader loader{cfg, backend_, cache};
auto const diffs = diffProvider.getLatestDiff();
@@ -261,7 +261,7 @@ TEST_F(CacheLoaderTest, AsyncCacheLoaderCanBeStopped)
TEST_F(CacheLoaderTest, DisabledCacheLoaderDoesNotLoadCache)
{
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"load": "none"}})"));
auto const cfg = getParseCacheConfig(json::parse(R"JSON({"cache": {"load": "none"}})JSON"));
CacheLoader loader{cfg, backend_, cache};
EXPECT_CALL(cache, updateImp).Times(0);
@@ -273,7 +273,7 @@ TEST_F(CacheLoaderTest, DisabledCacheLoaderDoesNotLoadCache)
TEST_F(CacheLoaderTest, DisabledCacheLoaderCanCallStopAndWait)
{
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"load": "none"}})"));
auto const cfg = getParseCacheConfig(json::parse(R"JSON({"cache": {"load": "none"}})JSON"));
CacheLoader loader{cfg, backend_, cache};
EXPECT_CALL(cache, updateImp).Times(0);

View File

@@ -71,7 +71,7 @@ struct ForwardingSourceOperationsTests : ForwardingSourceTests {
}
protected:
std::string const message_ = R"({"data": "some_data"})";
std::string const message_ = R"JSON({"data": "some_data"})JSON";
boost::json::object const reply_ = {{"reply", "some_reply"}};
};

View File

@@ -62,7 +62,7 @@ using namespace util::config;
using testing::Return;
using namespace util::prometheus;
constexpr static auto const kTWO_SOURCES_LEDGER_RESPONSE = R"({
constexpr static auto const kTWO_SOURCES_LEDGER_RESPONSE = R"JSON({
"etl_sources": [
{
"ip": "127.0.0.1",
@@ -75,9 +75,9 @@ constexpr static auto const kTWO_SOURCES_LEDGER_RESPONSE = R"({
"grpc_port": "source2"
}
]
})";
})JSON";
constexpr static auto const kTHREE_SOURCES_LEDGER_RESPONSE = R"({
constexpr static auto const kTHREE_SOURCES_LEDGER_RESPONSE = R"JSON({
"etl_sources": [
{
"ip": "127.0.0.1",
@@ -95,7 +95,7 @@ constexpr static auto const kTHREE_SOURCES_LEDGER_RESPONSE = R"({
"grpc_port": "source3"
}
]
})";
})JSON";
inline static ClioConfigDefinition
getParseLoadBalancerConfig(boost::json::value val)
@@ -227,8 +227,8 @@ TEST_F(LoadBalancerConstructorTests, fetchETLState_Source0Fails1OK)
TEST_F(LoadBalancerConstructorTests, fetchETLState_DifferentNetworkID)
{
auto const source1Json = boost::json::parse(R"({"result": {"info": {"network_id": 0}}})");
auto const source2Json = boost::json::parse(R"({"result": {"info": {"network_id": 1}}})");
auto const source1Json = boost::json::parse(R"JSON({"result": {"info": {"network_id": 0}}})JSON");
auto const source2Json = boost::json::parse(R"JSON({"result": {"info": {"network_id": 1}}})JSON");
EXPECT_CALL(sourceFactory_, makeSource).Times(2);
EXPECT_CALL(sourceFactory_.sourceAt(0), forwardToRippled).WillOnce(Return(source1Json.as_object()));
@@ -251,8 +251,8 @@ TEST_F(LoadBalancerConstructorTests, fetchETLState_AllSourcesFailButAllowNoEtlIs
TEST_F(LoadBalancerConstructorTests, fetchETLState_DifferentNetworkIDButAllowNoEtlIsTrue)
{
auto const source1Json = boost::json::parse(R"({"result": {"info": {"network_id": 0}}})");
auto const source2Json = boost::json::parse(R"({"result": {"info": {"network_id": 1}}})");
auto const source1Json = boost::json::parse(R"JSON({"result": {"info": {"network_id": 0}}})JSON");
auto const source2Json = boost::json::parse(R"JSON({"result": {"info": {"network_id": 1}}})JSON");
EXPECT_CALL(sourceFactory_, makeSource).Times(2);
EXPECT_CALL(sourceFactory_.sourceAt(0), forwardToRippled).WillOnce(Return(source1Json.as_object()));
EXPECT_CALL(sourceFactory_.sourceAt(0), run);

View File

@@ -71,7 +71,7 @@ struct SubscriptionSourceConnectionTestsBase : SyncAsioContextTest {
ASSERT_TRUE(message);
EXPECT_EQ(
message.value(),
R"({"command":"subscribe","streams":["ledger","manifests","validations","transactions_proposed"]})"
R"JSON({"command":"subscribe","streams":["ledger","manifests","validations","transactions_proposed"]})JSON"
);
}();
return std::move(connection).value();
@@ -199,7 +199,7 @@ TEST_F(SubscriptionSourceReadTests, GotWrongMessage_Reconnect)
TEST_F(SubscriptionSourceReadTests, GotResult)
{
boost::asio::spawn(ctx_, [this](boost::asio::yield_context yield) {
auto connection = connectAndSendMessage(R"({"result":{})", yield);
auto connection = connectAndSendMessage(R"JSON({"result":{})JSON", yield);
connection.close(yield);
});
@@ -211,7 +211,7 @@ TEST_F(SubscriptionSourceReadTests, GotResult)
TEST_F(SubscriptionSourceReadTests, GotResultWithLedgerIndex)
{
boost::asio::spawn(ctx_, [this](boost::asio::yield_context yield) {
auto connection = connectAndSendMessage(R"({"result":{"ledger_index":123}})", yield);
auto connection = connectAndSendMessage(R"JSON({"result":{"ledger_index":123}})JSON", yield);
connection.close(yield);
});
@@ -224,7 +224,7 @@ TEST_F(SubscriptionSourceReadTests, GotResultWithLedgerIndex)
TEST_F(SubscriptionSourceReadTests, GotResultWithLedgerIndexAsString_Reconnect)
{
boost::asio::spawn(ctx_, [this](boost::asio::yield_context yield) {
auto connection = connectAndSendMessage(R"({"result":{"ledger_index":"123"}})", yield);
auto connection = connectAndSendMessage(R"JSON({"result":{"ledger_index":"123"}})JSON", yield);
// We have to schedule receiving to receive close frame and boost will handle it automatically
connection.receive(yield);
serverConnection(yield);
@@ -238,7 +238,7 @@ TEST_F(SubscriptionSourceReadTests, GotResultWithLedgerIndexAsString_Reconnect)
TEST_F(SubscriptionSourceReadTests, GotResultWithValidatedLedgersAsNumber_Reconnect)
{
boost::asio::spawn(ctx_, [this](boost::asio::yield_context yield) {
auto connection = connectAndSendMessage(R"({"result":{"validated_ledgers":123}})", yield);
auto connection = connectAndSendMessage(R"JSON({"result":{"validated_ledgers":123}})JSON", yield);
// We have to schedule receiving to receive close frame and boost will handle it automatically
connection.receive(yield);
serverConnection(yield);
@@ -262,7 +262,7 @@ TEST_F(SubscriptionSourceReadTests, GotResultWithValidatedLedgers)
EXPECT_FALSE(subscriptionSource_.hasLedger(790));
boost::asio::spawn(ctx_, [this](boost::asio::yield_context yield) {
auto connection = connectAndSendMessage(R"({"result":{"validated_ledgers":"123-456,789,32"}})", yield);
auto connection = connectAndSendMessage(R"JSON({"result":{"validated_ledgers":"123-456,789,32"}})JSON", yield);
connection.close(yield);
});
@@ -286,7 +286,7 @@ TEST_F(SubscriptionSourceReadTests, GotResultWithValidatedLedgers)
TEST_F(SubscriptionSourceReadTests, GotResultWithValidatedLedgersWrongValue_Reconnect)
{
boost::asio::spawn(ctx_, [this](boost::asio::yield_context yield) {
auto connection = connectAndSendMessage(R"({"result":{"validated_ledgers":"123-456-789,32"}})", yield);
auto connection = connectAndSendMessage(R"JSON({"result":{"validated_ledgers":"123-456-789,32"}})JSON", yield);
// We have to schedule receiving to receive close frame and boost will handle it automatically
connection.receive(yield);
serverConnection(yield);
@@ -306,7 +306,8 @@ TEST_F(SubscriptionSourceReadTests, GotResultWithLedgerIndexAndValidatedLedgers)
EXPECT_FALSE(subscriptionSource_.hasLedger(4));
boost::asio::spawn(ctx_, [this](boost::asio::yield_context yield) {
auto connection = connectAndSendMessage(R"({"result":{"ledger_index":123,"validated_ledgers":"1-3"}})", yield);
auto connection =
connectAndSendMessage(R"JSON({"result":{"ledger_index":123,"validated_ledgers":"1-3"}})JSON", yield);
connection.close(yield);
});
@@ -326,7 +327,7 @@ TEST_F(SubscriptionSourceReadTests, GotResultWithLedgerIndexAndValidatedLedgers)
TEST_F(SubscriptionSourceReadTests, GotLedgerClosed)
{
boost::asio::spawn(ctx_, [this](boost::asio::yield_context yield) {
auto connection = connectAndSendMessage(R"({"type":"ledgerClosed"})", yield);
auto connection = connectAndSendMessage(R"JSON({"type":"ledgerClosed"})JSON", yield);
connection.close(yield);
});
@@ -340,7 +341,7 @@ TEST_F(SubscriptionSourceReadTests, GotLedgerClosedForwardingIsSet)
subscriptionSource_.setForwarding(true);
boost::asio::spawn(ctx_, [this](boost::asio::yield_context yield) {
auto connection = connectAndSendMessage(R"({"type": "ledgerClosed"})", yield);
auto connection = connectAndSendMessage(R"JSON({"type": "ledgerClosed"})JSON", yield);
connection.close(yield);
});
@@ -356,7 +357,7 @@ TEST_F(SubscriptionSourceReadTests, GotLedgerClosedForwardingIsSet)
TEST_F(SubscriptionSourceReadTests, GotLedgerClosedWithLedgerIndex)
{
boost::asio::spawn(ctx_, [this](boost::asio::yield_context yield) {
auto connection = connectAndSendMessage(R"({"type": "ledgerClosed","ledger_index": 123})", yield);
auto connection = connectAndSendMessage(R"JSON({"type": "ledgerClosed","ledger_index": 123})JSON", yield);
connection.close(yield);
});
@@ -369,7 +370,7 @@ TEST_F(SubscriptionSourceReadTests, GotLedgerClosedWithLedgerIndex)
TEST_F(SubscriptionSourceReadTests, GotLedgerClosedWithLedgerIndexAsString_Reconnect)
{
boost::asio::spawn(ctx_, [this](boost::asio::yield_context yield) {
auto connection = connectAndSendMessage(R"({"type":"ledgerClosed","ledger_index":"123"}})", yield);
auto connection = connectAndSendMessage(R"JSON({"type":"ledgerClosed","ledger_index":"123"}})JSON", yield);
// We have to schedule receiving to receive close frame and boost will handle it automatically
connection.receive(yield);
serverConnection(yield);
@@ -383,7 +384,7 @@ TEST_F(SubscriptionSourceReadTests, GotLedgerClosedWithLedgerIndexAsString_Recon
TEST_F(SubscriptionSourceReadTests, GorLedgerClosedWithValidatedLedgersAsNumber_Reconnect)
{
boost::asio::spawn(ctx_, [this](boost::asio::yield_context yield) {
auto connection = connectAndSendMessage(R"({"type":"ledgerClosed","validated_ledgers":123})", yield);
auto connection = connectAndSendMessage(R"JSON({"type":"ledgerClosed","validated_ledgers":123})JSON", yield);
// We have to schedule receiving to receive close frame and boost will handle it automatically
connection.receive(yield);
serverConnection(yield);
@@ -402,7 +403,7 @@ TEST_F(SubscriptionSourceReadTests, GotLedgerClosedWithValidatedLedgers)
EXPECT_FALSE(subscriptionSource_.hasLedger(3));
boost::asio::spawn(ctx_, [this](boost::asio::yield_context yield) {
auto connection = connectAndSendMessage(R"({"type":"ledgerClosed","validated_ledgers":"1-2"})", yield);
auto connection = connectAndSendMessage(R"JSON({"type":"ledgerClosed","validated_ledgers":"1-2"})JSON", yield);
connection.close(yield);
});
@@ -425,8 +426,9 @@ TEST_F(SubscriptionSourceReadTests, GotLedgerClosedWithLedgerIndexAndValidatedLe
EXPECT_FALSE(subscriptionSource_.hasLedger(3));
boost::asio::spawn(ctx_, [this](boost::asio::yield_context yield) {
auto connection =
connectAndSendMessage(R"({"type":"ledgerClosed","ledger_index":123,"validated_ledgers":"1-2"})", yield);
auto connection = connectAndSendMessage(
R"JSON({"type":"ledgerClosed","ledger_index":123,"validated_ledgers":"1-2"})JSON", yield
);
connection.close(yield);
});
@@ -445,7 +447,7 @@ TEST_F(SubscriptionSourceReadTests, GotLedgerClosedWithLedgerIndexAndValidatedLe
TEST_F(SubscriptionSourceReadTests, GotTransactionIsForwardingFalse)
{
boost::asio::spawn(ctx_, [this](boost::asio::yield_context yield) {
auto connection = connectAndSendMessage(R"({"transaction":"some_transaction_data"})", yield);
auto connection = connectAndSendMessage(R"JSON({"transaction":"some_transaction_data"})JSON", yield);
connection.close(yield);
});
@@ -489,7 +491,7 @@ TEST_F(SubscriptionSourceReadTests, GotTransactionWithMetaIsForwardingFalse)
TEST_F(SubscriptionSourceReadTests, GotValidationReceivedIsForwardingFalse)
{
boost::asio::spawn(ctx_, [this](boost::asio::yield_context yield) {
auto connection = connectAndSendMessage(R"({"type":"validationReceived"})", yield);
auto connection = connectAndSendMessage(R"JSON({"type":"validationReceived"})JSON", yield);
connection.close(yield);
});
@@ -517,7 +519,7 @@ TEST_F(SubscriptionSourceReadTests, GotValidationReceivedIsForwardingTrue)
TEST_F(SubscriptionSourceReadTests, GotManiefstReceivedIsForwardingFalse)
{
boost::asio::spawn(ctx_, [this](boost::asio::yield_context yield) {
auto connection = connectAndSendMessage(R"({"type":"manifestReceived"})", yield);
auto connection = connectAndSendMessage(R"JSON({"type":"manifestReceived"})JSON", yield);
connection.close(yield);
});