Merge branch 'develop' into feature/fastcov

This commit is contained in:
Niels Lohmann 2019-04-04 09:03:11 +02:00
commit da279234d5
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
56 changed files with 6601 additions and 11902 deletions

View File

@ -32,7 +32,7 @@ To make changes, you need to edit the following files:
1. [`include/nlohmann/*`](https://github.com/nlohmann/json/tree/develop/include/nlohmann) - These files are the sources of the library. Before testing or creating a pull request, execute `make amalgamate` to regenerate `single_include/nlohmann/json.hpp`.
2. [`test/src/unit-*.cpp`](https://github.com/nlohmann/json/tree/develop/test/src) - These files contain the [Catch](https://github.com/philsquared/Catch) unit tests which currently cover [100 %](https://coveralls.io/github/nlohmann/json) of the library's code.
2. [`test/src/unit-*.cpp`](https://github.com/nlohmann/json/tree/develop/test/src) - These files contain the [doctest](https://github.com/onqtam/doctest) unit tests which currently cover [100 %](https://coveralls.io/github/nlohmann/json) of the library's code.
If you add or change a feature, please also add a unit test to this file. The unit tests can be compiled and executed with

View File

@ -76,7 +76,7 @@ check-fast:
coverage:
rm -fr build_coverage
mkdir build_coverage
cd build_coverage ; CXX=g++-7 cmake .. -GNinja -DJSON_Coverage=ON -DJSON_MultipleHeaders=ON
cd build_coverage ; CXX=g++-8 cmake .. -GNinja -DJSON_Coverage=ON -DJSON_MultipleHeaders=ON
cd build_coverage ; ninja
cd build_coverage ; ctest -E '.*_default' -j10
cd build_coverage ; ninja lcov_html
@ -108,7 +108,7 @@ doctest:
# -Wno-c++2a-compat: u8 literals will behave differently in C++20...
# -Wno-deprecated-declarations: the library deprecated some functions
# -Wno-documentation-unknown-command: code uses user-defined commands like @complexity
# -Wno-exit-time-destructors: warning in Catch code
# -Wno-exit-time-destructors: warning in json code triggered by NLOHMANN_JSON_SERIALIZE_ENUM
# -Wno-float-equal: not all comparisons in the tests can be replaced by Approx
# -Wno-keyword-macro: unit-tests use "#define private public"
# -Wno-padded: padding is nothing to warn about
@ -190,7 +190,6 @@ pedantic_gcc:
-Wextra \
-Wextra-semi \
-Wfloat-conversion \
-Wfloat-equal \
-Wformat \
-Wformat-contains-nul \
-Wformat-extra-args \
@ -240,6 +239,7 @@ pedantic_gcc:
-Wmultistatement-macros \
-Wnarrowing \
-Wno-deprecated-declarations \
-Wno-float-equal \
-Wno-long-long \
-Wno-namespaces \
-Wno-padded \

View File

@ -1270,13 +1270,13 @@ The library itself consists of a single header file licensed under the MIT licen
- [**American fuzzy lop**](http://lcamtuf.coredump.cx/afl/) for fuzz testing
- [**AppVeyor**](https://www.appveyor.com) for [continuous integration](https://ci.appveyor.com/project/nlohmann/json) on Windows
- [**Artistic Style**](http://astyle.sourceforge.net) for automatic source code identation
- [**Catch**](https://github.com/philsquared/Catch) for the unit tests
- [**Clang**](http://clang.llvm.org) for compilation with code sanitizers
- [**CMake**](https://cmake.org) for build automation
- [**Codacity**](https://www.codacy.com) for further [code analysis](https://www.codacy.com/app/nlohmann/json)
- [**Coveralls**](https://coveralls.io) to measure [code coverage](https://coveralls.io/github/nlohmann/json)
- [**Coverity Scan**](https://scan.coverity.com) for [static analysis](https://scan.coverity.com/projects/nlohmann-json)
- [**cppcheck**](http://cppcheck.sourceforge.net) for static analysis
- [**doctest**](https://github.com/onqtam/doctest) for the unit tests
- [**Doozer**](https://doozer.io) for [continuous integration](https://doozer.io/nlohmann/json) on Linux (CentOS, Raspbian, Fedora)
- [**Doxygen**](http://www.stack.nl/~dimitri/doxygen/) to generate [documentation](https://nlohmann.github.io/json/)
- [**git-update-ghpages**](https://github.com/rstacruz/git-update-ghpages) to upload the documentation to gh-pages

View File

@ -136,6 +136,7 @@ void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l)
{
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
}
l.clear();
std::transform(j.rbegin(), j.rend(),
std::front_inserter(l), [](const BasicJsonType & i)
{
@ -156,6 +157,16 @@ void from_json(const BasicJsonType& j, std::valarray<T>& l)
std::copy(j.m_value.array->begin(), j.m_value.array->end(), std::begin(l));
}
template <typename BasicJsonType, typename T, std::size_t N>
auto from_json(const BasicJsonType& j, T (&arr)[N])
-> decltype(j.template get<T>(), void())
{
for (std::size_t i = 0; i < N; ++i)
{
arr[i] = j.at(i).template get<T>();
}
}
template<typename BasicJsonType>
void from_json_array_impl(const BasicJsonType& j, typename BasicJsonType::array_t& arr, priority_tag<3> /*unused*/)
{
@ -182,14 +193,16 @@ auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, p
{
using std::end;
arr.reserve(j.size());
ConstructibleArrayType ret;
ret.reserve(j.size());
std::transform(j.begin(), j.end(),
std::inserter(arr, end(arr)), [](const BasicJsonType & i)
std::inserter(ret, end(ret)), [](const BasicJsonType & i)
{
// get<BasicJsonType>() returns *this, this won't call a from_json
// method when value_type is BasicJsonType
return i.template get<typename ConstructibleArrayType::value_type>();
});
arr = std::move(ret);
}
template <typename BasicJsonType, typename ConstructibleArrayType>
@ -198,14 +211,16 @@ void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr,
{
using std::end;
ConstructibleArrayType ret;
std::transform(
j.begin(), j.end(), std::inserter(arr, end(arr)),
j.begin(), j.end(), std::inserter(ret, end(ret)),
[](const BasicJsonType & i)
{
// get<BasicJsonType>() returns *this, this won't call a from_json
// method when value_type is BasicJsonType
return i.template get<typename ConstructibleArrayType::value_type>();
});
arr = std::move(ret);
}
template <typename BasicJsonType, typename ConstructibleArrayType,
@ -239,15 +254,17 @@ void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
JSON_THROW(type_error::create(302, "type must be object, but is " + std::string(j.type_name())));
}
ConstructibleObjectType ret;
auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
using value_type = typename ConstructibleObjectType::value_type;
std::transform(
inner_object->begin(), inner_object->end(),
std::inserter(obj, obj.begin()),
std::inserter(ret, ret.begin()),
[](typename BasicJsonType::object_t::value_type const & p)
{
return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
});
obj = std::move(ret);
}
// overload for arithmetic types, not chosen for basic_json template arguments
@ -319,6 +336,7 @@ void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>&
{
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
}
m.clear();
for (const auto& p : j)
{
if (JSON_UNLIKELY(not p.is_array()))
@ -338,6 +356,7 @@ void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyE
{
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
}
m.clear();
for (const auto& p : j)
{
if (JSON_UNLIKELY(not p.is_array()))

View File

@ -192,10 +192,19 @@ struct is_constructible_object_type_impl <
using object_t = typename BasicJsonType::object_t;
static constexpr bool value =
(std::is_constructible<typename ConstructibleObjectType::key_type, typename object_t::key_type>::value and
std::is_same<typename object_t::mapped_type, typename ConstructibleObjectType::mapped_type>::value) or
(has_from_json<BasicJsonType, typename ConstructibleObjectType::mapped_type>::value or
has_non_default_from_json<BasicJsonType, typename ConstructibleObjectType::mapped_type >::value);
(std::is_default_constructible<ConstructibleObjectType>::value and
(std::is_move_assignable<ConstructibleObjectType>::value or
std::is_copy_assignable<ConstructibleObjectType>::value) and
(std::is_constructible<typename ConstructibleObjectType::key_type,
typename object_t::key_type>::value and
std::is_same <
typename object_t::mapped_type,
typename ConstructibleObjectType::mapped_type >::value)) or
(has_from_json<BasicJsonType,
typename ConstructibleObjectType::mapped_type>::value or
has_non_default_from_json <
BasicJsonType,
typename ConstructibleObjectType::mapped_type >::value);
};
template <typename BasicJsonType, typename ConstructibleObjectType>
@ -278,20 +287,24 @@ struct is_constructible_array_type_impl <
BasicJsonType, ConstructibleArrayType,
enable_if_t<not std::is_same<ConstructibleArrayType,
typename BasicJsonType::value_type>::value and
is_detected<value_type_t, ConstructibleArrayType>::value and
is_detected<iterator_t, ConstructibleArrayType>::value and
is_complete_type<
detected_t<value_type_t, ConstructibleArrayType>>::value >>
std::is_default_constructible<ConstructibleArrayType>::value and
(std::is_move_assignable<ConstructibleArrayType>::value or
std::is_copy_assignable<ConstructibleArrayType>::value) and
is_detected<value_type_t, ConstructibleArrayType>::value and
is_detected<iterator_t, ConstructibleArrayType>::value and
is_complete_type<
detected_t<value_type_t, ConstructibleArrayType>>::value >>
{
static constexpr bool value =
// This is needed because json_reverse_iterator has a ::iterator type,
// furthermore, std::back_insert_iterator (and other iterators) have a base class `iterator`...
// Therefore it is detected as a ConstructibleArrayType.
// The real fix would be to have an Iterable concept.
not is_iterator_traits <
iterator_traits<ConstructibleArrayType >>::value and
// furthermore, std::back_insert_iterator (and other iterators) have a
// base class `iterator`... Therefore it is detected as a
// ConstructibleArrayType. The real fix would be to have an Iterable
// concept.
not is_iterator_traits<iterator_traits<ConstructibleArrayType>>::value and
(std::is_same<typename ConstructibleArrayType::value_type, typename BasicJsonType::array_t::value_type>::value or
(std::is_same<typename ConstructibleArrayType::value_type,
typename BasicJsonType::array_t::value_type>::value or
has_from_json<BasicJsonType,
typename ConstructibleArrayType::value_type>::value or
has_non_default_from_json <

View File

@ -2684,6 +2684,19 @@ class basic_json
return v;
}
template <
typename T, std::size_t N,
typename Array = T (&)[N],
detail::enable_if_t <
detail::has_from_json<basic_json_t, Array>::value, int > = 0 >
Array get_to(T (&v)[N]) const
noexcept(noexcept(JSONSerializer<Array>::from_json(
std::declval<const basic_json_t&>(), v)))
{
JSONSerializer<Array>::from_json(*this, v);
return v;
}
/*!
@brief get a pointer value (implicit)

View File

@ -1059,10 +1059,19 @@ struct is_constructible_object_type_impl <
using object_t = typename BasicJsonType::object_t;
static constexpr bool value =
(std::is_constructible<typename ConstructibleObjectType::key_type, typename object_t::key_type>::value and
std::is_same<typename object_t::mapped_type, typename ConstructibleObjectType::mapped_type>::value) or
(has_from_json<BasicJsonType, typename ConstructibleObjectType::mapped_type>::value or
has_non_default_from_json<BasicJsonType, typename ConstructibleObjectType::mapped_type >::value);
(std::is_default_constructible<ConstructibleObjectType>::value and
(std::is_move_assignable<ConstructibleObjectType>::value or
std::is_copy_assignable<ConstructibleObjectType>::value) and
(std::is_constructible<typename ConstructibleObjectType::key_type,
typename object_t::key_type>::value and
std::is_same <
typename object_t::mapped_type,
typename ConstructibleObjectType::mapped_type >::value)) or
(has_from_json<BasicJsonType,
typename ConstructibleObjectType::mapped_type>::value or
has_non_default_from_json <
BasicJsonType,
typename ConstructibleObjectType::mapped_type >::value);
};
template <typename BasicJsonType, typename ConstructibleObjectType>
@ -1145,20 +1154,24 @@ struct is_constructible_array_type_impl <
BasicJsonType, ConstructibleArrayType,
enable_if_t<not std::is_same<ConstructibleArrayType,
typename BasicJsonType::value_type>::value and
is_detected<value_type_t, ConstructibleArrayType>::value and
is_detected<iterator_t, ConstructibleArrayType>::value and
is_complete_type<
detected_t<value_type_t, ConstructibleArrayType>>::value >>
std::is_default_constructible<ConstructibleArrayType>::value and
(std::is_move_assignable<ConstructibleArrayType>::value or
std::is_copy_assignable<ConstructibleArrayType>::value) and
is_detected<value_type_t, ConstructibleArrayType>::value and
is_detected<iterator_t, ConstructibleArrayType>::value and
is_complete_type<
detected_t<value_type_t, ConstructibleArrayType>>::value >>
{
static constexpr bool value =
// This is needed because json_reverse_iterator has a ::iterator type,
// furthermore, std::back_insert_iterator (and other iterators) have a base class `iterator`...
// Therefore it is detected as a ConstructibleArrayType.
// The real fix would be to have an Iterable concept.
not is_iterator_traits <
iterator_traits<ConstructibleArrayType >>::value and
// furthermore, std::back_insert_iterator (and other iterators) have a
// base class `iterator`... Therefore it is detected as a
// ConstructibleArrayType. The real fix would be to have an Iterable
// concept.
not is_iterator_traits<iterator_traits<ConstructibleArrayType>>::value and
(std::is_same<typename ConstructibleArrayType::value_type, typename BasicJsonType::array_t::value_type>::value or
(std::is_same<typename ConstructibleArrayType::value_type,
typename BasicJsonType::array_t::value_type>::value or
has_from_json<BasicJsonType,
typename ConstructibleArrayType::value_type>::value or
has_non_default_from_json <
@ -1411,6 +1424,7 @@ void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l)
{
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
}
l.clear();
std::transform(j.rbegin(), j.rend(),
std::front_inserter(l), [](const BasicJsonType & i)
{
@ -1431,6 +1445,16 @@ void from_json(const BasicJsonType& j, std::valarray<T>& l)
std::copy(j.m_value.array->begin(), j.m_value.array->end(), std::begin(l));
}
template <typename BasicJsonType, typename T, std::size_t N>
auto from_json(const BasicJsonType& j, T (&arr)[N])
-> decltype(j.template get<T>(), void())
{
for (std::size_t i = 0; i < N; ++i)
{
arr[i] = j.at(i).template get<T>();
}
}
template<typename BasicJsonType>
void from_json_array_impl(const BasicJsonType& j, typename BasicJsonType::array_t& arr, priority_tag<3> /*unused*/)
{
@ -1457,14 +1481,16 @@ auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, p
{
using std::end;
arr.reserve(j.size());
ConstructibleArrayType ret;
ret.reserve(j.size());
std::transform(j.begin(), j.end(),
std::inserter(arr, end(arr)), [](const BasicJsonType & i)
std::inserter(ret, end(ret)), [](const BasicJsonType & i)
{
// get<BasicJsonType>() returns *this, this won't call a from_json
// method when value_type is BasicJsonType
return i.template get<typename ConstructibleArrayType::value_type>();
});
arr = std::move(ret);
}
template <typename BasicJsonType, typename ConstructibleArrayType>
@ -1473,14 +1499,16 @@ void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr,
{
using std::end;
ConstructibleArrayType ret;
std::transform(
j.begin(), j.end(), std::inserter(arr, end(arr)),
j.begin(), j.end(), std::inserter(ret, end(ret)),
[](const BasicJsonType & i)
{
// get<BasicJsonType>() returns *this, this won't call a from_json
// method when value_type is BasicJsonType
return i.template get<typename ConstructibleArrayType::value_type>();
});
arr = std::move(ret);
}
template <typename BasicJsonType, typename ConstructibleArrayType,
@ -1514,15 +1542,17 @@ void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
JSON_THROW(type_error::create(302, "type must be object, but is " + std::string(j.type_name())));
}
ConstructibleObjectType ret;
auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
using value_type = typename ConstructibleObjectType::value_type;
std::transform(
inner_object->begin(), inner_object->end(),
std::inserter(obj, obj.begin()),
std::inserter(ret, ret.begin()),
[](typename BasicJsonType::object_t::value_type const & p)
{
return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
});
obj = std::move(ret);
}
// overload for arithmetic types, not chosen for basic_json template arguments
@ -1594,6 +1624,7 @@ void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>&
{
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
}
m.clear();
for (const auto& p : j)
{
if (JSON_UNLIKELY(not p.is_array()))
@ -1613,6 +1644,7 @@ void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyE
{
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
}
m.clear();
for (const auto& p : j)
{
if (JSON_UNLIKELY(not p.is_array()))
@ -15453,6 +15485,19 @@ class basic_json
return v;
}
template <
typename T, std::size_t N,
typename Array = T (&)[N],
detail::enable_if_t <
detail::has_from_json<basic_json_t, Array>::value, int > = 0 >
Array get_to(T (&v)[N]) const
noexcept(noexcept(JSONSerializer<Array>::from_json(
std::declval<const basic_json_t&>(), v)))
{
JSONSerializer<Array>::from_json(*this, v);
return v;
}
/*!
@brief get a pointer value (implicit)

View File

@ -22,22 +22,22 @@ if(JSON_NoExceptions)
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJSON_NOEXCEPTION")
endif()
set(CATCH_TEST_FILTER -e)
set(DOCTEST_TEST_FILTER --no-throw)
endif()
if(JSON_Coverage)
message(STATUS "Building test suite with coverage information")
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
message(FATAL_ERROR "JSON_Coverage requires GCC.")
endif()
#if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# message(FATAL_ERROR "JSON_Coverage requires GCC.")
#endif()
# enable profiling
set(CMAKE_CXX_FLAGS "--coverage -g -O0 -fprofile-arcs -ftest-coverage")
# from https://github.com/RWTH-HPC/CMake-codecov/blob/master/cmake/FindGcov.cmake
get_filename_component(COMPILER_PATH "${CMAKE_CXX_COMPILER}" PATH)
string(REGEX MATCH "^[0-9]+" GCC_VERSION "${CMAKE_CXX_COMPILER_VERSION}")
find_program(GCOV_BIN NAMES gcov-${GCC_VERSION} gcov HINTS ${COMPILER_PATH})
#get_filename_component(COMPILER_PATH "${CMAKE_CXX_COMPILER}" PATH)
#string(REGEX MATCH "^[0-9]+" GCC_VERSION "${CMAKE_CXX_COMPILER_VERSION}")
#find_program(GCOV_BIN NAMES gcov-${GCC_VERSION} gcov HINTS ${COMPILER_PATH})
# collect all source files from the chosen include dir
file(GLOB_RECURSE SOURCE_FILES ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}*.hpp)
@ -45,7 +45,7 @@ if(JSON_Coverage)
# add target to collect coverage information and generate HTML file
# (filter script from https://stackoverflow.com/a/43726240/266378)
add_custom_target(lcov_html
COMMAND lcov --directory . --capture --output-file json.info --gcov-tool ${GCOV_BIN} --rc lcov_branch_coverage=1
COMMAND lcov --directory . --capture --output-file json.info --rc lcov_branch_coverage=1
COMMAND lcov -e json.info ${SOURCE_FILES} --output-file json.info.filtered --rc lcov_branch_coverage=1
COMMAND ${CMAKE_SOURCE_DIR}/test/thirdparty/imapdl/filterbr.py json.info.filtered > json.info.filtered.noexcept
COMMAND genhtml --title "JSON for Modern C++" --legend --demangle-cpp --output-directory html --show-details --branch-coverage json.info.filtered.noexcept
@ -64,22 +64,22 @@ if(JSON_Coverage)
endif()
#############################################################################
# Catch library with the main function to speed up build
# doctest library with the main function to speed up build
#############################################################################
add_library(catch_main OBJECT
add_library(doctest_main OBJECT
"src/unit.cpp"
)
set_target_properties(catch_main PROPERTIES
set_target_properties(doctest_main PROPERTIES
COMPILE_DEFINITIONS "$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>"
COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>"
)
if (${CMAKE_VERSION} VERSION_LESS "3.8.0")
target_compile_features(catch_main PUBLIC cxx_range_for)
if (${CMAKE_VERSION} VERSION_LESS "3.8.0")
target_compile_features(doctest_main PUBLIC cxx_range_for)
else()
target_compile_features(catch_main PUBLIC cxx_std_11)
target_compile_features(doctest_main PUBLIC cxx_std_11)
endif()
target_include_directories(catch_main PRIVATE "thirdparty/catch")
target_include_directories(doctest_main PRIVATE "thirdparty/doctest")
# https://stackoverflow.com/questions/2368811/how-to-set-warning-level-in-cmake
if(MSVC)
@ -109,10 +109,9 @@ foreach(file ${files})
get_filename_component(file_basename ${file} NAME_WE)
string(REGEX REPLACE "unit-([^$]+)" "test-\\1" testcase ${file_basename})
add_executable(${testcase} $<TARGET_OBJECTS:catch_main> ${file})
add_executable(${testcase} $<TARGET_OBJECTS:doctest_main> ${file})
target_compile_definitions(${testcase} PRIVATE
CATCH_CONFIG_FAST_COMPILE
$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>
DOCTEST_CONFIG_SUPER_FAST_ASSERTS
)
target_compile_options(${testcase} PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>
@ -120,26 +119,26 @@ foreach(file ${files})
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations>
)
target_include_directories(${testcase} PRIVATE
thirdparty/catch
thirdparty/doctest
thirdparty/fifo_map
)
target_link_libraries(${testcase} ${NLOHMANN_JSON_TARGET_NAME})
add_test(NAME "${testcase}_default"
COMMAND ${testcase} ${CATCH_TEST_FILTER}
COMMAND ${testcase} ${DOCTEST_TEST_FILTER}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
set_tests_properties("${testcase}_default" PROPERTIES LABELS "default")
add_test(NAME "${testcase}_all"
COMMAND ${testcase} ${CATCH_TEST_FILTER} "*"
COMMAND ${testcase} ${DOCTEST_TEST_FILTER} --no-skip
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
set_tests_properties("${testcase}_all" PROPERTIES LABELS "all")
if(JSON_Valgrind)
add_test(NAME "${testcase}_valgrind"
COMMAND ${memcheck_command} ${CMAKE_CURRENT_BINARY_DIR}/${testcase} ${CATCH_TEST_FILTER}
COMMAND ${memcheck_command} ${CMAKE_CURRENT_BINARY_DIR}/${testcase} ${DOCTEST_TEST_FILTER}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
set_tests_properties("${testcase}_valgrind" PROPERTIES LABELS "valgrind")

View File

@ -4,7 +4,7 @@
# additional flags
CXXFLAGS += -std=c++11 -Wall -Wextra -pedantic -Wcast-align -Wcast-qual -Wno-ctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-declarations -Wmissing-include-dirs -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch -Wundef -Wno-unused -Wnon-virtual-dtor -Wreorder -Wdeprecated -Wno-float-equal
CPPFLAGS += -I ../single_include -I . -I thirdparty/catch -I thirdparty/fifo_map -DCATCH_CONFIG_FAST_COMPILE
CPPFLAGS += -I ../single_include -I . -I thirdparty/doctest -I thirdparty/fifo_map -DDOCTEST_CONFIG_SUPER_FAST_ASSERTS
SOURCES = src/unit.cpp \
src/unit-algorithms.cpp \
@ -63,11 +63,11 @@ clean:
# single test file
##############################################################################
json_unit: $(OBJECTS) ../single_include/nlohmann/json.hpp thirdparty/catch/catch.hpp
json_unit: $(OBJECTS) ../single_include/nlohmann/json.hpp thirdparty/doctest/doctest.h
@echo "[CXXLD] $@"
@$(CXX) $(CXXFLAGS) $(LDFLAGS) $(OBJECTS) -o $@
%.o: %.cpp ../single_include/nlohmann/json.hpp thirdparty/catch/catch.hpp
%.o: %.cpp ../single_include/nlohmann/json.hpp thirdparty/doctest/doctest.h
@echo "[CXX] $@"
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@
@ -76,7 +76,7 @@ json_unit: $(OBJECTS) ../single_include/nlohmann/json.hpp thirdparty/catch/catch
# individual test cases
##############################################################################
test-%: src/unit-%.o src/unit.o ../single_include/nlohmann/json.hpp thirdparty/catch/catch.hpp
test-%: src/unit-%.o src/unit.o ../single_include/nlohmann/json.hpp thirdparty/doctest/doctest.h
@echo "[CXXLD] $@"
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $< src/unit.o -o $@

View File

@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;

View File

@ -27,14 +27,16 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#define private public
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
namespace
{
// special test case to check if memory is leaked if constructor throws
template<class T>
struct bad_allocator : std::allocator<T>
{
@ -44,6 +46,7 @@ struct bad_allocator : std::allocator<T>
throw std::bad_alloc();
}
};
}
TEST_CASE("bad_alloc")
{
@ -64,6 +67,8 @@ TEST_CASE("bad_alloc")
}
}
namespace
{
static bool next_construct_fails = false;
static bool next_destroy_fails = false;
static bool next_deallocate_fails = false;
@ -129,6 +134,7 @@ void my_allocator_clean_up(T* p)
alloc.destroy(p);
alloc.deallocate(p, 1);
}
}
TEST_CASE("controlled bad_alloc")
{

View File

@ -27,9 +27,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
#include <string>
#include <utility>
@ -38,7 +39,6 @@ SOFTWARE.
class alt_string;
bool operator<(const char* op1, const alt_string& op2);
/*
* This is virtually a string class.
* It covers std::string under the hood.
@ -154,7 +154,6 @@ class alt_string
friend bool ::operator<(const char*, const alt_string&);
};
using alt_json = nlohmann::basic_json <
std::map,
std::vector,
@ -172,8 +171,6 @@ bool operator<(const char* op1, const alt_string& op2)
return op1 < op2.str_impl;
}
TEST_CASE("alternative string type")
{
SECTION("dump")

View File

@ -27,11 +27,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;
#include <fstream>
#include <sstream>
TEST_CASE("BSON")
{
@ -606,6 +608,8 @@ TEST_CASE("BSON input/output_adapters")
}
}
namespace
{
class SaxCountdown
{
public:
@ -675,6 +679,7 @@ class SaxCountdown
private:
int events_left = 0;
};
}
TEST_CASE("Incomplete BSON Input")
{
@ -1138,7 +1143,7 @@ TEST_CASE("BSON numerical data")
};
CHECK_THROWS_AS(json::to_bson(j), json::out_of_range&);
CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.out_of_range.407] integer number " + std::to_string(i) + " cannot be represented by BSON as it does not fit int64");
CHECK_THROWS_WITH_STD_STR(json::to_bson(j), "[json.exception.out_of_range.407] integer number " + std::to_string(i) + " cannot be represented by BSON as it does not fit int64");
}
}
@ -1146,7 +1151,7 @@ TEST_CASE("BSON numerical data")
}
}
TEST_CASE("BSON roundtrips", "[hide]")
TEST_CASE("BSON roundtrips" * doctest::skip())
{
SECTION("reference files")
{
@ -1161,8 +1166,8 @@ TEST_CASE("BSON roundtrips", "[hide]")
{
CAPTURE(filename)
SECTION(filename + ": std::vector<uint8_t>")
{
INFO_WITH_TEMP(filename + ": std::vector<uint8_t>");
// parse JSON file
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
@ -1179,8 +1184,8 @@ TEST_CASE("BSON roundtrips", "[hide]")
CHECK(j1 == j2);
}
SECTION(filename + ": std::ifstream")
{
INFO_WITH_TEMP(filename + ": std::ifstream");
// parse JSON file
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
@ -1194,8 +1199,8 @@ TEST_CASE("BSON roundtrips", "[hide]")
CHECK(j1 == j2);
}
SECTION(filename + ": uint8_t* and size")
{
INFO_WITH_TEMP(filename + ": uint8_t* and size");
// parse JSON file
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
@ -1212,8 +1217,8 @@ TEST_CASE("BSON roundtrips", "[hide]")
CHECK(j1 == j2);
}
SECTION(filename + ": output to output adapters")
{
INFO_WITH_TEMP(filename + ": output to output adapters");
// parse JSON file
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
@ -1224,8 +1229,8 @@ TEST_CASE("BSON roundtrips", "[hide]")
(std::istreambuf_iterator<char>(f_bson)),
std::istreambuf_iterator<char>());
SECTION(filename + ": output adapters: std::vector<uint8_t>")
{
INFO_WITH_TEMP(filename + ": output adapters: std::vector<uint8_t>");
std::vector<uint8_t> vec;
json::to_bson(j1, vec);

View File

@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;

View File

@ -27,13 +27,19 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
#include <nlohmann/json.hpp>
using nlohmann::json;
#include <fstream>
#include <sstream>
#include <iomanip>
#include <set>
namespace
{
class SaxCountdown
{
public:
@ -103,6 +109,7 @@ class SaxCountdown
private:
int events_left = 0;
};
}
TEST_CASE("CBOR")
{
@ -1586,7 +1593,8 @@ TEST_CASE("single CBOR roundtrip")
}
}
TEST_CASE("CBOR regressions", "[!throws]")
#if not defined(JSON_NOEXCEPTION)
TEST_CASE("CBOR regressions")
{
SECTION("fuzz test results")
{
@ -1655,12 +1663,13 @@ TEST_CASE("CBOR regressions", "[!throws]")
}
}
}
#endif
TEST_CASE("CBOR roundtrips", "[hide]")
TEST_CASE("CBOR roundtrips" * doctest::skip())
{
SECTION("input from flynn")
{
// most of these are exluded due to differences in key order (not a real problem)
// most of these are excluded due to differences in key order (not a real problem)
auto exclude_packed = std::set<std::string>
{
"test/data/json.org/1.json",
@ -1827,8 +1836,8 @@ TEST_CASE("CBOR roundtrips", "[hide]")
{
CAPTURE(filename)
SECTION(filename + ": std::vector<uint8_t>")
{
INFO_WITH_TEMP(filename + ": std::vector<uint8_t>");
// parse JSON file
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
@ -1845,8 +1854,8 @@ TEST_CASE("CBOR roundtrips", "[hide]")
CHECK(j1 == j2);
}
SECTION(filename + ": std::ifstream")
{
INFO_WITH_TEMP(filename + ": std::ifstream");
// parse JSON file
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
@ -1860,8 +1869,8 @@ TEST_CASE("CBOR roundtrips", "[hide]")
CHECK(j1 == j2);
}
SECTION(filename + ": uint8_t* and size")
{
INFO_WITH_TEMP(filename + ": uint8_t* and size");
// parse JSON file
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
@ -1878,8 +1887,8 @@ TEST_CASE("CBOR roundtrips", "[hide]")
CHECK(j1 == j2);
}
SECTION(filename + ": output to output adapters")
{
INFO_WITH_TEMP(filename + ": output to output adapters");
// parse JSON file
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
@ -1892,8 +1901,8 @@ TEST_CASE("CBOR roundtrips", "[hide]")
if (!exclude_packed.count(filename))
{
SECTION(filename + ": output adapters: std::vector<uint8_t>")
{
INFO_WITH_TEMP(filename + ": output adapters: std::vector<uint8_t>");
std::vector<uint8_t> vec;
json::to_cbor(j1, vec);
CHECK(vec == packed);
@ -1904,7 +1913,8 @@ TEST_CASE("CBOR roundtrips", "[hide]")
}
}
TEST_CASE("all CBOR first bytes", "[!throws]")
#if not defined(JSON_NOEXCEPTION)
TEST_CASE("all CBOR first bytes")
{
// these bytes will fail immediately with exception parse_error.112
std::set<uint8_t> unsupported =
@ -1968,7 +1978,7 @@ TEST_CASE("all CBOR first bytes", "[!throws]")
{
// check that parse_error.112 is only thrown if the
// first byte is in the unsupported set
CAPTURE(e.what())
INFO_WITH_TEMP(e.what());
if (std::find(unsupported.begin(), unsupported.end(), byte) != unsupported.end())
{
CHECK(e.id == 112);
@ -1980,6 +1990,7 @@ TEST_CASE("all CBOR first bytes", "[!throws]")
}
}
}
#endif
TEST_CASE("examples from RFC 7049 Appendix A")
{

View File

@ -27,11 +27,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#define private public
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
TEST_CASE("const_iterator class")
{

View File

@ -27,11 +27,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#define private public
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
TEST_CASE("iterator class")
{

View File

@ -27,18 +27,22 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#define private public
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
namespace
{
// shortcut to scan a string literal
json::lexer::token_type scan_string(const char* s);
json::lexer::token_type scan_string(const char* s)
{
return json::lexer(nlohmann::detail::input_adapter(s)).scan();
}
}
TEST_CASE("lexer class")
{

View File

@ -27,14 +27,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#define private public
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
#include <valarray>
namespace
{
class SaxEventLogger
{
public:
@ -255,6 +258,7 @@ bool accept_helper(const std::string& s)
// 7. return result
return ok_accept;
}
}
TEST_CASE("parser class")
{
@ -1105,8 +1109,8 @@ TEST_CASE("parser class")
// only check error message if c is not a control character
if (c > 0x1f)
{
CHECK_THROWS_WITH(parser_helper(s.c_str()),
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid string: forbidden character after backslash; last read: '\"\\" + std::string(1, static_cast<char>(c)) + "'");
CHECK_THROWS_WITH_STD_STR(parser_helper(s.c_str()),
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid string: forbidden character after backslash; last read: '\"\\" + std::string(1, static_cast<char>(c)) + "'");
}
break;
}
@ -1181,8 +1185,8 @@ TEST_CASE("parser class")
// only check error message if c is not a control character
if (c > 0x1f)
{
CHECK_THROWS_WITH(parser_helper(s1.c_str()),
"[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s1.substr(0, 7) + "'");
CHECK_THROWS_WITH_STD_STR(parser_helper(s1.c_str()),
"[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s1.substr(0, 7) + "'");
}
CAPTURE(s2)
@ -1190,8 +1194,8 @@ TEST_CASE("parser class")
// only check error message if c is not a control character
if (c > 0x1f)
{
CHECK_THROWS_WITH(parser_helper(s2.c_str()),
"[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s2.substr(0, 6) + "'");
CHECK_THROWS_WITH_STD_STR(parser_helper(s2.c_str()),
"[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s2.substr(0, 6) + "'");
}
CAPTURE(s3)
@ -1199,8 +1203,8 @@ TEST_CASE("parser class")
// only check error message if c is not a control character
if (c > 0x1f)
{
CHECK_THROWS_WITH(parser_helper(s3.c_str()),
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s3.substr(0, 5) + "'");
CHECK_THROWS_WITH_STD_STR(parser_helper(s3.c_str()),
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s3.substr(0, 5) + "'");
}
CAPTURE(s4)
@ -1208,8 +1212,8 @@ TEST_CASE("parser class")
// only check error message if c is not a control character
if (c > 0x1f)
{
CHECK_THROWS_WITH(parser_helper(s4.c_str()),
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s4.substr(0, 4) + "'");
CHECK_THROWS_WITH_STD_STR(parser_helper(s4.c_str()),
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s4.substr(0, 4) + "'");
}
}
}

View File

@ -27,11 +27,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;
namespace
{
// helper function to check std::less<json::value_t>
// see https://en.cppreference.com/w/cpp/utility/functional/less
template <typename A, typename B, typename U = std::less<json::value_t>>
@ -39,6 +41,7 @@ bool f(A a, B b, U u = U())
{
return u(a, b);
}
}
TEST_CASE("lexicographical comparison operators")
{

View File

@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;

View File

@ -27,16 +27,19 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
#define private public
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
#include <deque>
#include <forward_list>
#include <fstream>
#include <list>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <valarray>

View File

@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;

View File

@ -27,12 +27,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#define private public
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
#include <sstream>
namespace
{
void check_escaped(const char* original, const char* escaped = "", const bool ensure_ascii = false);
void check_escaped(const char* original, const char* escaped, const bool ensure_ascii)
{
@ -41,6 +46,7 @@ void check_escaped(const char* original, const char* escaped, const bool ensure_
s.dump_escaped(original, ensure_ascii);
CHECK(ss.str() == escaped);
}
}
TEST_CASE("convenience functions")
{

View File

@ -27,15 +27,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#define private public
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
#include <deque>
#include <forward_list>
#include <list>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
@ -140,6 +142,54 @@ TEST_CASE("value conversion")
}
}
SECTION("get an object (explicit, get_to)")
{
json::object_t o_reference = {{"object", json::object()},
{"array", {1, 2, 3, 4}},
{"number", 42},
{"boolean", false},
{"null", nullptr},
{"string", "Hello world"}
};
json j(o_reference);
SECTION("json::object_t")
{
json::object_t o = {{"previous", "value"}};
j.get_to(o);
CHECK(json(o) == j);
}
SECTION("std::map<json::string_t, json>")
{
std::map<json::string_t, json> o{{"previous", "value"}};
j.get_to(o);
CHECK(json(o) == j);
}
SECTION("std::multimap<json::string_t, json>")
{
std::multimap<json::string_t, json> o{{"previous", "value"}};
j.get_to(o);
CHECK(json(o) == j);
}
SECTION("std::unordered_map<json::string_t, json>")
{
std::unordered_map<json::string_t, json> o{{"previous", "value"}};
j.get_to(o);
CHECK(json(o) == j);
}
SECTION("std::unordered_multimap<json::string_t, json>")
{
std::unordered_multimap<json::string_t, json> o{{"previous", "value"}};
j.get_to(o);
CHECK(json(o) == j);
}
}
SECTION("get an object (implicit)")
{
json::object_t o_reference = {{"object", json::object()},
@ -226,11 +276,6 @@ TEST_CASE("value conversion")
#if not defined(JSON_NOEXCEPTION)
SECTION("reserve is called on containers that supports it")
{
// making the call to from_json throw in order to check capacity
std::vector<float> v;
CHECK_THROWS_AS(nlohmann::from_json(j, v), json::type_error&);
CHECK(v.capacity() == j.size());
// make sure all values are properly copied
std::vector<int> v2 = json({1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
CHECK(v2.size() == 10);
@ -302,6 +347,65 @@ TEST_CASE("value conversion")
}
}
SECTION("get an array (explicit, get_to)")
{
json::array_t a_reference{json(1), json(1u), json(2.2),
json(false), json("string"), json()};
json j(a_reference);
SECTION("json::array_t")
{
json::array_t a{"previous", "value"};
j.get_to(a);
CHECK(json(a) == j);
}
SECTION("std::valarray<json>")
{
std::valarray<json> a{"previous", "value"};
j.get_to(a);
CHECK(json(a) == j);
}
SECTION("std::list<json>")
{
std::list<json> a{"previous", "value"};
j.get_to(a);
CHECK(json(a) == j);
}
SECTION("std::forward_list<json>")
{
std::forward_list<json> a{"previous", "value"};
j.get_to(a);
CHECK(json(a) == j);
}
SECTION("std::vector<json>")
{
std::vector<json> a{"previous", "value"};
j.get_to(a);
CHECK(json(a) == j);
}
SECTION("built-in arrays")
{
const int nbs[] = {0, 1, 2};
int nbs2[] = {0, 0, 0};
json j2 = nbs;
j2.get_to(nbs2);
CHECK(std::equal(std::begin(nbs), std::end(nbs), std::begin(nbs2)));
}
SECTION("std::deque<json>")
{
std::deque<json> a{"previous", "value"};
j.get_to(a);
CHECK(json(a) == j);
}
}
SECTION("get an array (implicit)")
{
json::array_t a_reference{json(1), json(1u), json(2.2),
@ -433,6 +537,35 @@ TEST_CASE("value conversion")
#endif
}
SECTION("get a string (explicit, get_to)")
{
json::string_t s_reference{"Hello world"};
json j(s_reference);
SECTION("string_t")
{
json::string_t s = "previous value";
j.get_to(s);
CHECK(json(s) == j);
}
SECTION("std::string")
{
std::string s = "previous value";
j.get_to(s);
CHECK(json(s) == j);
}
#if defined(JSON_HAS_CPP_17)
SECTION("std::string_view")
{
std::string s = "previous value";
std::string_view sv = s;
j.get_to(sv);
CHECK(json(sv) == j);
}
#endif
}
SECTION("get null (explicit)")
{
std::nullptr_t n = nullptr;
@ -503,13 +636,19 @@ TEST_CASE("value conversion")
CHECK(json(b) == j);
}
SECTION("uint8_t")
{
auto n = j.get<uint8_t>();
CHECK(n == 1);
}
SECTION("bool")
{
bool b = j.get<bool>();
CHECK(json(b) == j);
}
SECTION("exception in case of a non-string type")
SECTION("exception in case of a non-number type")
{
CHECK_THROWS_AS(json(json::value_t::null).get<json::boolean_t>(),
json::type_error&);
@ -519,6 +658,8 @@ TEST_CASE("value conversion")
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::string).get<json::boolean_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::string).get<uint8_t>(),
json::type_error&);
CHECK_THROWS_AS(
json(json::value_t::number_integer).get<json::boolean_t>(),
json::type_error&);

View File

@ -27,14 +27,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;
#include <iostream>
#include <sstream>
#include <valarray>
namespace
{
struct SaxEventLogger : public nlohmann::json_sax<json>
{
bool null() override
@ -166,6 +169,7 @@ struct SaxEventLoggerExitAfterStartArray : public SaxEventLogger
return false;
}
};
}
TEST_CASE("deserialization")
{

View File

@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;

View File

@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;
@ -1072,7 +1072,8 @@ TEST_CASE("element access 2")
}
}
TEST_CASE("element access 2 (throwing tests)", "[!throws]")
#if not defined(JSON_NOEXCEPTION)
TEST_CASE("element access 2 (throwing tests)")
{
SECTION("object")
{
@ -1105,3 +1106,4 @@ TEST_CASE("element access 2 (throwing tests)", "[!throws]")
}
}
}
#endif

View File

@ -27,12 +27,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <fstream>
#include <nlohmann/json.hpp>
using nlohmann::json;
#include <fstream>
#include <sstream>
TEST_CASE("object inspection")
{
SECTION("convenience type checker")

View File

@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;

View File

@ -27,11 +27,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#define private public
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
TEST_CASE("iterators 1")
{

View File

@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;

View File

@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;
@ -342,7 +342,7 @@ TEST_CASE("JSON patch")
// check that evaluation throws
CHECK_THROWS_AS(doc.patch(patch), json::other_error&);
CHECK_THROWS_WITH(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
}
SECTION("A.10. Adding a Nested Member Object")
@ -483,7 +483,7 @@ TEST_CASE("JSON patch")
// check that evaluation throws
CHECK_THROWS_AS(doc.patch(patch), json::other_error&);
CHECK_THROWS_WITH(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
}
SECTION("A.16. Adding an Array Value")
@ -1182,7 +1182,7 @@ TEST_CASE("JSON patch")
// the test will fail
CHECK_THROWS_AS(doc.patch(patch), json::other_error&);
CHECK_THROWS_WITH(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
}
}
}
@ -1268,7 +1268,7 @@ TEST_CASE("JSON patch")
for (const auto& test : suite)
{
CAPTURE(test.value("comment", ""))
INFO_WITH_TEMP(test.value("comment", ""));
// skip tests marked as disabled
if (test.value("disabled", false))

View File

@ -27,11 +27,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#define private public
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
TEST_CASE("JSON pointers")
{

View File

@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;

View File

@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;

View File

@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;

View File

@ -27,13 +27,18 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;
#include <fstream>
#include <sstream>
#include <iomanip>
#include <set>
namespace
{
class SaxCountdown
{
public:
@ -103,6 +108,7 @@ class SaxCountdown
private:
int events_left = 0;
};
}
TEST_CASE("MessagePack")
{
@ -1297,7 +1303,6 @@ TEST_CASE("MessagePack")
}
}
// use this testcase outside [hide] to run it with Valgrind
TEST_CASE("single MessagePack roundtrip")
{
@ -1344,8 +1349,7 @@ TEST_CASE("single MessagePack roundtrip")
}
}
TEST_CASE("MessagePack roundtrips", "[hide]")
TEST_CASE("MessagePack roundtrips" * doctest::skip())
{
SECTION("input from msgpack-python")
{
@ -1519,8 +1523,8 @@ TEST_CASE("MessagePack roundtrips", "[hide]")
{
CAPTURE(filename)
SECTION(filename + ": std::vector<uint8_t>")
{
INFO_WITH_TEMP(filename + ": std::vector<uint8_t>");
// parse JSON file
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
@ -1537,8 +1541,8 @@ TEST_CASE("MessagePack roundtrips", "[hide]")
CHECK(j1 == j2);
}
SECTION(filename + ": std::ifstream")
{
INFO_WITH_TEMP(filename + ": std::ifstream");
// parse JSON file
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
@ -1552,8 +1556,8 @@ TEST_CASE("MessagePack roundtrips", "[hide]")
CHECK(j1 == j2);
}
SECTION(filename + ": uint8_t* and size")
{
INFO_WITH_TEMP(filename + ": uint8_t* and size");
// parse JSON file
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
@ -1570,8 +1574,8 @@ TEST_CASE("MessagePack roundtrips", "[hide]")
CHECK(j1 == j2);
}
SECTION(filename + ": output to output adapters")
{
INFO_WITH_TEMP(filename + ": output to output adapters");
// parse JSON file
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
@ -1584,8 +1588,8 @@ TEST_CASE("MessagePack roundtrips", "[hide]")
if (!exclude_packed.count(filename))
{
SECTION(filename + ": output adapters: std::vector<uint8_t>")
{
INFO_WITH_TEMP(filename + ": output adapters: std::vector<uint8_t>");
std::vector<uint8_t> vec;
json::to_msgpack(j1, vec);
CHECK(vec == packed);

View File

@ -27,11 +27,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;
namespace
{
enum test
{
};
@ -58,6 +61,7 @@ static_assert(noexcept(json(pod{})), "");
static_assert(noexcept(j.get<pod>()), "");
static_assert(not noexcept(j.get<pod_bis>()), "");
static_assert(noexcept(json(pod{})), "");
}
TEST_CASE("runtime checks")
{

View File

@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;

View File

@ -27,7 +27,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
#include <nlohmann/json.hpp>
using nlohmann::json;
@ -35,16 +36,19 @@ using nlohmann::json;
#include <deque>
#include <forward_list>
#include <list>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iostream>
#include <sstream>
#include <iomanip>
#if defined(_MSC_VER)
#pragma warning (push)
#pragma warning (disable : 4189) // local variable is initialized but not referenced
#endif
TEST_CASE("README", "[hide]")
TEST_CASE("README" * doctest::skip())
{
{
// redirect std::cout for the README file

View File

@ -27,7 +27,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
#include <nlohmann/json.hpp>
using nlohmann::json;

View File

@ -27,11 +27,21 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
// for some reason including this after the json header leads to linker errors with VS 2017...
#include <locale>
#define private public
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
#include <fstream>
#include <sstream>
#include <list>
#include <cstdio>
#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
#define JSON_HAS_CPP_17
@ -43,10 +53,6 @@ using nlohmann::json;
#include "fifo_map.hpp"
#include <fstream>
#include <list>
#include <cstdio>
/////////////////////////////////////////////////////////////////////
// for #972
/////////////////////////////////////////////////////////////////////
@ -287,7 +293,7 @@ TEST_CASE("regression tests")
int number = j["Number"];
CHECK(number == 100);
float foo = j["Foo"];
CHECK(foo == Approx(42.42));
CHECK(static_cast<double>(foo) == Approx(42.42));
}
SECTION("issue #89 - nonstandard integer type")
@ -297,8 +303,7 @@ TEST_CASE("regression tests")
nlohmann::basic_json<std::map, std::vector, std::string, bool, int32_t, uint32_t, float>;
custom_json j;
j["int_1"] = 1;
// we need to cast to int to compile with Catch - the value is int32_t
CHECK(static_cast<int>(j["int_1"]) == 1);
CHECK(j["int_1"] == 1);
// tests for correct handling of non-standard integers that overflow the type selected by the user
@ -1780,7 +1785,8 @@ TEST_CASE("regression tests")
}
}
TEST_CASE("regression tests, exceptions dependent", "[!throws]")
#if not defined(JSON_NOEXCEPTION)
TEST_CASE("regression tests, exceptions dependent")
{
SECTION("issue #1340 - eof not set on exhausted input stream")
{
@ -1792,3 +1798,4 @@ TEST_CASE("regression tests, exceptions dependent", "[!throws]")
CHECK(s.eof());
}
}
#endif

View File

@ -27,11 +27,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;
#include <sstream>
#include <iomanip>
TEST_CASE("serialization")
{
SECTION("operator<<")

View File

@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;
@ -418,7 +418,6 @@ TEST_CASE("json.org examples")
json j;
CHECK_NOTHROW(j.parse(f.get()));
}
}
TEST_CASE("RFC 7159 examples")
@ -1352,6 +1351,8 @@ TEST_CASE("nst's JSONTestSuite (2)")
}
}
namespace
{
std::string trim(const std::string& str);
// from http://stackoverflow.com/a/25829178/266378
@ -1365,6 +1366,7 @@ std::string trim(const std::string& str)
size_t last = str.find_last_not_of(' ');
return str.substr(first, (last - first + 1));
}
}
TEST_CASE("Big List of Naughty Strings")
{

View File

@ -31,11 +31,13 @@ SOFTWARE.
// Only compile these tests if 'float' and 'double' are IEEE-754 single- and
// double-precision numbers, resp.
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::detail::dtoa_impl::reinterpret_bits;
namespace
{
static float make_float(uint32_t sign_bit, uint32_t biased_exponent, uint32_t significand)
{
assert(sign_bit == 0 || sign_bit == 1);
@ -139,6 +141,7 @@ static double make_double(uint64_t f, int e)
uint64_t bits = (f & kSignificandMask) | (biased_exponent << kPhysicalSignificandSize);
return reinterpret_bits<double>(bits);
}
}
TEST_CASE("digit gen")
{

View File

@ -27,13 +27,16 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;
#include <fstream>
#include <set>
namespace
{
class SaxCountdown
{
public:
@ -103,6 +106,7 @@ class SaxCountdown
private:
int events_left = 0;
};
}
TEST_CASE("UBJSON")
{
@ -2113,7 +2117,8 @@ TEST_CASE("Universal Binary JSON Specification Examples 1")
}
}
TEST_CASE("all UBJSON first bytes", "[!throws]")
#if not defined(JSON_NOEXCEPTION)
TEST_CASE("all UBJSON first bytes")
{
// these bytes will fail immediately with exception parse_error.112
std::set<uint8_t> supported =
@ -2134,7 +2139,7 @@ TEST_CASE("all UBJSON first bytes", "[!throws]")
{
// check that parse_error.112 is only thrown if the
// first byte is not in the supported set
CAPTURE(e.what())
INFO_WITH_TEMP(e.what());
if (std::find(supported.begin(), supported.end(), byte) == supported.end())
{
CHECK(e.id == 112);
@ -2146,8 +2151,9 @@ TEST_CASE("all UBJSON first bytes", "[!throws]")
}
}
}
#endif
TEST_CASE("UBJSON roundtrips", "[hide]")
TEST_CASE("UBJSON roundtrips" * doctest::skip())
{
SECTION("input from self-generated UBJSON files")
{
@ -2199,8 +2205,8 @@ TEST_CASE("UBJSON roundtrips", "[hide]")
{
CAPTURE(filename)
SECTION(filename + ": std::vector<uint8_t>")
{
INFO_WITH_TEMP(filename + ": std::vector<uint8_t>");
// parse JSON file
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
@ -2217,8 +2223,8 @@ TEST_CASE("UBJSON roundtrips", "[hide]")
CHECK(j1 == j2);
}
SECTION(filename + ": std::ifstream")
{
INFO_WITH_TEMP(filename + ": std::ifstream");
// parse JSON file
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
@ -2232,8 +2238,8 @@ TEST_CASE("UBJSON roundtrips", "[hide]")
CHECK(j1 == j2);
}
SECTION(filename + ": uint8_t* and size")
{
INFO_WITH_TEMP(filename + ": uint8_t* and size");
// parse JSON file
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
@ -2250,8 +2256,8 @@ TEST_CASE("UBJSON roundtrips", "[hide]")
CHECK(j1 == j2);
}
SECTION(filename + ": output to output adapters")
{
INFO_WITH_TEMP(filename + ": output to output adapters");
// parse JSON file
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
@ -2262,8 +2268,8 @@ TEST_CASE("UBJSON roundtrips", "[hide]")
(std::istreambuf_iterator<char>(f_ubjson)),
std::istreambuf_iterator<char>());
SECTION(filename + ": output adapters: std::vector<uint8_t>")
{
INFO_WITH_TEMP(filename + ": output adapters: std::vector<uint8_t>");
std::vector<uint8_t> vec;
json::to_ubjson(j1, vec);
CHECK(vec == packed);

View File

@ -27,10 +27,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;
#include <array>
@ -236,7 +235,7 @@ void from_json(const nlohmann::json& j, contact_book& cb)
}
}
TEST_CASE("basic usage", "[udt]")
TEST_CASE("basic usage" * doctest::test_suite("udt"))
{
// a bit narcissic maybe :) ?
@ -392,7 +391,7 @@ struct adl_serializer<udt::legacy_type>
};
}
TEST_CASE("adl_serializer specialization", "[udt]")
TEST_CASE("adl_serializer specialization" * doctest::test_suite("udt"))
{
SECTION("partial specialization")
{
@ -468,7 +467,7 @@ struct adl_serializer<std::vector<float>>
};
}
TEST_CASE("even supported types can be specialized", "[udt]")
TEST_CASE("even supported types can be specialized" * doctest::test_suite("udt"))
{
json j = std::vector<float> {1.0, 2.0, 3.0};
CHECK(j.dump() == R"("hijacked!")");
@ -509,7 +508,7 @@ struct adl_serializer<std::unique_ptr<T>>
};
}
TEST_CASE("Non-copyable types", "[udt]")
TEST_CASE("Non-copyable types" * doctest::test_suite("udt"))
{
SECTION("to_json")
{
@ -650,7 +649,7 @@ std::ostream& operator<<(std::ostream& os, small_pod l)
}
}
TEST_CASE("custom serializer for pods", "[udt]")
TEST_CASE("custom serializer for pods" * doctest::test_suite("udt"))
{
using custom_json =
nlohmann::basic_json<std::map, std::vector, std::string, bool,
@ -691,7 +690,7 @@ struct another_adl_serializer
}
};
TEST_CASE("custom serializer that does adl by default", "[udt]")
TEST_CASE("custom serializer that does adl by default" * doctest::test_suite("udt"))
{
using json = nlohmann::json;
@ -797,7 +796,7 @@ template <typename T>
struct is_constructible_patched<T, decltype(void(json(std::declval<T>())))> : std::true_type {};
}
TEST_CASE("an incomplete type does not trigger a compiler error in non-evaluated context", "[udt]")
TEST_CASE("an incomplete type does not trigger a compiler error in non-evaluated context" * doctest::test_suite("udt"))
{
static_assert(not is_constructible_patched<json, incomplete>::value, "");
}

View File

@ -27,15 +27,23 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
// for some reason including this after the json header leads to linker errors with VS 2017...
#include <locale>
#define private public
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
#include <fstream>
#include <sstream>
#include <iostream>
#include <iomanip>
namespace
{
extern size_t calls;
size_t calls = 0;
@ -159,8 +167,9 @@ void check_utf8string(bool success_expected, int byte1, int byte2 = -1, int byte
CHECK_THROWS_AS(json::parse(json_string), json::parse_error&);
}
}
}
TEST_CASE("Unicode", "[hide]")
TEST_CASE("Unicode" * doctest::skip())
{
SECTION("RFC 3629")
{
@ -1199,6 +1208,8 @@ TEST_CASE("Unicode", "[hide]")
}
}
namespace
{
void roundtrip(bool success_expected, const std::string& s);
void roundtrip(bool success_expected, const std::string& s)
@ -1238,6 +1249,7 @@ void roundtrip(bool success_expected, const std::string& s)
CHECK_THROWS_AS(json::parse(ps), json::parse_error&);
}
}
}
TEST_CASE("Markus Kuhn's UTF-8 decoder capability and stress test")
{

View File

@ -27,12 +27,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "catch.hpp"
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
using nlohmann::json;
namespace
{
bool wstring_is_utf16();
bool wstring_is_utf16()
{
@ -50,6 +51,7 @@ bool u32string_is_utf32()
{
return (std::u32string(U"💩") == std::u32string(U"\U0001F4A9"));
}
}
TEST_CASE("wide strings")
{

View File

@ -27,5 +27,5 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest_compatibility.h"

View File

@ -1,23 +0,0 @@
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

File diff suppressed because it is too large Load Diff

21
test/thirdparty/doctest/LICENSE.txt vendored Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016-2018 Viktor Kirilov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

6025
test/thirdparty/doctest/doctest.h vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,37 @@
#ifndef DOCTEST_COMPATIBILITY
#define DOCTEST_COMPATIBILITY
#define DOCTEST_CONFIG_VOID_CAST_EXPRESSIONS
#define DOCTEST_THREAD_LOCAL // enable single-threaded builds on XCode 6/7 - https://github.com/onqtam/doctest/issues/172
#include "doctest.h"
// Catch doesn't require a semicolon after CAPTURE but doctest does
#undef CAPTURE
#define CAPTURE(x) DOCTEST_CAPTURE(x);
// Sections from Catch are called Subcases in doctest and don't work with std::string by default
#undef SUBCASE
#define SECTION(x) DOCTEST_SUBCASE(x)
// convenience macro around INFO since it doesn't support temporaries (it is optimized to avoid allocations for runtime speed)
#define INFO_WITH_TEMP_IMPL(x, var_name) const auto var_name = x; INFO(var_name) // lvalue!
#define INFO_WITH_TEMP(x) INFO_WITH_TEMP_IMPL(x, DOCTEST_ANONYMOUS(DOCTEST_STD_STRING_))
// doctest doesn't support THROWS_WITH for std::string out of the box (has to include <string>...)
#define CHECK_THROWS_WITH_STD_STR_IMPL(expr, str, var_name) \
do { \
std::string var_name = str; \
CHECK_THROWS_WITH(expr, var_name.c_str()); \
} while (false)
#define CHECK_THROWS_WITH_STD_STR(expr, str) \
CHECK_THROWS_WITH_STD_STR_IMPL(expr, str, DOCTEST_ANONYMOUS(DOCTEST_STD_STRING_))
// included here because for some tests in the json repository private is defined as
// public and if no STL header is included before that then in the json include when STL
// stuff is included the MSVC STL complains (errors) that C++ keywords are being redefined
#include <iosfwd>
// Catch does this by default
using doctest::Approx;
#endif