From b941149a37e3564ba215fd9ea1232649ec3525b5 Mon Sep 17 00:00:00 2001 From: Frank Richter Date: Mon, 26 Aug 2019 21:36:27 +0200 Subject: [PATCH] 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. --- src/test_lib_json/main.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index d0baa86..c6f2c5c 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -2116,22 +2116,34 @@ JSONTEST_FIXTURE(CharReaderFailIfExtraTest, issue164) { Json::String errs; bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs); JSONTEST_ASSERT(!ok); - JSONTEST_ASSERT_STRING_EQUAL(errs, - "* Line 1, Column 13\n" - " Extra non-whitespace after JSON value.\n"); + JSONTEST_ASSERT_STRING_EQUAL("* Line 1, Column 13\n" + " Extra non-whitespace after JSON value.\n", + errs); JSONTEST_ASSERT_EQUAL("property", root); delete reader; } { - b.settings_["failIfExtra"] = false; b.strictMode(&b.settings_); 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(errs, - "* Line 1, Column 13\n" - " Extra non-whitespace after JSON value.\n"); + JSONTEST_ASSERT_STRING_EQUAL("* Line 1, Column 13\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); delete reader; }