Fixing noexcept on operator << with simdjson_result. (#1678)

* Additional tests.

* Finishing touch.

* Extending to IO.
This commit is contained in:
Daniel Lemire 2021-07-31 17:54:27 -04:00 committed by GitHub
parent cc98358453
commit 0fa68d8930
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 1 deletions

View File

@ -287,7 +287,7 @@ struct simdjson_result : public internal::simdjson_result_base<T> {
#if SIMDJSON_EXCEPTIONS #if SIMDJSON_EXCEPTIONS
template<typename T> template<typename T>
inline std::ostream& operator<<(std::ostream& out, simdjson_result<T> value) noexcept { return out << value.value(); } inline std::ostream& operator<<(std::ostream& out, simdjson_result<T> value) { return out << value.value(); }
#endif // SIMDJSON_EXCEPTIONS #endif // SIMDJSON_EXCEPTIONS
#ifndef SIMDJSON_DISABLE_DEPRECATED_API #ifndef SIMDJSON_DISABLE_DEPRECATED_API

View File

@ -13,7 +13,49 @@ namespace error_tests {
ASSERT_ERROR( parser.iterate(json), EMPTY ); ASSERT_ERROR( parser.iterate(json), EMPTY );
TEST_SUCCEED(); TEST_SUCCEED();
} }
bool raw_json_string_error() {
TEST_START();
ondemand::parser parser;
auto json = "{\"haha\":{\"df2\":3.5, \"df3\": \"fd\"}}"_padded;
ondemand::document doc;
ASSERT_SUCCESS( parser.iterate(json).get(doc) );
ondemand::raw_json_string rawjson;
ASSERT_ERROR( doc.get_raw_json_string().get(rawjson), INCORRECT_TYPE );
TEST_SUCCEED();
}
#if SIMDJSON_EXCEPTIONS
bool raw_json_string_except() {
TEST_START();
ondemand::parser parser;
auto json = "{\"haha\":{\"df2\":3.5, \"df3\": \"fd\"}}"_padded;
ondemand::document doc;
ASSERT_SUCCESS( parser.iterate(json).get(doc) );
try {
ondemand::raw_json_string rawjson = doc.get_raw_json_string();
(void)rawjson;
TEST_FAIL("Should have thrown an exception!")
} catch(simdjson_error& e) {
ASSERT_ERROR(e.error(), INCORRECT_TYPE);
TEST_SUCCEED();
}
}
bool raw_json_string_except_with_io() {
TEST_START();
ondemand::parser parser;
auto json = "{\"haha\":{\"df2\":3.5, \"df3\": \"fd\"}}"_padded;
ondemand::document doc;
ASSERT_SUCCESS( parser.iterate(json).get(doc) );
try {
auto rawjson = doc.get_raw_json_string();
std::cout << rawjson;
TEST_FAIL("Should have thrown an exception!")
} catch(simdjson_error& e) {
ASSERT_ERROR(e.error(), INCORRECT_TYPE);
TEST_SUCCEED();
}
}
#endif
bool parser_max_capacity() { bool parser_max_capacity() {
TEST_START(); TEST_START();
ondemand::parser parser(1); // max_capacity set to 1 byte ondemand::parser parser(1); // max_capacity set to 1 byte
@ -230,6 +272,11 @@ namespace error_tests {
bool run() { bool run() {
return return
#if SIMDJSON_EXCEPTIONS
raw_json_string_except() &&
raw_json_string_except_with_io() &&
#endif
raw_json_string_error() &&
empty_document_error() && empty_document_error() &&
parser_max_capacity() && parser_max_capacity() &&
get_fail_then_succeed_bool() && get_fail_then_succeed_bool() &&