Skip to content

Commit b941149

Browse files
res2kbaylesj
authored andcommitted
tests: Improve CharReaderFailIfExtraTest (open-source-parsers#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.
1 parent 2cf939e commit b941149

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/test_lib_json/main.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,22 +2116,34 @@ JSONTEST_FIXTURE(CharReaderFailIfExtraTest, issue164) {
21162116
Json::String errs;
21172117
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
21182118
JSONTEST_ASSERT(!ok);
2119-
JSONTEST_ASSERT_STRING_EQUAL(errs,
2120-
"* Line 1, Column 13\n"
2121-
" Extra non-whitespace after JSON value.\n");
2119+
JSONTEST_ASSERT_STRING_EQUAL("* Line 1, Column 13\n"
2120+
" Extra non-whitespace after JSON value.\n",
2121+
errs);
2122+
JSONTEST_ASSERT_EQUAL("property", root);
2123+
delete reader;
2124+
}
2125+
{
2126+
b.strictMode(&b.settings_);
2127+
Json::CharReader* reader(b.newCharReader());
2128+
Json::String errs;
2129+
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
2130+
JSONTEST_ASSERT(!ok);
2131+
JSONTEST_ASSERT_STRING_EQUAL("* Line 1, Column 13\n"
2132+
" Extra non-whitespace after JSON value.\n",
2133+
errs);
21222134
JSONTEST_ASSERT_EQUAL("property", root);
21232135
delete reader;
21242136
}
21252137
{
2126-
b.settings_["failIfExtra"] = false;
21272138
b.strictMode(&b.settings_);
2139+
b.settings_["failIfExtra"] = false;
21282140
Json::CharReader* reader(b.newCharReader());
21292141
Json::String errs;
21302142
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
21312143
JSONTEST_ASSERT(!ok);
2132-
JSONTEST_ASSERT_STRING_EQUAL(errs,
2133-
"* Line 1, Column 13\n"
2134-
" Extra non-whitespace after JSON value.\n");
2144+
JSONTEST_ASSERT_STRING_EQUAL("* Line 1, Column 1\n"
2145+
" A valid JSON document must be either an array or an object value.\n",
2146+
errs);
21352147
JSONTEST_ASSERT_EQUAL("property", root);
21362148
delete reader;
21372149
}

0 commit comments

Comments
 (0)