Skip to content

Commit e9092b1

Browse files
Abseil Teamcopybara-github
authored andcommitted
Fix unified diff headers.
The length part (only) of each range is optional when equal to one. See http://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html PiperOrigin-RevId: 765326445 Change-Id: I4aec68e82f889e3b4f01861d3b6a16a8b2785ce6
1 parent 7427a6b commit e9092b1

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

googletest/src/gtest.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,17 +1488,17 @@ class Hunk {
14881488
// Print a unified diff header for one hunk.
14891489
// The format is
14901490
// "@@ -<left_start>,<left_length> +<right_start>,<right_length> @@"
1491-
// where the left/right parts are omitted if unnecessary.
1491+
// where the left/right lengths are omitted if unnecessary.
14921492
void PrintHeader(std::ostream* ss) const {
1493-
*ss << "@@ ";
1494-
if (removes_) {
1495-
*ss << "-" << left_start_ << "," << (removes_ + common_);
1493+
size_t left_length = removes_ + common_;
1494+
size_t right_length = adds_ + common_;
1495+
*ss << "@@ " << "-" << left_start_;
1496+
if (left_length != 1) {
1497+
*ss << "," << left_length;
14961498
}
1497-
if (removes_ && adds_) {
1498-
*ss << " ";
1499-
}
1500-
if (adds_) {
1501-
*ss << "+" << right_start_ << "," << (adds_ + common_);
1499+
*ss << " " << "+" << right_start_;
1500+
if (right_length != 1) {
1501+
*ss << "," << right_length;
15021502
}
15031503
*ss << " @@\n";
15041504
}

googletest/test/googletest-output-test-golden-lin.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Expected equality of these values:
6262
Which is: "\"Line\0 1\"\nLine 2"
6363
"Line 2"
6464
With diff:
65-
@@ -1,2 @@
65+
@@ -1,2 +1 @@
6666
-\"Line\0 1\"
6767
Line 2
6868

googletest/test/gtest_unittest.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3579,13 +3579,13 @@ TEST(EditDistance, TestSuites) {
35793579
{__LINE__, "A", "A", " ", ""},
35803580
{__LINE__, "ABCDE", "ABCDE", " ", ""},
35813581
// Simple adds.
3582-
{__LINE__, "X", "XA", " +", "@@ +1,2 @@\n X\n+A\n"},
3583-
{__LINE__, "X", "XABCD", " ++++", "@@ +1,5 @@\n X\n+A\n+B\n+C\n+D\n"},
3582+
{__LINE__, "X", "XA", " +", "@@ -1 +1,2 @@\n X\n+A\n"},
3583+
{__LINE__, "X", "XABCD", " ++++", "@@ -1 +1,5 @@\n X\n+A\n+B\n+C\n+D\n"},
35843584
// Simple removes.
3585-
{__LINE__, "XA", "X", " -", "@@ -1,2 @@\n X\n-A\n"},
3586-
{__LINE__, "XABCD", "X", " ----", "@@ -1,5 @@\n X\n-A\n-B\n-C\n-D\n"},
3585+
{__LINE__, "XA", "X", " -", "@@ -1,2 +1 @@\n X\n-A\n"},
3586+
{__LINE__, "XABCD", "X", " ----", "@@ -1,5 +1 @@\n X\n-A\n-B\n-C\n-D\n"},
35873587
// Simple replaces.
3588-
{__LINE__, "A", "a", "/", "@@ -1,1 +1,1 @@\n-A\n+a\n"},
3588+
{__LINE__, "A", "a", "/", "@@ -1 +1 @@\n-A\n+a\n"},
35893589
{__LINE__, "ABCD", "abcd", "////",
35903590
"@@ -1,4 +1,4 @@\n-A\n-B\n-C\n-D\n+a\n+b\n+c\n+d\n"},
35913591
// Path finding.

0 commit comments

Comments
 (0)