mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-10-15 15:16:47 +02:00
CharReader: Add StructuredError (#1409)
* CharReader: Add Structured Error Add getStructuredError to CharReader * run clang format --------- Co-authored-by: Jordan Bayles <bayles.jordan@gmail.com> Co-authored-by: Jordan Bayles <jophba@chromium.org>
This commit is contained in:
@@ -3917,6 +3917,36 @@ JSONTEST_FIXTURE_LOCAL(FuzzTest, fuzzDoesntCrash) {
|
||||
example.size()));
|
||||
}
|
||||
|
||||
struct ParseWithStructuredErrorsTest : JsonTest::TestCase {
|
||||
void testErrors(
|
||||
const std::string& doc, bool success,
|
||||
const std::vector<Json::CharReader::StructuredError>& expectedErrors) {
|
||||
Json::CharReaderBuilder b;
|
||||
CharReaderPtr reader(b.newCharReader());
|
||||
Json::Value root;
|
||||
JSONTEST_ASSERT_EQUAL(
|
||||
reader->parse(doc.data(), doc.data() + doc.length(), &root, nullptr),
|
||||
success);
|
||||
auto actualErrors = reader->getStructuredErrors();
|
||||
JSONTEST_ASSERT_EQUAL(expectedErrors.size(), actualErrors.size());
|
||||
for (std::size_t i = 0; i < actualErrors.size(); i++) {
|
||||
const auto& a = actualErrors[i];
|
||||
const auto& e = expectedErrors[i];
|
||||
JSONTEST_ASSERT_EQUAL(a.offset_start, e.offset_start);
|
||||
JSONTEST_ASSERT_EQUAL(a.offset_limit, e.offset_limit);
|
||||
JSONTEST_ASSERT_STRING_EQUAL(a.message, e.message);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
JSONTEST_FIXTURE_LOCAL(ParseWithStructuredErrorsTest, success) {
|
||||
testErrors("{}", true, {});
|
||||
}
|
||||
|
||||
JSONTEST_FIXTURE_LOCAL(ParseWithStructuredErrorsTest, singleError) {
|
||||
testErrors("{ 1 : 2 }", false, {{2, 3, "Missing '}' or object member name"}});
|
||||
}
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
JsonTest::Runner runner;
|
||||
|
||||
|
Reference in New Issue
Block a user