Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions include/vix/json/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,7 @@ namespace vix::json
namespace literals
{
#if defined(VIX_JSON_ENABLE_LITERALS) && (VIX_JSON_ENABLE_LITERALS == 1)
inline Json operator"" _json(const char *s, std::size_t n)
{
return Json::parse(std::string_view{s, n});
}
using nlohmann::literals::operator""_json;
#endif
} // namespace literals

Expand Down
107 changes: 107 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ set(VIX_JSON_TEST_TARGETS
json_simple_test
)

set(VIX_JSON_HEADER_TESTS
build
convert
dumps
jpath
json
loads
simple
)

foreach(test_name IN LISTS VIX_JSON_TEST_TARGETS)
add_executable(${test_name}
${test_name}.cpp
Expand Down Expand Up @@ -46,6 +56,103 @@ foreach(test_name IN LISTS VIX_JSON_TEST_TARGETS)
)
endforeach()

foreach(header_name IN LISTS VIX_JSON_HEADER_TESTS)
set(test_name json_${header_name}_header_test)

add_executable(${test_name}
headers/${header_name}_header_test.cpp
)

target_link_libraries(${test_name}
PRIVATE
vix::json
)

target_compile_features(${test_name}
PRIVATE
cxx_std_20
)

if (TARGET vix_warnings)
target_link_libraries(${test_name}
PRIVATE
vix_warnings
)
elseif (MSVC)
target_compile_options(${test_name}
PRIVATE
/W4
/permissive-
)
else()
target_compile_options(${test_name}
PRIVATE
-Wall
-Wextra
-Wpedantic
-Wconversion
-Wsign-conversion
)
endif()

add_test(
NAME ${test_name}
COMMAND ${test_name}
)

list(APPEND VIX_JSON_TEST_TARGETS ${test_name})
endforeach()

set(literal_test_name json_literals_header_test)

add_executable(${literal_test_name}
headers/json_header_test.cpp
)

target_link_libraries(${literal_test_name}
PRIVATE
vix::json
)

target_compile_features(${literal_test_name}
PRIVATE
cxx_std_20
)

target_compile_definitions(${literal_test_name}
PRIVATE
VIX_JSON_ENABLE_LITERALS=1
)

if (TARGET vix_warnings)
target_link_libraries(${literal_test_name}
PRIVATE
vix_warnings
)
elseif (MSVC)
target_compile_options(${literal_test_name}
PRIVATE
/W4
/permissive-
)
else()
target_compile_options(${literal_test_name}
PRIVATE
-Wall
-Wextra
-Wpedantic
-Wconversion
-Wsign-conversion
)
endif()

add_test(
NAME ${literal_test_name}
COMMAND ${literal_test_name}
)

list(APPEND VIX_JSON_TEST_TARGETS ${literal_test_name})

add_custom_target(vix_json_tests
DEPENDS
${VIX_JSON_TEST_TARGETS}
Expand Down
6 changes: 6 additions & 0 deletions tests/headers/build_header_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <vix/json/build.hpp>

int main()
{
return 0;
}
6 changes: 6 additions & 0 deletions tests/headers/convert_header_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <vix/json/convert.hpp>

int main()
{
return 0;
}
6 changes: 6 additions & 0 deletions tests/headers/dumps_header_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <vix/json/dumps.hpp>

int main()
{
return 0;
}
6 changes: 6 additions & 0 deletions tests/headers/jpath_header_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <vix/json/jpath.hpp>

int main()
{
return 0;
}
15 changes: 15 additions & 0 deletions tests/headers/json_header_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <vix/json/json.hpp>

#if defined(VIX_JSON_ENABLE_LITERALS) && (VIX_JSON_ENABLE_LITERALS == 1)
using namespace vix::json::literals;
#endif

int main()
{
#if defined(VIX_JSON_ENABLE_LITERALS) && (VIX_JSON_ENABLE_LITERALS == 1)
const auto value = R"({"header":"json"})"_json;
return value.at("header") == "json" ? 0 : 1;
#else
return 0;
#endif
}
6 changes: 6 additions & 0 deletions tests/headers/loads_header_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <vix/json/loads.hpp>

int main()
{
return 0;
}
6 changes: 6 additions & 0 deletions tests/headers/simple_header_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <vix/json/Simple.hpp>

int main()
{
return 0;
}