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