Commit 4f728d38 authored by Dominik Charousset's avatar Dominik Charousset

Revert default behavior of deep_to_string

parent ff4c3f92
......@@ -274,11 +274,51 @@ struct config_value_access;
CAF_DEFAULT_CONFIG_VALUE_ACCESS(bool, "boolean");
CAF_DEFAULT_CONFIG_VALUE_ACCESS(double, "real64");
CAF_DEFAULT_CONFIG_VALUE_ACCESS(timespan, "timespan");
CAF_DEFAULT_CONFIG_VALUE_ACCESS(uri, "uri");
#undef CAF_DEFAULT_CONFIG_VALUE_ACCESS
template <>
struct CAF_CORE_EXPORT config_value_access<timespan> {
static std::string type_name() {
return "timespan";
}
static bool is(const config_value& x) {
return static_cast<bool>(get_if(&x));
}
static optional<timespan> get_if(const config_value* x) {
auto data_ptr = std::addressof(x->get_data());
if (auto res = caf::get_if<timespan>(data_ptr))
return static_cast<timespan>(*res);
if (auto str = caf::get_if<std::string>(data_ptr)) {
string_view sv{*str};
timespan result;
string_parser_state ps{sv.begin(), sv.end()};
detail::parse(ps, result);
if (ps.code == pec::success)
return result;
}
return none;
}
static timespan get(const config_value& x) {
auto result = get_if(&x);
CAF_ASSERT(result);
return *result;
}
static timespan convert(timespan x) {
return x;
}
template <class Nested>
static void parse_cli(string_parser_state& ps, timespan& x, Nested) {
detail::parse(ps, x);
}
};
template <>
struct CAF_CORE_EXPORT config_value_access<float> {
static std::string type_name() {
......
......@@ -53,7 +53,7 @@ public:
return true;
}
bool always_quote_strings = false;
bool always_quote_strings = true;
// -- serializer interface ---------------------------------------------------
......@@ -236,6 +236,8 @@ private:
void sep();
std::string& result_;
bool in_string_object_ = false;
};
} // namespace caf::detail
......@@ -146,7 +146,6 @@ struct to_string_visitor {
template <class T>
void operator()(const T& x) {
detail::stringification_inspector f{str};
f.always_quote_strings = true;
f.value(x);
}
......
......@@ -51,13 +51,20 @@ namespace caf::detail {
bool stringification_inspector::begin_object(string_view name) {
sep();
result_.insert(result_.end(), name.begin(), name.end());
result_ += '(';
if (name != "std::string") {
result_.insert(result_.end(), name.begin(), name.end());
result_ += '(';
} else {
in_string_object_ = true;
}
return ok;
}
bool stringification_inspector::end_object() {
result_ += ')';
if (!in_string_object_)
result_ += ')';
else
in_string_object_ = false;
return ok;
}
......
......@@ -602,7 +602,6 @@ void logger::log_first_line() {
msg += to_string(system_.node());
msg += ", excluded-components = ";
detail::stringification_inspector f{msg};
f.always_quote_strings = true;
detail::save_value(f, filter);
return msg;
};
......
......@@ -167,16 +167,16 @@ CAF_TEST(profilers record asynchronous messaging) {
sys.spawn(foo);
run();
CAF_CHECK_EQUAL(string_list({
"new: foo",
"new: bar, parent: foo",
"foo sends: message(std::string(\"hello bar\"))",
"bar got: message(std::string(\"hello bar\"))",
"bar sends: message(std::string(\"hello foo\"))",
"bar consumed the message",
"foo got: message(std::string(\"hello foo\"))",
"delete: bar",
"foo consumed the message",
"delete: foo",
R"__(new: foo)__",
R"__(new: bar, parent: foo)__",
R"__(foo sends: message("hello bar"))__",
R"__(bar got: message("hello bar"))__",
R"__(bar sends: message("hello foo"))__",
R"__(bar consumed the message)__",
R"__(foo got: message("hello foo"))__",
R"__(delete: bar)__",
R"__(foo consumed the message)__",
R"__(delete: foo)__",
}),
rec.log);
}
......
......@@ -103,7 +103,7 @@ CAF_TEST(unsharing) {
CAF_TEST(to_string) {
auto x = make_cow_tuple(1, string{"abc"});
CAF_CHECK_EQUAL(deep_to_string(x), "[1, abc]");
CAF_CHECK_EQUAL(deep_to_string(x), R"__([1, "abc"])__");
}
CAF_TEST_FIXTURE_SCOPE(cow_tuple_tests, test_coordinator_fixture<>)
......
......@@ -91,17 +91,17 @@ CAF_TEST(to_string converts messages to strings) {
using svec = vector<string>;
CAF_CHECK_EQUAL(msg_as_string(), "message()");
CAF_CHECK_EQUAL(msg_as_string("hello", "world"),
R"__(message(std::string(hello), std::string(world)))__");
R"__(message("hello", "world"))__");
CAF_CHECK_EQUAL(
msg_as_string(svec{"one", "two", "three"}),
R"__(message(std::vector<std::string>([one, two, three])))__");
R"__(message(std::vector<std::string>(["one", "two", "three"])))__");
CAF_CHECK_EQUAL(
msg_as_string(svec{"one", "two"}, "three", "four",
svec{"five", "six", "seven"}),
"message(std::vector<std::string>([one, two]), std::string(three), "
"std::string(four), std::vector<std::string>([five, six, seven]))");
R"__(message(std::vector<std::string>(["one", "two"]), "three", "four", )__"
R"__(std::vector<std::string>(["five", "six", "seven"])))__");
CAF_CHECK_EQUAL(msg_as_string(R"(this is a "test")"),
"message(std::string(\"this is a \\\"test\\\"\"))");
R"__(message("this is a \"test\""))__");
CAF_CHECK_EQUAL(msg_as_string(make_tuple(1, 2, 3), 4, 5),
"message(std::tuple<int32_t, int32_t, int32_t>([1, 2, 3]), "
"int32_t(4), int32_t(5))");
......
......@@ -141,9 +141,9 @@ CAF_TEST(n_ary_visit) {
variant<float, int, std::string> b{"bar"s};
variant<int, std::string, double> c{123};
test_visitor f;
CAF_CHECK_EQUAL(visit(f, a), "[42]");
CAF_CHECK_EQUAL(visit(f, a, b), "[42, bar]");
CAF_CHECK_EQUAL(visit(f, a, b, c), "[42, bar, 123]");
CAF_CHECK_EQUAL(visit(f, a), R"__([42])__");
CAF_CHECK_EQUAL(visit(f, a, b), R"__([42, "bar"])__");
CAF_CHECK_EQUAL(visit(f, a, b, c), R"__([42, "bar", 123])__");
}
CAF_TEST(get_if) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment