Commit d290c078 authored by Giuseppe Ottaviano's avatar Giuseppe Ottaviano Committed by Facebook Github Bot

Add gtest helpers for JsonTestUtil

Reviewed By: shixiao

Differential Revision: D8516223

fbshipit-source-id: 0e259ce65183d779f066869091cdea837b7bd237
parent 2e427ec7
......@@ -60,3 +60,13 @@ bool compareDynamicWithTolerance(
double tolerance);
} // namespace folly
/**
* GTest helpers. Note that to use them you'll need to include the
* gtest headers yourself.
*/
#define FOLLY_EXPECT_JSON_EQ(json1, json2) \
EXPECT_PRED2(::folly::compareJson, json1, json2)
#define FOLLY_EXPECT_JSON_NEAR(json1, json2, tolerance) \
EXPECT_PRED3(::folly::compareJsonWithTolerance, json1, json2, tolerance)
......@@ -25,6 +25,7 @@ TEST(CompareJson, Simple) {
constexpr StringPiece json1 = R"({"a": 1, "b": 2})";
constexpr StringPiece json2 = R"({"b": 2, "a": 1})";
EXPECT_TRUE(compareJson(json1, json2));
FOLLY_EXPECT_JSON_EQ(json1, json2);
constexpr StringPiece json3 = R"({"b": 3, "a": 1})";
EXPECT_FALSE(compareJson(json1, json3));
......@@ -66,4 +67,7 @@ TEST(CompareJsonWithTolerance, Simple) {
EXPECT_TRUE(compare(R"("hello")", R"("hello")"));
EXPECT_FALSE(compare(R"("hello")", R"("world")"));
FOLLY_EXPECT_JSON_NEAR(
R"({"a": 1, "b": 2})", R"({"b": 2.01, "a": 1.05})", 0.1);
}
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