<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[204695] trunk/Tools</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/204695">204695</a></dd>
<dt>Author</dt> <dd>dbates@webkit.org</dd>
<dt>Date</dt> <dd>2016-08-21 11:08:28 -0700 (Sun, 21 Aug 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>prepare-ChangeLog lists modified methods as having been deleted
https://bugs.webkit.org/show_bug.cgi?id=148437

Reviewed by Dan Bernstein.

* Scripts/prepare-ChangeLog:
(diffCommand): When using a Subversion checkout, generate a unified diff without any context lines.
This matches our behavior when using a Git checkout. The function overlap logic in generateFunctionListsByRanges()
assumes that its line ranges were from a unified diff without any context lines.
(extractLineRangeAfterChange): A deleted line should be represented with a (&quot;begin line number&quot;, &quot;end line number&quot;) = (&quot;new starting line number&quot;, &quot;new starting line number&quot;).
(extractLineRangeBeforeChange): An added line should be represented with a (&quot;begin line number&quot;, &quot;end line number&quot;) = (&quot;original starting line number&quot;, &quot;original starting line number&quot;).
* Scripts/webkitperl/prepare-ChangeLog_unittest/extractLineRangeBeforeAndAfterChange.pl: Update expected results
based on changes to extractLineRangeAfterChange() and extractLineRangeBeforeChange().
* Scripts/webkitperl/prepare-ChangeLog_unittest/generateFunctionLists.pl: Added.
(discardOutput): Convenience function invokes the specified function redirecting standard output and standard error
to /dev/null for the duration of the function call.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsScriptsprepareChangeLog">trunk/Tools/Scripts/prepare-ChangeLog</a></li>
<li><a href="#trunkToolsScriptswebkitperlprepareChangeLog_unittestextractLineRangeBeforeAndAfterChangepl">trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/extractLineRangeBeforeAndAfterChange.pl</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsScriptswebkitperlprepareChangeLog_unittestgenerateFunctionListspl">trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/generateFunctionLists.pl</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (204694 => 204695)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-08-21 15:41:20 UTC (rev 204694)
+++ trunk/Tools/ChangeLog        2016-08-21 18:08:28 UTC (rev 204695)
</span><span class="lines">@@ -1,3 +1,22 @@
</span><ins>+2016-08-21  Daniel Bates  &lt;dabates@apple.com&gt;
+
+        prepare-ChangeLog lists modified methods as having been deleted
+        https://bugs.webkit.org/show_bug.cgi?id=148437
+
+        Reviewed by Dan Bernstein.
+
+        * Scripts/prepare-ChangeLog:
+        (diffCommand): When using a Subversion checkout, generate a unified diff without any context lines.
+        This matches our behavior when using a Git checkout. The function overlap logic in generateFunctionListsByRanges()
+        assumes that its line ranges were from a unified diff without any context lines.
+        (extractLineRangeAfterChange): A deleted line should be represented with a (&quot;begin line number&quot;, &quot;end line number&quot;) = (&quot;new starting line number&quot;, &quot;new starting line number&quot;).
+        (extractLineRangeBeforeChange): An added line should be represented with a (&quot;begin line number&quot;, &quot;end line number&quot;) = (&quot;original starting line number&quot;, &quot;original starting line number&quot;).
+        * Scripts/webkitperl/prepare-ChangeLog_unittest/extractLineRangeBeforeAndAfterChange.pl: Update expected results
+        based on changes to extractLineRangeAfterChange() and extractLineRangeBeforeChange().
+        * Scripts/webkitperl/prepare-ChangeLog_unittest/generateFunctionLists.pl: Added.
+        (discardOutput): Convenience function invokes the specified function redirecting standard output and standard error
+        to /dev/null for the duration of the function call.
+
</ins><span class="cx"> 2016-08-20  Gyuyoung Kim  &lt;gyuyoung.kim@navercorp.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [EFL] Remove unnecessary a patch to mute ecore warnings
</span></span></pre></div>
<a id="trunkToolsScriptsprepareChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/prepare-ChangeLog (204694 => 204695)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/prepare-ChangeLog        2016-08-21 15:41:20 UTC (rev 204694)
+++ trunk/Tools/Scripts/prepare-ChangeLog        2016-08-21 18:08:28 UTC (rev 204695)
</span><span class="lines">@@ -1996,11 +1996,13 @@
</span><span class="cx"> {
</span><span class="cx">     my ($paths, $gitCommit, $gitIndex, $mergeBase) = @_;
</span><span class="cx"> 
</span><ins>+    # The function overlap detection logic in generateFunctionListsByRanges() assumes that its line
+    # ranges were from a unified diff without any context lines.
</ins><span class="cx">     my $command;
</span><span class="cx">     if (isSVN()) {
</span><span class="cx">         my @escapedPaths = map(escapeSubversionPath($_), @$paths);
</span><span class="cx">         my $escapedPathsString = qq(&quot;) . join(qq(&quot; &quot;), @escapedPaths) . qq(&quot;);
</span><del>-        $command = SVN . &quot; diff --diff-cmd diff -x -u $escapedPathsString&quot;;
</del><ins>+        $command = SVN . &quot; diff --diff-cmd diff -x -U0 $escapedPathsString&quot;;
</ins><span class="cx">     } elsif (isGit()) {
</span><span class="cx">         my $pathsString = &quot;'&quot; . join(&quot;' '&quot;, @$paths) . &quot;'&quot;; 
</span><span class="cx">         $command = GIT . &quot; diff --no-ext-diff -U0 &quot; . diffFromToString($gitCommit, $gitIndex, $mergeBase);
</span><span class="lines">@@ -2368,9 +2370,12 @@
</span><span class="cx"> {
</span><span class="cx">     my ($string) = @_;
</span><span class="cx">     my $chunkRange = parseChunkRange($string);
</span><del>-    if (!$chunkRange || !$chunkRange-&gt;{newStartingLine} || !$chunkRange-&gt;{newLineCount}) {
</del><ins>+    if (!$chunkRange) {
+        return (-1, -1); # Malformed
+    }
+    if (!$chunkRange-&gt;{newStartingLine} || !$chunkRange-&gt;{newLineCount}) {
</ins><span class="cx">          # Deletion; no lines exist after change.
</span><del>-        return (-1, -1);
</del><ins>+        return ($chunkRange-&gt;{newStartingLine}, $chunkRange-&gt;{newStartingLine});
</ins><span class="cx">     }
</span><span class="cx">     return ($chunkRange-&gt;{newStartingLine}, $chunkRange-&gt;{newStartingLine} + $chunkRange-&gt;{newLineCount} - 1);
</span><span class="cx"> }
</span><span class="lines">@@ -2379,9 +2384,12 @@
</span><span class="cx"> {
</span><span class="cx">     my ($string) = @_;
</span><span class="cx">     my $chunkRange = parseChunkRange($string);
</span><del>-    if (!$chunkRange || !$chunkRange-&gt;{startingLine} || !$chunkRange-&gt;{lineCount}) {
</del><ins>+    if (!$chunkRange) {
+        return (-1, -1); # Malformed
+    }
+    if (!$chunkRange-&gt;{startingLine} || !$chunkRange-&gt;{lineCount}) {
</ins><span class="cx">         # Addition; no lines existed before change.
</span><del>-        return (-1, -1);
</del><ins>+        return ($chunkRange-&gt;{startingLine}, $chunkRange-&gt;{startingLine});
</ins><span class="cx">     }
</span><span class="cx">     return ($chunkRange-&gt;{startingLine}, $chunkRange-&gt;{startingLine} + $chunkRange-&gt;{lineCount} - 1);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkToolsScriptswebkitperlprepareChangeLog_unittestextractLineRangeBeforeAndAfterChangepl"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/extractLineRangeBeforeAndAfterChange.pl (204694 => 204695)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/extractLineRangeBeforeAndAfterChange.pl        2016-08-21 15:41:20 UTC (rev 204694)
+++ trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/extractLineRangeBeforeAndAfterChange.pl        2016-08-21 18:08:28 UTC (rev 204695)
</span><span class="lines">@@ -39,7 +39,7 @@
</span><span class="cx">     testName =&gt; &quot;add single line to the beginning of the file&quot;,
</span><span class="cx">     inputText =&gt; &quot;@@ -0,0 +1 @@&quot;,
</span><span class="cx">     expectedResults =&gt; {
</span><del>-        beforeChange =&gt; [-1, -1],
</del><ins>+        beforeChange =&gt; [0, 0],
</ins><span class="cx">         afterChange =&gt; [1, 1],
</span><span class="cx">     }
</span><span class="cx"> },
</span><span class="lines">@@ -48,7 +48,7 @@
</span><span class="cx">     testName =&gt; &quot;add two lines to the beginning of the file&quot;,
</span><span class="cx">     inputText =&gt; &quot;@@ -0,0 +1,2 @@&quot;,
</span><span class="cx">     expectedResults =&gt; {
</span><del>-        beforeChange =&gt; [-1, -1],
</del><ins>+        beforeChange =&gt; [0, 0],
</ins><span class="cx">         afterChange =&gt; [1, 2],
</span><span class="cx">     }
</span><span class="cx"> },
</span><span class="lines">@@ -57,7 +57,7 @@
</span><span class="cx">     testName =&gt; &quot;add two lines in the middle of the file&quot;,
</span><span class="cx">     inputText =&gt; &quot;@@ -4,0 +5,2 @@&quot;,
</span><span class="cx">     expectedResults =&gt; {
</span><del>-        beforeChange =&gt; [-1, -1],
</del><ins>+        beforeChange =&gt; [4, 4],
</ins><span class="cx">         afterChange =&gt; [5, 6],
</span><span class="cx">     }
</span><span class="cx"> },
</span><span class="lines">@@ -66,7 +66,7 @@
</span><span class="cx">     testName =&gt; &quot;append a single line to the end of the file&quot;,
</span><span class="cx">     inputText =&gt; &quot;@@ -1,0 +2 @@&quot;,
</span><span class="cx">     expectedResults =&gt; {
</span><del>-        beforeChange =&gt; [-1, -1],
</del><ins>+        beforeChange =&gt; [1, 1],
</ins><span class="cx">         afterChange =&gt; [2, 2],
</span><span class="cx">     }
</span><span class="cx"> },
</span><span class="lines">@@ -79,7 +79,7 @@
</span><span class="cx">     inputText =&gt; &quot;@@ -1 +0,0 @@&quot;,
</span><span class="cx">     expectedResults =&gt; {
</span><span class="cx">         beforeChange =&gt; [1, 1],
</span><del>-        afterChange =&gt; [-1, -1],
</del><ins>+        afterChange =&gt; [0, 0],
</ins><span class="cx">     }
</span><span class="cx"> },
</span><span class="cx"> {
</span><span class="lines">@@ -88,7 +88,7 @@
</span><span class="cx">     inputText =&gt; &quot;@@ -1,7 +0,0 @@&quot;,
</span><span class="cx">     expectedResults =&gt; {
</span><span class="cx">         beforeChange =&gt; [1, 7],
</span><del>-        afterChange =&gt; [-1, -1],
</del><ins>+        afterChange =&gt; [0, 0],
</ins><span class="cx">     }
</span><span class="cx"> },
</span><span class="cx"> {
</span><span class="lines">@@ -97,7 +97,7 @@
</span><span class="cx">     inputText =&gt; &quot;@@ -4,2 +3,0 @@&quot;,
</span><span class="cx">     expectedResults =&gt; {
</span><span class="cx">         beforeChange =&gt; [4, 5],
</span><del>-        afterChange =&gt; [-1, -1],
</del><ins>+        afterChange =&gt; [3, 3],
</ins><span class="cx">     }
</span><span class="cx"> },
</span><span class="cx"> ####
</span></span></pre></div>
<a id="trunkToolsScriptswebkitperlprepareChangeLog_unittestgenerateFunctionListspl"></a>
<div class="addfile"><h4>Added: trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/generateFunctionLists.pl (0 => 204695)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/generateFunctionLists.pl                                (rev 0)
+++ trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/generateFunctionLists.pl        2016-08-21 18:08:28 UTC (rev 204695)
</span><span class="lines">@@ -0,0 +1,397 @@
</span><ins>+#!/usr/bin/perl
+#
+# Copyright (C) 2016 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1.  Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+# 2.  Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+# 
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+use strict;
+use warnings;
+
+use File::Slurp;
+use File::Temp;
+use FindBin;
+use Test::More;
+use VCSUtils;
+
+use lib File::Spec-&gt;catdir($FindBin::Bin, &quot;..&quot;);
+use LoadAsModule qw(PrepareChangeLog prepare-ChangeLog);
+
+my $EXAMPLE_CPP = &lt;&lt;EOF;
+#include &lt;cassert&gt;
+#include &lt;cmath&gt;
+#include &lt;limits&gt;
+#include &lt;iostream&gt;
+
+unsigned fib(unsigned);
+
+unsigned fibPlusFive(unsigned n)
+{
+    return fib(n) + 5;
+}
+
+unsigned fib(unsigned n)
+{
+    // Derived from Binet's formula, &lt;http://mathworld.wolfram.com/BinetsFibonacciNumberFormula.html&gt;.
+    assert(n &lt;= std::floor(std::log(std::numeric_limits&lt;unsigned&gt;::max() * std::sqrt(5)) / std::log((1 + std::sqrt(5)) / 2)));
+    if (!n)
+        return 0;
+    if (n == 1)
+        return 1;
+    --n;
+    unsigned a = 0;
+    unsigned b = 1;
+    do {
+        unsigned k = a + b;
+        a = b;
+        b = k;
+    } while (--n);
+    return b;
+}
+
+int main(int argc, const char* argv[])
+{
+    std::cout &lt;&lt; fib(1) &lt;&lt; std::endl;
+    std::cout &lt;&lt; fibPlusFive(1) &lt;&lt; std::endl;
+    std::cout &lt;&lt; fib(5) &lt;&lt; std::endl;
+    std::cout &lt;&lt; fibPlusFive(5) &lt;&lt; std::endl;
+    return 0;
+}
+EOF
+
+my @testCaseHashRefs = (
+###
+# 0 lines of context
+##
+{
+    testName =&gt; &quot;Unified diff with 0 context&quot;,
+    inputText =&gt; $EXAMPLE_CPP,
+    diffToApply =&gt; &lt;&lt;EOF,
+diff --git a/fib.cpp b/fib.cpp
+--- a/fib.cpp
++++ b/fib.cpp
+@@ -15 +14,0 @@ unsigned fib(unsigned n)
+-    // Derived from Binet's formula, &lt;http://mathworld.wolfram.com/BinetsFibonacciNumberFormula.html&gt;.
+EOF
+    expected =&gt; &lt;&lt;EOF
+
+        (fib):
+EOF
+},
+{
+    testName =&gt; &quot;Unified diff with 0 context; combine two adjacent functions&quot;,
+    inputText =&gt; $EXAMPLE_CPP,
+    diffToApply =&gt; &lt;&lt;EOF,
+diff --git a/fib.cpp b/fib.cpp
+--- a/fib.cpp
++++ b/fib.cpp
+@@ -10,5 +9,0 @@ unsigned fibPlusFive(unsigned n)
+-    return fib(n) + 5;
+-}
+-
+-unsigned fib(unsigned n)
+-{
+EOF
+    expected =&gt; &lt;&lt;EOF
+
+        (fibPlusFive):
+        (fib): Deleted.
+EOF
+},
+{
+    testName =&gt; &quot;Unified diff with 0 context; remove function&quot;,
+    inputText =&gt; $EXAMPLE_CPP,
+    diffToApply =&gt; &lt;&lt;EOF,
+diff --git a/fib.cpp b/fib.cpp
+--- a/fib.cpp
++++ b/fib.cpp
+@@ -13,19 +12,0 @@ unsigned fibPlusFive(unsigned n)
+-unsigned fib(unsigned n)
+-{
+-    // Derived from Binet's formula, &lt;http://mathworld.wolfram.com/BinetsFibonacciNumberFormula.html&gt;.
+-    assert(n &lt;= std::floor(std::log(std::numeric_limits&lt;unsigned&gt;::max() * std::sqrt(5)) / std::log((1 + std::sqrt(5)) / 2)));
+-    if (!n)
+-        return 0;
+-    if (n == 1)
+-        return 1;
+-    --n;
+-    unsigned a = 0;
+-    unsigned b = 1;
+-    do {
+-        unsigned k = a + b;
+-        a = b;
+-        b = k;
+-    } while (--n);
+-    return b;
+-}
+-
+EOF
+    expected =&gt; &lt;&lt;EOF
+
+        (fib): Deleted.
+EOF
+},
+{
+    # This is a contrived example and would cause a redefinition error in C++, but an analagous change in a JavaScript script would be fine.
+    testName =&gt; &quot;Unified diff with 0 context; add function above function with the same name&quot;,
+    inputText =&gt; $EXAMPLE_CPP,
+    diffToApply =&gt; &lt;&lt;EOF,
+diff --git a/fib.cpp b/fib.cpp
+--- a/fib.cpp
++++ b/fib.cpp
+@@ -33,0 +34,5 @@ int main(int argc, const char* argv[])
++    return 0;
++}
++
++int main(int argc, const char* argv[])
++{
+EOF
+    expected =&gt; &lt;&lt;EOF
+
+        (main):
+EOF
+},
+{
+    # This is a contrived example and would cause a redefinition error in C++, but an analagous change in a JavaScript script would be fine.
+    testName =&gt; &quot;Unified diff with 0 context; add function after function with the same name&quot;,
+    inputText =&gt; $EXAMPLE_CPP,
+    diffToApply =&gt; &lt;&lt;EOF,
+diff --git a/fib.cpp b/fib.cpp
+--- a/fib.cpp
++++ b/fib.cpp
+@@ -38,0 +39,5 @@ int main(int argc, const char* argv[])
++}
++
++int main(int argc, const char* argv[])
++{
++    return 0;
+EOF
+    expected =&gt; &lt;&lt;EOF
+
+        (main):
+EOF
+},
+###
+# 3 lines of context
+##
+{
+    testName =&gt; &quot;Unified diff with 3 lines of context&quot;,
+    inputText =&gt; $EXAMPLE_CPP,
+    diffToApply =&gt; &lt;&lt;EOF,
+diff --git a/fib.cpp b/fib.cpp
+--- a/fib.cpp
++++ b/fib.cpp
+@@ -12,7 +12,6 @@ unsigned fibPlusFive(unsigned n)

+ unsigned fib(unsigned n)
+ {
+-    // Derived from Binet's formula, &lt;http://mathworld.wolfram.com/BinetsFibonacciNumberFormula.html&gt;.
+     assert(n &lt;= std::floor(std::log(std::numeric_limits&lt;unsigned&gt;::max() * std::sqrt(5)) / std::log((1 + std::sqrt(5)) / 2)));
+     if (!n)
+         return 0;
+EOF
+    expected =&gt; &lt;&lt;EOF
+
+        (fib):
+EOF
+},
+{
+    testName =&gt; &quot;Unified diff with 3 lines of context; combine two adjacent functions&quot;,
+    inputText =&gt; $EXAMPLE_CPP,
+    diffToApply =&gt; &lt;&lt;EOF,
+diff --git a/fib.cpp b/fib.cpp
+--- a/fib.cpp
++++ b/fib.cpp
+@@ -7,11 +7,6 @@ unsigned fib(unsigned);

+ unsigned fibPlusFive(unsigned n)
+ {
+-    return fib(n) + 5;
+-}
+-
+-unsigned fib(unsigned n)
+-{
+     // Derived from Binet's formula, &lt;http://mathworld.wolfram.com/BinetsFibonacciNumberFormula.html&gt;.
+     assert(n &lt;= std::floor(std::log(std::numeric_limits&lt;unsigned&gt;::max() * std::sqrt(5)) / std::log((1 + std::sqrt(5)) / 2)));
+     if (!n)
+EOF
+    expected =&gt; &lt;&lt;EOF,
+
+        (fibPlusFive):
+        (fib): Deleted.
+EOF
+},
+{
+    testName =&gt; &quot;Unified diff with 3 lines of context; remove function&quot;,
+    inputText =&gt; $EXAMPLE_CPP,
+    diffToApply =&gt; &lt;&lt;EOF,
+diff --git a/fib.cpp b/fib.cpp
+--- a/fib.cpp
++++ b/fib.cpp
+@@ -10,25 +10,6 @@ unsigned fibPlusFive(unsigned n)
+     return fib(n) + 5;
+ }

+-unsigned fib(unsigned n)
+-{
+-    // Derived from Binet's formula, &lt;http://mathworld.wolfram.com/BinetsFibonacciNumberFormula.html&gt;.
+-    assert(n &lt;= std::floor(std::log(std::numeric_limits&lt;unsigned&gt;::max() * std::sqrt(5)) / std::log((1 + std::sqrt(5)) / 2)));
+-    if (!n)
+-        return 0;
+-    if (n == 1)
+-        return 1;
+-    --n;
+-    unsigned a = 0;
+-    unsigned b = 1;
+-    do {
+-        unsigned k = a + b;
+-        a = b;
+-        b = k;
+-    } while (--n);
+-    return b;
+-}
+-
+ int main(int argc, const char* argv[])
+ {
+     std::cout &lt;&lt; fib(1) &lt;&lt; std::endl;
+EOF
+    # Note that this output is expected given that the chunk range includes the removed content plus context lines.
+    # The context lines make the after chunk range (+10, 6) overlap the implementation of fibPlusFive() and main().
+    expected =&gt; &lt;&lt;EOF,
+
+        (fibPlusFive):
+        (main):
+        (fib): Deleted.
+EOF
+},
+###
+# Diff that does not differ with respect to number of context lines
+##
+{
+    testName =&gt; &quot;Unified diff; delete contents of entire file&quot;,
+    inputText =&gt; $EXAMPLE_CPP,
+    diffToApply =&gt; &lt;&lt;EOF,
+diff --git a/fib.cpp b/fib.cpp
+--- a/fib.cpp
++++ b/fib.cpp
+@@ -1,39 +0,0 @@
+-#include &lt;cassert&gt;
+-#include &lt;cmath&gt;
+-#include &lt;limits&gt;
+-#include &lt;iostream&gt;
+-
+-unsigned fib(unsigned);
+-
+-unsigned fibPlusFive(unsigned n)
+-{
+-    return fib(n) + 5;
+-}
+-
+-unsigned fib(unsigned n)
+-{
+-    // Derived from Binet's formula, &lt;http://mathworld.wolfram.com/BinetsFibonacciNumberFormula.html&gt;.
+-    assert(n &lt;= std::floor(std::log(std::numeric_limits&lt;unsigned&gt;::max() * std::sqrt(5)) / std::log((1 + std::sqrt(5)) / 2)));
+-    if (!n)
+-        return 0;
+-    if (n == 1)
+-        return 1;
+-    --n;
+-    unsigned a = 0;
+-    unsigned b = 1;
+-    do {
+-        unsigned k = a + b;
+-        a = b;
+-        b = k;
+-    } while (--n);
+-    return b;
+-}
+-
+-int main(int argc, const char* argv[])
+-{
+-    std::cout &lt;&lt; fib(1) &lt;&lt; std::endl;
+-    std::cout &lt;&lt; fibPlusFive(1) &lt;&lt; std::endl;
+-    std::cout &lt;&lt; fib(5) &lt;&lt; std::endl;
+-    std::cout &lt;&lt; fibPlusFive(5) &lt;&lt; std::endl;
+-    return 0;
+-}
+EOF
+    expected =&gt; &lt;&lt;EOF
+
+        (fibPlusFive): Deleted.
+        (fib): Deleted.
+        (main): Deleted.
+EOF
+},
+);
+
+sub discardOutput(&amp;)
+{
+    my ($functionRef) = @_;
+    open(my $savedStdout, &quot;&gt;&amp;STDOUT&quot;) or die &quot;Cannot dup STDOUT: $!&quot;;
+    open(my $savedStderr, &quot;&gt;&amp;STDERR&quot;) or die &quot;Cannot dup STDERR: $!&quot;;
+
+    open(STDOUT, &quot;&gt;&quot;, File::Spec-&gt;devnull());
+    open(STDERR, &quot;&gt;&quot;, File::Spec-&gt;devnull());
+    &amp;$functionRef();
+
+    open(STDOUT, &quot;&gt;&amp;&quot;, $savedStdout) or die &quot;Cannot restore stdout: $!&quot;;
+    open(STDERR, &quot;&gt;&amp;&quot;, $savedStderr) or die &quot;Cannot restore stderr: $!&quot;;
+}
+
+my $testCasesCount = @testCaseHashRefs;
+plan(tests =&gt; $testCasesCount);
+
+my $temporaryDirectory = File::Temp-&gt;newdir();
+my $filename = &quot;fib.cpp&quot;;
+my $originalFile = File::Spec-&gt;catfile($temporaryDirectory, $filename);
+my $patchedFile = File::Spec-&gt;catfile($temporaryDirectory, &quot;patched-$filename&quot;);
+my $diffFile = File::Spec-&gt;catfile($temporaryDirectory, &quot;a.diff&quot;);
+foreach my $testCase (@testCaseHashRefs) {
+    write_file($originalFile, $testCase-&gt;{inputText});
+    write_file($diffFile, $testCase-&gt;{diffToApply});
+    my $exitCode = exitStatus(system(&quot;patch&quot;, &quot;-s&quot;, &quot;-d&quot;, $temporaryDirectory, &quot;-i&quot;, $diffFile, &quot;-o&quot;, $patchedFile));
+    die &quot;Failed to apply patch for $testCase-&gt;{testName}: $exitCode&quot; if $exitCode;
+
+    my %delegateHash = (
+        openDiff =&gt; sub () {
+            my $fileHandle;
+            open($fileHandle, &quot;&lt;&quot;, \$testCase-&gt;{diffToApply});
+            return $fileHandle;
+        },
+        openFile =&gt; sub () {
+            return unless open(PATCHED_FILE, &quot;&lt;&quot;, $patchedFile);
+            return \*PATCHED_FILE;
+        },
+        openOriginalFile =&gt; sub () {
+            my $fileHandle;
+            open($fileHandle, &quot;&lt;&quot;, \$testCase-&gt;{inputText});
+            return $fileHandle;
+        },
+        normalizePath =&gt; sub () {
+            return $filename;
+        },
+    );
+    my %functionLists;
+    discardOutput(sub {
+        PrepareChangeLog::actuallyGenerateFunctionLists([$filename], \%functionLists, undef, undef, undef, \%delegateHash);
+    });
+    chomp(my $expected = $testCase-&gt;{expected});
+    is($functionLists{$filename}, $expected, $testCase-&gt;{testName});
+}
</ins></span></pre>
</div>
</div>

</body>
</html>