Add tests for empty object/array

This commit is contained in:
John Keiser 2020-09-28 09:07:17 -07:00
parent 9f1786aeb1
commit c719ccdb48
2 changed files with 33 additions and 32 deletions

View File

@ -45,7 +45,7 @@ namespace ondemand {
simdjson_really_inline object::object(json_iterator_ref &&_iter) noexcept
: iter{std::forward<json_iterator_ref>(_iter)},
at_start{true}
at_start{iter.is_alive()}
{
}

View File

@ -37,7 +37,6 @@ namespace number_tests {
return ua + ub + 0x80000000;
}
bool small_integers() {
std::cout << __func__ << std::endl;
ondemand::parser parser;
@ -278,37 +277,39 @@ namespace dom_api_tests {
return true;
}
// bool object_iterator_empty() {
// std::cout << "Running " << __func__ << std::endl;
// auto json = R"({})"_padded;
// int i = 0;
bool object_iterator_empty() {
std::cout << "Running " << __func__ << std::endl;
auto json = R"({})"_padded;
int i = 0;
// ondemand::parser parser;
// ondemand::object object;
// ASSERT_SUCCESS( parser.iterate(json).get(object) );
// for (SIMDJSON_UNUSED auto field : object) {
// TEST_FAIL("Unexpected field");
// i++;
// }
// ASSERT_EQUAL(i, 0);
// return true;
// }
ondemand::parser parser;
ondemand::object object;
auto doc = parser.iterate(json);
ASSERT_SUCCESS( doc.get(object) );
for (SIMDJSON_UNUSED auto field : object) {
TEST_FAIL("Unexpected field");
i++;
}
ASSERT_EQUAL(i, 0);
return true;
}
// bool array_iterator_empty() {
// std::cout << "Running " << __func__ << std::endl;
// auto json = R"([])"_padded;
// int i=0;
bool array_iterator_empty() {
std::cout << "Running " << __func__ << std::endl;
auto json = R"([])"_padded;
int i=0;
// ondemand::parser parser;
// ondemand::array array;
// ASSERT_SUCCESS( parser.iterate(json).get(array) );
// for (SIMDJSON_UNUSED auto value : array) {
// TEST_FAIL("Unexpected value");
// i++;
// }
// ASSERT_EQUAL(i, 0);
// return true;
// }
ondemand::parser parser;
ondemand::array array;
auto doc = parser.iterate(json);
ASSERT_SUCCESS( doc.get(array) );
for (SIMDJSON_UNUSED auto value : array) {
TEST_FAIL("Unexpected value");
i++;
}
ASSERT_EQUAL(i, 0);
return true;
}
// bool string_value() {
// std::cout << "Running " << __func__ << std::endl;
@ -650,8 +651,8 @@ namespace dom_api_tests {
return
object_iterator() &&
array_iterator() &&
// object_iterator_empty() &&
// array_iterator_empty() &&
object_iterator_empty() &&
array_iterator_empty() &&
// string_value() &&
// numeric_values() &&
// boolean_values() &&