Description
When I write testcases in #1095, I find some problems:
1. comment
I find the comments can be inserted anywhere except the place after the key value of an object. for example:
the input is:
char const doc[] = "//comment1\n [ //comment2\n \"value\" //comment3\n,"
" //comment4\n true //comment5\n ] //comment6\n";
char const doc[] = "//comment1\n { //comment2\n \"property\" :"
" \"value\" //comment3\n } //comment4\n";
after parse the doc, then print root[0], we get:
//comment2
"value" //comment3
Is this an ideal result? we should update the Wiki and tell the user what should be concerned when they add the comments.
2. Value::LargestUInt(Value::maxLargestInt) (9223372036854775807 )
jsoncpp/src/lib_json/json_reader.cpp
Line 1605 in d2e6a97
if (isNegative) {
// We use the same magnitude assumption here, just in case.
const Value::UInt last_digit = static_cast<Value::UInt>(value % 10);
decoded = -Value::LargestInt(value / 10) * 10 - last_digit;
} else if (value <= Value::LargestUInt(Value::maxLargestInt)) {
decoded = Value::LargestInt(value);
} else {
decoded = value;
}
return true;
}
In order to cover this line, we add the testcase:
{
char const doc[] = "[9223372036854775808]";
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
JSONTEST_ASSERT(ok);
JSONTEST_ASSERT(errs.empty());
JSONTEST_ASSERT_EQUAL(9223372036854775808, root[0]);
}
and get the error message:
FAILED: jsoncpp_test@exe/src_test_lib_json_main.cpp.o
c++ -Ijsoncpp_test@exe -I. -I.. -I../include -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -std=c++11 -g -MD -MQ 'jsoncpp_test@exe/src_test_lib_json_main.cpp.o' -MF 'jsoncpp_test@exe/src_test_lib_json_main.cpp.o.d' -o 'jsoncpp_test@exe/src_test_lib_json_main.cpp.o' -c ../src/test_lib_json/main.cpp
../src/test_lib_json/main.cpp:2861:55: warning: integer constant is so large that it is unsigned
JSONTEST_ASSERT_EQUAL(9223372036854775808, root[0]);
^
In file included from ../src/test_lib_json/main.cpp:14:0:
../src/test_lib_json/jsontest.h: In instantiation of ‘JsonTest::TestResult& JsonTest::checkEqual(JsonTest::TestResult&, T, U, const char*, unsigned int, const char*) [with T = __int128; U = Json::Value]’:
../src/test_lib_json/main.cpp:2861:5: required from here
../src/test_lib_json/jsontest.h:178:7: error: call of overloaded ‘Value(__int128&)’ is ambiguous
Is this a bug? How can we remove this error?
3 some redundant code
while (current != end) {
Char c = *current++;
if (c == '"') {
break;
} else if (c == '\\') {
if (current == end)
return addError("Empty escape sequence in string", token, current);
Char escape = *current++;
switch (escape) {
I think we can never get this line:
jsoncpp/src/lib_json/json_reader.cpp
Line 1657 in d2e6a97
and this line:
jsoncpp/src/lib_json/json_reader.cpp
Line 1660 in d2e6a97