Commit d3f8fa39 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

No need to load test files at runtime in json test

Summary: [Folly] No need to load test files at runtime in json test - just embed the content into the test source as usual.

Reviewed By: vitaut

Differential Revision: D17578929

fbshipit-source-id: 65b0bb7fe94f03b3defa9c539c2837c341e042c3
parent 2aa07752
......@@ -18,7 +18,6 @@
#include <folly/Benchmark.h>
#include <folly/Conv.h>
#include <folly/FileUtil.h>
#include <folly/Range.h>
#include <folly/portability/GFlags.h>
#include <folly/portability/GTest.h>
......@@ -62,20 +61,30 @@ constexpr folly::StringPiece kLargeAsciiStringWithSpecialChars =
"<script>foo%@bar.com</script>";
TEST(Json, StripComments) {
const std::string kTestDir = "folly/test/";
const std::string kTestFile = "json_test_data/commented.json";
const std::string kTestExpected = "json_test_data/commented.json.exp";
std::string testStr;
std::string expectedStr;
if (!folly::readFile(kTestFile.data(), testStr) &&
!folly::readFile((kTestDir + kTestFile).data(), testStr)) {
FAIL() << "can not read test file " << kTestFile;
}
if (!folly::readFile(kTestExpected.data(), expectedStr) &&
!folly::readFile((kTestDir + kTestExpected).data(), expectedStr)) {
FAIL() << "can not read test file " << kTestExpected;
}
auto testStr = folly::stripLeftMargin(R"JSON(
{
// comment
"test": "foo", // comment
"test2": "foo // bar", // more comments
/*
"test3": "baz"
*/
"test4": "foo /* bar", /* comment */
"te//": "foo",
"te/*": "bar",
"\\\"": "\\" /* comment */
}
)JSON");
auto expectedStr = folly::stripLeftMargin(R"JSON(
{
"test": "foo", "test2": "foo // bar",
"test4": "foo /* bar",
"te//": "foo",
"te/*": "bar",
"\\\"": "\\"
}
)JSON");
EXPECT_EQ(expectedStr, folly::json::stripComments(testStr));
}
......
{
// comment
"test": "foo", // comment
"test2": "foo // bar", // more comments
/*
"test3": "baz"
*/
"test4": "foo /* bar", /* comment */
"te//": "foo",
"te/*": "bar",
"\\\"": "\\" /* comment */
}
{
"test": "foo", "test2": "foo // bar",
"test4": "foo /* bar",
"te//": "foo",
"te/*": "bar",
"\\\"": "\\"
}
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