mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-27 11:21:02 +08:00
tests: Improve CharReaderFailIfExtraTest (#1011)
* There was a nonsensical change of 'failIfExtra' before calling strictMode(): the latter resets the former. Dealt with by having one test with pure strictMode and one with strictMode but failIfExtra=false. * The JSONTEST_ASSERT_STRING_EQUAL tests for the error strings swapped the 'expected' and 'actual' values.
This commit is contained in:
parent
2cf939e8c3
commit
b941149a37
@ -2116,22 +2116,34 @@ JSONTEST_FIXTURE(CharReaderFailIfExtraTest, issue164) {
|
|||||||
Json::String errs;
|
Json::String errs;
|
||||||
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
||||||
JSONTEST_ASSERT(!ok);
|
JSONTEST_ASSERT(!ok);
|
||||||
JSONTEST_ASSERT_STRING_EQUAL(errs,
|
JSONTEST_ASSERT_STRING_EQUAL("* Line 1, Column 13\n"
|
||||||
"* Line 1, Column 13\n"
|
" Extra non-whitespace after JSON value.\n",
|
||||||
" Extra non-whitespace after JSON value.\n");
|
errs);
|
||||||
JSONTEST_ASSERT_EQUAL("property", root);
|
JSONTEST_ASSERT_EQUAL("property", root);
|
||||||
delete reader;
|
delete reader;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
b.settings_["failIfExtra"] = false;
|
|
||||||
b.strictMode(&b.settings_);
|
b.strictMode(&b.settings_);
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
Json::String errs;
|
Json::String errs;
|
||||||
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
||||||
JSONTEST_ASSERT(!ok);
|
JSONTEST_ASSERT(!ok);
|
||||||
JSONTEST_ASSERT_STRING_EQUAL(errs,
|
JSONTEST_ASSERT_STRING_EQUAL("* Line 1, Column 13\n"
|
||||||
"* Line 1, Column 13\n"
|
" Extra non-whitespace after JSON value.\n",
|
||||||
" Extra non-whitespace after JSON value.\n");
|
errs);
|
||||||
|
JSONTEST_ASSERT_EQUAL("property", root);
|
||||||
|
delete reader;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
b.strictMode(&b.settings_);
|
||||||
|
b.settings_["failIfExtra"] = false;
|
||||||
|
Json::CharReader* reader(b.newCharReader());
|
||||||
|
Json::String errs;
|
||||||
|
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
||||||
|
JSONTEST_ASSERT(!ok);
|
||||||
|
JSONTEST_ASSERT_STRING_EQUAL("* Line 1, Column 1\n"
|
||||||
|
" A valid JSON document must be either an array or an object value.\n",
|
||||||
|
errs);
|
||||||
JSONTEST_ASSERT_EQUAL("property", root);
|
JSONTEST_ASSERT_EQUAL("property", root);
|
||||||
delete reader;
|
delete reader;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user