Add WideString test for Issue #756

This commit is contained in:
Billy Donahue 2018-05-28 12:45:01 -04:00 committed by Jordan Bayles
parent 101d4797db
commit dd6921f479

View File

@ -14,6 +14,8 @@
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <json/config.h>
#include <json/json.h>
#include <limits>
@ -1644,6 +1646,28 @@ JSONTEST_FIXTURE(ValueTest, StaticString) {
}
}
JSONTEST_FIXTURE(ValueTest, WideString) {
// https://github.com/open-source-parsers/jsoncpp/issues/756
const std::string uni = u8"式,进"; // "\u5f0f\uff0c\u8fdb"
std::string styled;
{
Json::Value v;
v["abc"] = uni;
styled = v.toStyledString();
}
Json::Value root;
{
JSONCPP_STRING errs;
std::istringstream iss(styled);
bool ok = parseFromStream(Json::CharReaderBuilder(), iss, &root, &errs);
JSONTEST_ASSERT(ok);
if (!ok) {
std::cerr << "errs: " << errs << std::endl;
}
}
JSONTEST_ASSERT_STRING_EQUAL(root["abc"].asString(), uni);
}
JSONTEST_FIXTURE(ValueTest, CommentBefore) {
Json::Value val; // fill val
val.setComment(Json::String("// this comment should appear before"),
@ -2556,6 +2580,7 @@ int main(int argc, const char* argv[]) {
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, offsetAccessors);
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, typeChecksThrowExceptions);
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, StaticString);
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, WideString);
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, CommentBefore);
// JSONTEST_REGISTER_FIXTURE(runner, ValueTest, nulls);
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, zeroes);