diff options
author | Antony Woods <acron1@gmail.com> | 2014-12-10 17:29:31 +0000 |
---|---|---|
committer | Antony Woods <acron1@gmail.com> | 2014-12-10 17:29:31 +0000 |
commit | c2f75a7de1eaa9a0e1a5a97b5fc1ee60c8c3a642 (patch) | |
tree | fed6ff698f211cca192e68d954c577cac9134a97 /tests/unittest.cpp | |
parent | 693aac108de4dc62811b9a2737d895ada474cfb2 (diff) | |
parent | 21b027774e4c472d27d8726774aad1aaed95ea42 (diff) | |
download | crow-c2f75a7de1eaa9a0e1a5a97b5fc1ee60c8c3a642.tar.gz crow-c2f75a7de1eaa9a0e1a5a97b5fc1ee60c8c3a642.zip |
Merged upstream
Diffstat (limited to 'tests/unittest.cpp')
-rw-r--r-- | tests/unittest.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/unittest.cpp b/tests/unittest.cpp index 4dec727..57a4324 100644 --- a/tests/unittest.cpp +++ b/tests/unittest.cpp @@ -453,6 +453,40 @@ TEST(json_read) q = y["ints"][2].i(); ASSERT_EQUAL(3, q); + std::string s2 = R"({"bools":[true, false], "doubles":[1.2, -3.4]})"; + auto z = json::load(s2); + ASSERT_EQUAL(2, z["bools"].size()); + ASSERT_EQUAL(2, z["doubles"].size()); + ASSERT_EQUAL(true, z["bools"][0].b()); + ASSERT_EQUAL(false, z["bools"][1].b()); + ASSERT_EQUAL(1.2, z["doubles"][0].d()); + ASSERT_EQUAL(-3.4, z["doubles"][1].d()); +} + +TEST(json_read_real) +{ + vector<std::string> v{"0.036303908355795146", "0.18320417789757412", + "0.05319940476190476", "0.15224702380952382", "0", "0.3296201145552561", + "0.47921580188679247", "0.05873511904761905", "0.1577827380952381", + "0.4996841307277628", "0.6425412735849056", "0.052113095238095236", + "0.12830357142857143", "0.7871041105121294", "0.954220013477089", + "0.05869047619047619", "0.1625", "0.8144794474393531", + "0.9721613881401617", "0.1399404761904762", "0.24470238095238095", + "0.04527459568733154", "0.2096950808625337", "0.35267857142857145", + "0.42791666666666667", "0.855731974393531", "0.9352467991913747", + "0.3816220238095238", "0.4282886904761905", "0.39414167789757415", + "0.5316079851752021", "0.3809375", "0.4571279761904762", + "0.03522995283018868", "0.1915641846361186", "0.6164136904761904", + "0.7192708333333333", "0.05675117924528302", "0.21308541105121293", + "0.7045386904761904", "0.8016815476190476"}; + for(auto x:v) + { + CROW_LOG_DEBUG << x; + ASSERT_EQUAL(json::load(x).d(), boost::lexical_cast<double>(x)); + } + + auto ret = json::load(R"---({"balloons":[{"mode":"ellipse","left":0.036303908355795146,"right":0.18320417789757412,"top":0.05319940476190476,"bottom":0.15224702380952382,"index":"0"},{"mode":"ellipse","left":0.3296201145552561,"right":0.47921580188679247,"top":0.05873511904761905,"bottom":0.1577827380952381,"index":"1"},{"mode":"ellipse","left":0.4996841307277628,"right":0.6425412735849056,"top":0.052113095238095236,"bottom":0.12830357142857143,"index":"2"},{"mode":"ellipse","left":0.7871041105121294,"right":0.954220013477089,"top":0.05869047619047619,"bottom":0.1625,"index":"3"},{"mode":"ellipse","left":0.8144794474393531,"right":0.9721613881401617,"top":0.1399404761904762,"bottom":0.24470238095238095,"index":"4"},{"mode":"ellipse","left":0.04527459568733154,"right":0.2096950808625337,"top":0.35267857142857145,"bottom":0.42791666666666667,"index":"5"},{"mode":"ellipse","left":0.855731974393531,"right":0.9352467991913747,"top":0.3816220238095238,"bottom":0.4282886904761905,"index":"6"},{"mode":"ellipse","left":0.39414167789757415,"right":0.5316079851752021,"top":0.3809375,"bottom":0.4571279761904762,"index":"7"},{"mode":"ellipse","left":0.03522995283018868,"right":0.1915641846361186,"top":0.6164136904761904,"bottom":0.7192708333333333,"index":"8"},{"mode":"ellipse","left":0.05675117924528302,"right":0.21308541105121293,"top":0.7045386904761904,"bottom":0.8016815476190476,"index":"9"}]})---"); + ASSERT_TRUE(ret); } TEST(json_read_unescaping) |