Skip to content

Commit 4994c77

Browse files
ycqiucdunn2001
authored andcommitted
add test code
does not compile
1 parent beae999 commit 4994c77

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Diff for: src/test_lib_json/main.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
#include <json/json.h>
99
#include <cstring>
1010
#include <limits>
11+
#include <sstream>
12+
#include <string>
13+
#include <iostream>
14+
#include <iomanip>
1115

1216
// Make numeric limits more convenient to talk about.
1317
// Assumes int type in 32 bits.
@@ -2430,6 +2434,31 @@ JSONTEST_FIXTURE(IteratorTest, indexes) {
24302434
JSONTEST_ASSERT(it == json.end());
24312435
}
24322436

2437+
JSONTEST_FIXTURE(IteratorTest, const) {
2438+
Json::Value const v;
2439+
Json::Value::iterator it = v.begin(); // This *should not* compile, but does.
2440+
2441+
Json::Value value;
2442+
2443+
for(int i = 9; i < 12; ++i)
2444+
{
2445+
std::ostringstream out;
2446+
out << std::setw(2) << i;
2447+
std::string str = out.str();
2448+
value[str] = str;
2449+
}
2450+
2451+
std::ostringstream out;
2452+
//in old code, this will get a compile error
2453+
Json::Value::const_iterator iter = value.begin();
2454+
for(; iter != value.end(); ++iter)
2455+
{
2456+
out << *iter << ',';
2457+
}
2458+
std::string expected = "\" 9\",\"10\",\"11\",";
2459+
JSONTEST_ASSERT_STRING_EQUAL(expected, out.str());
2460+
}
2461+
24332462
int main(int argc, const char* argv[]) {
24342463
JsonTest::Runner runner;
24352464
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, checkNormalizeFloatingPointStr);
@@ -2500,6 +2529,7 @@ int main(int argc, const char* argv[]) {
25002529
JSONTEST_REGISTER_FIXTURE(runner, IteratorTest, distance);
25012530
JSONTEST_REGISTER_FIXTURE(runner, IteratorTest, names);
25022531
JSONTEST_REGISTER_FIXTURE(runner, IteratorTest, indexes);
2532+
JSONTEST_REGISTER_FIXTURE(runner, IteratorTest, const);
25032533

25042534
return runner.runCommandLine(argc, argv);
25052535
}

0 commit comments

Comments
 (0)