Improve performance of JSON rendering (#6380)
This commit is contained in:
committed by
GitHub
parent
41fd947ebd
commit
9a4b4648f4
@@ -0,0 +1,30 @@
|
||||
#include "util/json_container.hpp"
|
||||
#include "util/json_renderer.hpp"
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(json_renderer)
|
||||
|
||||
using namespace osrm::util::json;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(number_truncating)
|
||||
{
|
||||
std::string str;
|
||||
Renderer<std::string> renderer(str);
|
||||
|
||||
// this number would have more than 10 decimals if not truncated
|
||||
renderer(Number{42.9995999594999399299});
|
||||
BOOST_CHECK_EQUAL(str, "42.999599959");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(integer)
|
||||
{
|
||||
std::string str;
|
||||
Renderer<std::string> renderer(str);
|
||||
renderer(Number{42.0});
|
||||
BOOST_CHECK_EQUAL(str, "42");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -12,13 +12,19 @@ using namespace osrm::util;
|
||||
BOOST_AUTO_TEST_CASE(json_escaping)
|
||||
{
|
||||
std::string input{"\b\\"};
|
||||
std::string output{escape_JSON(input)};
|
||||
std::string output;
|
||||
EscapeJSONString(input, output);
|
||||
|
||||
BOOST_CHECK(RequiresJSONStringEscaping(input));
|
||||
BOOST_CHECK_EQUAL(output, "\\b\\\\");
|
||||
|
||||
input = "Aleja \"Solidarnosci\"";
|
||||
output = escape_JSON(input);
|
||||
output.clear();
|
||||
EscapeJSONString(input, output);
|
||||
BOOST_CHECK(RequiresJSONStringEscaping(input));
|
||||
BOOST_CHECK_EQUAL(output, "Aleja \\\"Solidarnosci\\\"");
|
||||
|
||||
BOOST_CHECK(!RequiresJSONStringEscaping("Aleja Solidarnosci"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(print_int)
|
||||
|
||||
Reference in New Issue
Block a user