aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorErik Åldstedt Sund <erik.sund@conoptica.com>2017-10-22 13:31:17 +0200
committerErik Åldstedt Sund <erik.sund@conoptica.com>2017-10-30 20:47:48 +0100
commit4fe7dd171a77747f1b14654acd369381d6eb3f17 (patch)
tree269230272e206ed522814323e45c3a102156dfe6 /tests
parent7f3f72441c242836d00ab2109a83baef89c08aaa (diff)
downloadcrow-4fe7dd171a77747f1b14654acd369381d6eb3f17.tar.gz
crow-4fe7dd171a77747f1b14654acd369381d6eb3f17.zip
Handle big integers in json::wvalue
Handled by adding an enum num_type in both rvalue and wvalue (to separate between signed/unsigned ints, and floating point values) and a union for the number value in wvalue.
Diffstat (limited to 'tests')
-rw-r--r--tests/unittest.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/unittest.cpp b/tests/unittest.cpp
index bffdd60..d7f1c80 100644
--- a/tests/unittest.cpp
+++ b/tests/unittest.cpp
@@ -501,7 +501,7 @@ TEST(json_read)
//ASSERT_THROW(3 == x["message"]);
ASSERT_EQUAL(12, x["message"].size());
- std::string s = R"({"int":3, "ints" :[1,2,3,4,5] })";
+ std::string s = R"({"int":3, "ints" :[1,2,3,4,5], "bigint":1234567890 })";
auto y = json::load(s);
ASSERT_EQUAL(3, y["int"]);
ASSERT_EQUAL(3.0, y["int"]);
@@ -519,6 +519,7 @@ TEST(json_read)
ASSERT_EQUAL(2, q);
q = y["ints"][2].i();
ASSERT_EQUAL(3, q);
+ ASSERT_EQUAL(1234567890, y["bigint"]);
std::string s2 = R"({"bools":[true, false], "doubles":[1.2, -3.4]})";
auto z = json::load(s2);
@@ -596,6 +597,8 @@ TEST(json_write)
ASSERT_TRUE(R"({"message":{"x":3,"y":5}})" == json::dump(x) || R"({"message":{"y":5,"x":3}})" == json::dump(x));
x["message"] = 5.5;
ASSERT_EQUAL(R"({"message":5.5})", json::dump(x));
+ x["message"] = 1234567890;
+ ASSERT_EQUAL(R"({"message":1234567890})", json::dump(x));
json::wvalue y;
y["scores"][0] = 1;
@@ -616,6 +619,30 @@ TEST(json_write)
}
+TEST(json_copy_r_to_w_to_r)
+{
+ json::rvalue r = json::load(R"({"smallint":2,"bigint":2147483647,"fp":23.43,"fpsc":2.343e1,"str":"a string","trueval":true,"falseval":false,"nullval":null,"listval":[1,2,"foo","bar"],"obj":{"member":23,"other":"baz"}})");
+ json::wvalue w{r};
+ json::rvalue x = json::load(json::dump(w)); // why no copy-ctor wvalue -> rvalue?
+ ASSERT_EQUAL(2, x["smallint"]);
+ ASSERT_EQUAL(2147483647, x["bigint"]);
+ ASSERT_EQUAL(23.43, x["fp"]);
+ ASSERT_EQUAL(23.43, x["fpsc"]);
+ ASSERT_EQUAL("a string", x["str"]);
+ ASSERT_TRUE(true == x["trueval"].b());
+ ASSERT_TRUE(false == x["falseval"].b());
+ ASSERT_TRUE(json::type::Null == x["nullval"].t());
+ ASSERT_EQUAL(4u, x["listval"].size());
+ ASSERT_EQUAL(1, x["listval"][0]);
+ ASSERT_EQUAL(2, x["listval"][1]);
+ ASSERT_EQUAL("foo", x["listval"][2]);
+ ASSERT_EQUAL("bar", x["listval"][3]);
+ ASSERT_EQUAL(23, x["obj"]["member"]);
+ ASSERT_EQUAL("member", x["obj"]["member"].key());
+ ASSERT_EQUAL("baz", x["obj"]["other"]);
+ ASSERT_EQUAL("other", x["obj"]["other"].key());
+}
+
TEST(template_basic)
{
auto t = crow::mustache::compile(R"---(attack of {{name}})---");