From 573a6f1d814dc26fbfa86ea01c354f49faf40abc Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Thu, 6 Feb 2020 01:21:04 +0900 Subject: [PATCH] test: use JSON format_key to format a key in JSON The rule to format a basic string and a key is different. `"""` cannot be used with JSON keys. Also, toml key is basically not wrapped by `"`. So we need a function to format a key in JSON. --- tests/check_toml_test.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/check_toml_test.cpp b/tests/check_toml_test.cpp index ec03124..3fe1660 100644 --- a/tests/check_toml_test.cpp +++ b/tests/check_toml_test.cpp @@ -84,9 +84,7 @@ struct json_serializer { if(!is_first) {std::cout << ", ";} is_first = false; - std::cout << toml::format(toml::value(elem.first), - std::numeric_limits::max()); - std::cout << ':'; + std::cout << this->format_key(elem.first) << ':'; toml::visit(*this, elem.second); } std::cout << '}'; @@ -112,6 +110,12 @@ struct json_serializer } return retval; } + + std::string format_key(const std::string& s) const + { + const auto quote("\""); + return quote + escape_string(s) + quote; + } }; int main()