Skip to content

Removed unneeded newlines from parsed comments #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/jsontestrunner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ static std::string readInputTestFile(const char* path) {

static void
printValueTree(FILE* fout, Json::Value& value, const std::string& path = ".") {
if (value.hasComment(Json::commentBefore)) {
fprintf(fout, "%s\n", value.getComment(Json::commentBefore).c_str());
}
switch (value.type()) {
case Json::nullValue:
fprintf(fout, "%s=null\n", path.c_str());
Expand Down Expand Up @@ -117,6 +120,10 @@ printValueTree(FILE* fout, Json::Value& value, const std::string& path = ".") {
default:
break;
}

if (value.hasComment(Json::commentAfter)) {
fprintf(fout, "%s\n", value.getComment(Json::commentAfter).c_str());
}
}

static int parseAndSaveValueTree(const std::string& input,
Expand Down
2 changes: 0 additions & 2 deletions src/lib_json/json_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,6 @@ Reader::addComment(Location begin, Location end, CommentPlacement placement) {
assert(lastValue_ != 0);
lastValue_->setComment(std::string(begin, end), placement);
} else {
if (!commentsBefore_.empty())
commentsBefore_ += "\n";
commentsBefore_ += std::string(begin, end);
}
}
Expand Down
1 change: 1 addition & 0 deletions test/data/test_basic_08.expected
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// C++ style comment
.=null

2 changes: 2 additions & 0 deletions test/data/test_basic_09.expected
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/* C style comment
*/
.=null

7 changes: 7 additions & 0 deletions test/data/test_comment_02.expected
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
.={}
/* C-style comment

C-style-2 comment */
.c-test={}
.c-test.a=1
/* Internal comment c-style */
.c-test.b=2
// C++-style comment
.cpp-test={}
// Multiline comment cpp-style
// Second line
.cpp-test.c=3
.cpp-test.d=4
3 changes: 2 additions & 1 deletion test/data/test_comment_02.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
// C++-style comment
"cpp-test" : {
// Internal comment cpp-style
// Multiline comment cpp-style
// Second line
"c" : 3,
"d" : 4
}
Expand Down
1 change: 1 addition & 0 deletions test/data/test_integer_01.expected
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// Max signed integer
.=2147483647
1 change: 1 addition & 0 deletions test/data/test_integer_02.expected
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// Min signed integer
.=-2147483648
1 change: 1 addition & 0 deletions test/data/test_integer_03.expected
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// Max unsigned integer
.=4294967295
1 change: 1 addition & 0 deletions test/data/test_integer_04.expected
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// Min unsigned integer
.=0

8 changes: 8 additions & 0 deletions test/data/test_preserve_comment_01.expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/* A comment
at the beginning of the file.
*/
.={}
.first=1
/* Comment before 'second'
*/
.second=2
/* A comment at
the end of the file.
*/
1 change: 1 addition & 0 deletions test/data/test_real_01.expected
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// 2^33 => out of integer range, switch to double
.=8589934592

1 change: 1 addition & 0 deletions test/data/test_real_02.expected
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// -2^32 => out of signed integer range, switch to double
.=-4294967295

1 change: 1 addition & 0 deletions test/data/test_real_03.expected
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// -2^32 => out of signed integer range, switch to double
.=-4294967295

1 change: 1 addition & 0 deletions test/data/test_real_04.expected
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// 1.2345678
.=1.2345678

1 change: 1 addition & 0 deletions test/data/test_real_05.expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// 1234567.8
.=1234567.8


1 change: 1 addition & 0 deletions test/data/test_real_06.expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// -1.2345678
.=-1.2345678


1 change: 1 addition & 0 deletions test/data/test_real_07.expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// -1234567.8
.=-1234567.8


3 changes: 3 additions & 0 deletions test/data/test_real_08.expected
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
// Out of 32-bit integer range, switch to double in 32-bit mode. Length the
// same as UINT_MAX in base 10 and digit less than UINT_MAX's last digit in
// order to catch a bug in the parsing code.
.=4300000001
3 changes: 3 additions & 0 deletions test/data/test_real_09.expected
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
// Out of 64-bit integer range, switch to double in all modes. Length the same
// as ULONG_MAX in base 10 and digit less than ULONG_MAX's last digit in order
// to catch a bug in the parsing code.
.=1.9e+19
3 changes: 3 additions & 0 deletions test/data/test_real_10.expected
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
// Out of 32-bit signed integer range, switch to double in all modes. Length
// the same as INT_MIN in base 10 and digit less than INT_MIN's last digit in
// order to catch a bug in the parsing code.
.=-2200000001
3 changes: 3 additions & 0 deletions test/data/test_real_11.expected
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
// Out of 64-bit signed integer range, switch to double in all modes. Length
// the same as LONG_MIN in base 10 and digit less than LONG_MIN's last digit in
// order to catch a bug in the parsing code.
.=-9.3e+18
1 change: 1 addition & 0 deletions test/data/test_real_12.expected
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// 2^64 -> switch to double.
.=1.844674407370955e+19