Move JSON helpers to lib

This commit is contained in:
WarmUpTill
2025-04-17 11:51:00 +02:00
committed by WarmUpTill
parent 7c4c0056ce
commit 5568f92ad0
13 changed files with 64 additions and 58 deletions

View File

@@ -64,9 +64,14 @@ target_sources(
# --- json --- #
if(TARGET jsoncons)
target_link_libraries(${PROJECT_NAME} PRIVATE jsoncons)
target_compile_definitions(${PROJECT_NAME} PRIVATE JSONPATH_SUPPORT=1)
endif()
target_link_libraries(${PROJECT_NAME} PUBLIC nlohmann_json::nlohmann_json)
target_sources(
${PROJECT_NAME}
PRIVATE test-json.cpp ${ADVSS_SOURCE_DIR}/plugins/base/utils/json-helpers.cpp)
${PROJECT_NAME} PRIVATE test-json.cpp
${ADVSS_SOURCE_DIR}/lib/utils/json-helpers.cpp)
# --- math --- #
@@ -95,8 +100,6 @@ target_sources(
# --- utility --- #
target_link_libraries(${PROJECT_NAME} PUBLIC nlohmann_json::nlohmann_json)
target_sources(
${PROJECT_NAME} PRIVATE test-utility.cpp
${ADVSS_SOURCE_DIR}/lib/utils/utility.cpp)

View File

@@ -51,3 +51,18 @@ TEST_CASE("MatchJson", "[json-helpers]")
result = advss::MatchJson("{\n \"test\": true\n}\n", "(", regex);
REQUIRE(result == false);
}
TEST_CASE("GetJsonField", "[utility]")
{
auto result = advss::GetJsonField("{}", "");
REQUIRE_FALSE(result);
result = advss::GetJsonField("{}", "not there");
REQUIRE_FALSE(result);
result = advss::GetJsonField("invalid json", "not there");
REQUIRE_FALSE(result);
result = advss::GetJsonField("{ \"test\": 1 }", "test");
REQUIRE(*result == "1");
}

View File

@@ -20,21 +20,6 @@ TEST_CASE("ReplaceAll", "[utility]")
REQUIRE(input == "sleeping");
}
TEST_CASE("GetJsonField", "[utility]")
{
auto result = advss::GetJsonField("{}", "");
REQUIRE_FALSE(result);
result = advss::GetJsonField("{}", "not there");
REQUIRE_FALSE(result);
result = advss::GetJsonField("invalid json", "not there");
REQUIRE_FALSE(result);
result = advss::GetJsonField("{ \"test\": 1 }", "test");
REQUIRE(*result == "1");
}
TEST_CASE("CompareIgnoringLineEnding", "[utility]")
{
QString s1;