Skip to content

Commit bc8b5d8

Browse files
committed
Merge pull request #52 from cquammen/master
Removed unneeded newlines from parsed comments
2 parents aa650c5 + fd06bfc commit bc8b5d8

23 files changed

+51
-3
lines changed

src/jsontestrunner/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ static std::string readInputTestFile(const char* path) {
6161

6262
static void
6363
printValueTree(FILE* fout, Json::Value& value, const std::string& path = ".") {
64+
if (value.hasComment(Json::commentBefore)) {
65+
fprintf(fout, "%s\n", value.getComment(Json::commentBefore).c_str());
66+
}
6467
switch (value.type()) {
6568
case Json::nullValue:
6669
fprintf(fout, "%s=null\n", path.c_str());
@@ -117,6 +120,10 @@ printValueTree(FILE* fout, Json::Value& value, const std::string& path = ".") {
117120
default:
118121
break;
119122
}
123+
124+
if (value.hasComment(Json::commentAfter)) {
125+
fprintf(fout, "%s\n", value.getComment(Json::commentAfter).c_str());
126+
}
120127
}
121128

122129
static int parseAndSaveValueTree(const std::string& input,

src/lib_json/json_reader.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,6 @@ Reader::addComment(Location begin, Location end, CommentPlacement placement) {
358358
assert(lastValue_ != 0);
359359
lastValue_->setComment(std::string(begin, end), placement);
360360
} else {
361-
if (!commentsBefore_.empty())
362-
commentsBefore_ += "\n";
363361
commentsBefore_ += std::string(begin, end);
364362
}
365363
}

test/data/test_basic_08.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
// C++ style comment
12
.=null
23

test/data/test_basic_09.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
/* C style comment
2+
*/
13
.=null
24

test/data/test_comment_02.expected

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
.={}
2+
/* C-style comment
3+
4+
C-style-2 comment */
25
.c-test={}
36
.c-test.a=1
7+
/* Internal comment c-style */
48
.c-test.b=2
9+
// C++-style comment
510
.cpp-test={}
11+
// Multiline comment cpp-style
12+
// Second line
613
.cpp-test.c=3
714
.cpp-test.d=4

test/data/test_comment_02.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
},
1010
// C++-style comment
1111
"cpp-test" : {
12-
// Internal comment cpp-style
12+
// Multiline comment cpp-style
13+
// Second line
1314
"c" : 3,
1415
"d" : 4
1516
}

test/data/test_integer_01.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// Max signed integer
12
.=2147483647

test/data/test_integer_02.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// Min signed integer
12
.=-2147483648

test/data/test_integer_03.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// Max unsigned integer
12
.=4294967295

test/data/test_integer_04.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
// Min unsigned integer
12
.=0
23

0 commit comments

Comments
 (0)