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.
This commit is contained in:
ToruNiina
2020-02-06 01:21:04 +09:00
parent f6a41d986c
commit 573a6f1d81

View File

@@ -84,9 +84,7 @@ struct json_serializer
{ {
if(!is_first) {std::cout << ", ";} if(!is_first) {std::cout << ", ";}
is_first = false; is_first = false;
std::cout << toml::format(toml::value(elem.first), std::cout << this->format_key(elem.first) << ':';
std::numeric_limits<std::size_t>::max());
std::cout << ':';
toml::visit(*this, elem.second); toml::visit(*this, elem.second);
} }
std::cout << '}'; std::cout << '}';
@@ -112,6 +110,12 @@ struct json_serializer
} }
return retval; return retval;
} }
std::string format_key(const std::string& s) const
{
const auto quote("\"");
return quote + escape_string(s) + quote;
}
}; };
int main() int main()