mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
Test strings
This commit is contained in:
@@ -215,11 +215,6 @@ simdjson_really_inline simdjson_result<T> simdjson_result<SIMDJSON_IMPLEMENTATIO
|
||||
if (error()) { return error(); }
|
||||
return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(first).get<T>();
|
||||
}
|
||||
template<>
|
||||
simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get<SIMDJSON_IMPLEMENTATION::ondemand::document>() && noexcept {
|
||||
if (error()) { return error(); }
|
||||
return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(first);
|
||||
}
|
||||
template<typename T>
|
||||
simdjson_really_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get(T &out) & noexcept {
|
||||
if (error()) { return error(); }
|
||||
@@ -230,9 +225,17 @@ simdjson_really_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondem
|
||||
if (error()) { return error(); }
|
||||
return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(first).get<T>(out);
|
||||
}
|
||||
template<>
|
||||
simdjson_really_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get<SIMDJSON_IMPLEMENTATION::ondemand::document>(SIMDJSON_IMPLEMENTATION::ondemand::document &out) && noexcept {
|
||||
return std::forward<simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>>(*this).SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::document>::get(out);
|
||||
|
||||
template<> simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get<SIMDJSON_IMPLEMENTATION::ondemand::document>() & noexcept = delete;
|
||||
template<> simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get<SIMDJSON_IMPLEMENTATION::ondemand::document>() && noexcept {
|
||||
if (error()) { return error(); }
|
||||
return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(first);
|
||||
}
|
||||
template<> simdjson_really_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get<SIMDJSON_IMPLEMENTATION::ondemand::document>(SIMDJSON_IMPLEMENTATION::ondemand::document &out) & noexcept = delete;
|
||||
template<> simdjson_really_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get<SIMDJSON_IMPLEMENTATION::ondemand::document>(SIMDJSON_IMPLEMENTATION::ondemand::document &out) && noexcept {
|
||||
if (error()) { return error(); }
|
||||
out = std::forward<SIMDJSON_IMPLEMENTATION::ondemand::document>(first);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
#if SIMDJSON_EXCEPTIONS
|
||||
|
||||
@@ -108,6 +108,7 @@ template<> simdjson_really_inline simdjson_result<uint64_t> value::get() & noexc
|
||||
template<> simdjson_really_inline simdjson_result<int64_t> value::get() & noexcept { return get_int64(); }
|
||||
template<> simdjson_really_inline simdjson_result<bool> value::get() & noexcept { return get_bool(); }
|
||||
|
||||
template<> simdjson_really_inline simdjson_result<value> value::get() && noexcept { return std::forward<value>(*this); }
|
||||
template<> simdjson_really_inline simdjson_result<array> value::get() && noexcept { return std::forward<value>(*this).get_array(); }
|
||||
template<> simdjson_really_inline simdjson_result<object> value::get() && noexcept { return std::forward<value>(*this).get_object(); }
|
||||
template<> simdjson_really_inline simdjson_result<raw_json_string> value::get() && noexcept { return std::forward<value>(*this).get_raw_json_string(); }
|
||||
@@ -310,27 +311,35 @@ simdjson_really_inline bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::v
|
||||
return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>(first).is_null();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
simdjson_really_inline simdjson_result<T> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get() & noexcept {
|
||||
template<typename T> simdjson_really_inline simdjson_result<T> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get() & noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.get<T>();
|
||||
}
|
||||
template<typename T>
|
||||
simdjson_really_inline simdjson_result<T> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get() && noexcept {
|
||||
template<typename T> simdjson_really_inline simdjson_result<T> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get() && noexcept {
|
||||
if (error()) { return error(); }
|
||||
return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>(first).get<T>();
|
||||
}
|
||||
template<typename T>
|
||||
simdjson_really_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get(T &out) & noexcept {
|
||||
template<typename T> simdjson_really_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get(T &out) & noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.get<T>(out);
|
||||
}
|
||||
template<typename T>
|
||||
simdjson_really_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get(T &out) && noexcept {
|
||||
template<typename T> simdjson_really_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get(T &out) && noexcept {
|
||||
if (error()) { return error(); }
|
||||
return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>(first).get<T>(out);
|
||||
}
|
||||
|
||||
template<> simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get<SIMDJSON_IMPLEMENTATION::ondemand::value>() & noexcept = delete;
|
||||
template<> simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get<SIMDJSON_IMPLEMENTATION::ondemand::value>() && noexcept {
|
||||
if (error()) { return error(); }
|
||||
return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>(first);
|
||||
}
|
||||
template<> simdjson_really_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get<SIMDJSON_IMPLEMENTATION::ondemand::value>(SIMDJSON_IMPLEMENTATION::ondemand::value &out) & noexcept = delete;
|
||||
template<> simdjson_really_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get<SIMDJSON_IMPLEMENTATION::ondemand::value>(SIMDJSON_IMPLEMENTATION::ondemand::value &out) && noexcept {
|
||||
if (error()) { return error(); }
|
||||
out = std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>(first);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
#if SIMDJSON_EXCEPTIONS
|
||||
simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator SIMDJSON_IMPLEMENTATION::ondemand::array() noexcept(false) {
|
||||
if (error()) { throw simdjson_error(error()); }
|
||||
|
||||
@@ -342,73 +342,100 @@ namespace dom_api_tests {
|
||||
TEST_SUCCEED();
|
||||
}
|
||||
|
||||
// bool string_value() {
|
||||
// TEST_START();
|
||||
// auto json = R"([ "hi", "has backslash\\" ])"_padded;
|
||||
// ondemand::parser parser;
|
||||
// ondemand::array array;
|
||||
// ASSERT_SUCCESS( parser.iterate(json).get(array) );
|
||||
template<typename T>
|
||||
bool test_scalar_value(const padded_string &json, const T &expected) {
|
||||
SUBTEST( "simdjson_result<document>", test_ondemand_doc(json, [&](auto doc_result) {
|
||||
T actual;
|
||||
ASSERT_SUCCESS( doc_result.get(actual) );
|
||||
ASSERT_EQUAL( expected, actual );
|
||||
return true;
|
||||
}));
|
||||
SUBTEST( "document", test_ondemand_doc(json, [&](auto doc_result) {
|
||||
T actual;
|
||||
ASSERT_SUCCESS( doc_result.get(actual) );
|
||||
ASSERT_EQUAL( expected, actual );
|
||||
return true;
|
||||
}));
|
||||
padded_string array_json = std::string("[") + std::string(json) + "]";
|
||||
SUBTEST( "simdjson_result<ondemand::value>", test_ondemand_doc(array_json, [&](auto doc_result) {
|
||||
int count = 0;
|
||||
for (simdjson_result<ondemand::value> val_result : doc_result) {
|
||||
T actual;
|
||||
ASSERT_SUCCESS( val_result.get(actual) );
|
||||
ASSERT_EQUAL(expected, actual);
|
||||
count++;
|
||||
}
|
||||
ASSERT_EQUAL(count, 1);
|
||||
return true;
|
||||
}));
|
||||
SUBTEST( "ondemand::value", test_ondemand_doc(array_json, [&](auto doc_result) {
|
||||
int count = 0;
|
||||
for (simdjson_result<ondemand::value> val_result : doc_result) {
|
||||
ondemand::value val;
|
||||
ASSERT_SUCCESS( std::move(val_result).get(val) );
|
||||
T actual;
|
||||
ASSERT_SUCCESS( val.get(actual) );
|
||||
ASSERT_EQUAL(expected, actual);
|
||||
count++;
|
||||
}
|
||||
ASSERT_EQUAL(count, 1);
|
||||
return true;
|
||||
}));
|
||||
TEST_SUCCEED();
|
||||
}
|
||||
bool string_value() {
|
||||
TEST_START();
|
||||
return test_scalar_value(R"("hi")"_padded, std::string_view("hi"));
|
||||
}
|
||||
|
||||
// auto iter = array.begin();
|
||||
// std::string_view val;
|
||||
// ASSERT_SUCCESS( (*iter).get(val) );
|
||||
// ASSERT_EQUAL( val, "hi" );
|
||||
// bool numeric_values() {
|
||||
// TEST_START();
|
||||
// auto json = R"([ 0, 1, -1, 1.1 ])"_padded;
|
||||
// ondemand::parser parser;
|
||||
// ondemand::array array;
|
||||
// ASSERT_SUCCESS( parser.iterate(json).get(array) );
|
||||
|
||||
// ++iter;
|
||||
// ASSERT_SUCCESS( (*iter).get(val) );
|
||||
// ASSERT_EQUAL( val, "has backslash\\" );
|
||||
// auto iter = array.begin();
|
||||
// ASSERT_EQUAL( (*iter).get<uint64_t>().first, 0 );
|
||||
// ASSERT_EQUAL( (*iter).get<int64_t>().first, 0 );
|
||||
// ASSERT_EQUAL( (*iter).get<double>().first, 0 );
|
||||
// ++iter;
|
||||
// ASSERT_EQUAL( (*iter).get<uint64_t>().first, 1 );
|
||||
// ASSERT_EQUAL( (*iter).get<int64_t>().first, 1 );
|
||||
// ASSERT_EQUAL( (*iter).get<double>().first, 1 );
|
||||
// ++iter;
|
||||
// ASSERT_EQUAL( (*iter).get<int64_t>().first, -1 );
|
||||
// ASSERT_EQUAL( (*iter).get<double>().first, -1 );
|
||||
// ++iter;
|
||||
// ASSERT_EQUAL( (*iter).get<double>().first, 1.1 );
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// return true;
|
||||
// }
|
||||
// bool boolean_values() {
|
||||
// TEST_START();
|
||||
// auto json = R"([ true, false ])"_padded;
|
||||
// ondemand::parser parser;
|
||||
// ondemand::array array;
|
||||
// ASSERT_SUCCESS( parser.iterate(json).get(array) );
|
||||
|
||||
// bool numeric_values() {
|
||||
// TEST_START();
|
||||
// auto json = R"([ 0, 1, -1, 1.1 ])"_padded;
|
||||
// ondemand::parser parser;
|
||||
// ondemand::array array;
|
||||
// ASSERT_SUCCESS( parser.iterate(json).get(array) );
|
||||
// auto val = array.begin();
|
||||
// ASSERT_EQUAL( (*val).get<bool>().first, true );
|
||||
// ++val;
|
||||
// ASSERT_EQUAL( (*val).get<bool>().first, false );
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// auto iter = array.begin();
|
||||
// ASSERT_EQUAL( (*iter).get<uint64_t>().first, 0 );
|
||||
// ASSERT_EQUAL( (*iter).get<int64_t>().first, 0 );
|
||||
// ASSERT_EQUAL( (*iter).get<double>().first, 0 );
|
||||
// ++iter;
|
||||
// ASSERT_EQUAL( (*iter).get<uint64_t>().first, 1 );
|
||||
// ASSERT_EQUAL( (*iter).get<int64_t>().first, 1 );
|
||||
// ASSERT_EQUAL( (*iter).get<double>().first, 1 );
|
||||
// ++iter;
|
||||
// ASSERT_EQUAL( (*iter).get<int64_t>().first, -1 );
|
||||
// ASSERT_EQUAL( (*iter).get<double>().first, -1 );
|
||||
// ++iter;
|
||||
// ASSERT_EQUAL( (*iter).get<double>().first, 1.1 );
|
||||
// return true;
|
||||
// }
|
||||
// bool null_value() {
|
||||
// TEST_START();
|
||||
// auto json = R"([ null ])"_padded;
|
||||
// ondemand::parser parser;
|
||||
// ondemand::array array;
|
||||
// ASSERT_SUCCESS( parser.iterate(json).get(array) );
|
||||
|
||||
// bool boolean_values() {
|
||||
// TEST_START();
|
||||
// auto json = R"([ true, false ])"_padded;
|
||||
// ondemand::parser parser;
|
||||
// ondemand::array array;
|
||||
// ASSERT_SUCCESS( parser.iterate(json).get(array) );
|
||||
|
||||
// auto val = array.begin();
|
||||
// ASSERT_EQUAL( (*val).get<bool>().first, true );
|
||||
// ++val;
|
||||
// ASSERT_EQUAL( (*val).get<bool>().first, false );
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// bool null_value() {
|
||||
// TEST_START();
|
||||
// auto json = R"([ null ])"_padded;
|
||||
// ondemand::parser parser;
|
||||
// ondemand::array array;
|
||||
// ASSERT_SUCCESS( parser.iterate(json).get(array) );
|
||||
|
||||
// auto val = array.begin();
|
||||
// ASSERT_EQUAL( !(*val).is_null(), 0 );
|
||||
// return true;
|
||||
// }
|
||||
// auto val = array.begin();
|
||||
// ASSERT_EQUAL( !(*val).is_null(), 0 );
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// bool document_object_index() {
|
||||
// TEST_START();
|
||||
@@ -684,7 +711,7 @@ namespace dom_api_tests {
|
||||
iterate_empty_array() &&
|
||||
iterate_object() &&
|
||||
iterate_empty_object() &&
|
||||
// string_value() &&
|
||||
string_value() &&
|
||||
// numeric_values() &&
|
||||
// boolean_values() &&
|
||||
// null_value() &&
|
||||
|
||||
Reference in New Issue
Block a user