Commit c1ab48e4 authored by Alexey Spiridonov's avatar Alexey Spiridonov Committed by facebook-github-bot-1

Print null correctly

Summary: Null by itself was printing as 0, now it prints as null, which is consistent with the 'pseudo json' output.

Reviewed By: yfeldblum

Differential Revision: D2789284

fb-gh-sync-id: f318b8d0f8349f4b36f868c419842fb50bee9517
parent b015c8c3
......@@ -728,6 +728,14 @@ struct dynamic::PrintImpl {
out << t;
}
};
// Otherwise, null, being (void*)0, would print as 0.
template <>
struct dynamic::PrintImpl<void*> {
static void print(dynamic const& d, std::ostream& out, void* const& nul) {
DCHECK_EQ((void*)0, nul);
out << "null";
}
};
template<>
struct dynamic::PrintImpl<dynamic::ObjectImpl> {
static void print(dynamic const& d,
......
......@@ -475,6 +475,12 @@ TEST(Dynamic, Brackets) {
EXPECT_NE(ds, md["key1"]);
}
TEST(Dynamic, PrintNull) {
std::stringstream ss;
ss << folly::dynamic(nullptr);
EXPECT_EQ("null", ss.str());
}
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
gflags::ParseCommandLineFlags(&argc, &argv, true);
......
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