| Index: third_party/WebKit/Tools/Scripts/webkitpy/common/checkout/diff_parser_unittest.py
|
| diff --git a/third_party/WebKit/Tools/Scripts/webkitpy/common/checkout/diff_parser_unittest.py b/third_party/WebKit/Tools/Scripts/webkitpy/common/checkout/diff_parser_unittest.py
|
| index 6ea84b6df17cebf8da7b920721c9cf420836e6f0..8af9066d0ad7ec68d541f80d0cac25e0253a10ed 100644
|
| --- a/third_party/WebKit/Tools/Scripts/webkitpy/common/checkout/diff_parser_unittest.py
|
| +++ b/third_party/WebKit/Tools/Scripts/webkitpy/common/checkout/diff_parser_unittest.py
|
| @@ -26,44 +26,47 @@
|
| # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
| -import cStringIO as StringIO
|
| import re
|
| import unittest
|
|
|
| -from webkitpy.common.checkout import diff_parser
|
| +from webkitpy.common.checkout.diff_parser import DiffParser
|
| from webkitpy.common.checkout.diff_test_data import DIFF_TEST_DATA
|
|
|
|
|
| class DiffParserTest(unittest.TestCase):
|
| - maxDiff = None
|
|
|
| def test_diff_parser(self, parser=None):
|
| if not parser:
|
| - parser = diff_parser.DiffParser(DIFF_TEST_DATA.splitlines())
|
| + parser = DiffParser(DIFF_TEST_DATA.splitlines())
|
| self.assertEqual(3, len(parser.files))
|
|
|
| self.assertIn('WebCore/style/StyleFlexibleBoxData.h', parser.files)
|
| diff = parser.files['WebCore/style/StyleFlexibleBoxData.h']
|
| self.assertEqual(7, len(diff.lines))
|
| +
|
| # The first two unchanged lines.
|
| self.assertEqual((47, 47), diff.lines[0][0:2])
|
| self.assertEqual('', diff.lines[0][2])
|
| self.assertEqual((48, 48), diff.lines[1][0:2])
|
| self.assertEqual(' unsigned align : 3; // EBoxAlignment', diff.lines[1][2])
|
| - # The deleted line
|
| +
|
| + # The deleted line.
|
| self.assertEqual((50, 0), diff.lines[3][0:2])
|
| self.assertEqual(' unsigned orient: 1; // EBoxOrient', diff.lines[3][2])
|
|
|
| # The first file looks OK. Let's check the next, more complicated file.
|
| self.assertIn('WebCore/style/StyleRareInheritedData.cpp', parser.files)
|
| diff = parser.files['WebCore/style/StyleRareInheritedData.cpp']
|
| +
|
| # There are 3 chunks.
|
| self.assertEqual(7 + 7 + 9, len(diff.lines))
|
| +
|
| # Around an added line.
|
| self.assertEqual((60, 61), diff.lines[9][0:2])
|
| self.assertEqual((0, 62), diff.lines[10][0:2])
|
| self.assertEqual((61, 63), diff.lines[11][0:2])
|
| - # Look through the last chunk, which contains both add's and delete's.
|
| +
|
| + # Look through the last chunk, which contains both adds and deletes.
|
| self.assertEqual((81, 83), diff.lines[14][0:2])
|
| self.assertEqual((82, 84), diff.lines[15][0:2])
|
| self.assertEqual((83, 85), diff.lines[16][0:2])
|
| @@ -79,99 +82,22 @@ class DiffParserTest(unittest.TestCase):
|
| self.assertEqual(1, len(diff.lines))
|
| self.assertEqual((0, 1), diff.lines[0][0:2])
|
|
|
| - def test_diff_converter(self):
|
| - comment_lines = [
|
| - "Hey people,\n",
|
| - "\n",
|
| - "See my awesome patch below!\n",
|
| - "\n",
|
| - " - Cool Hacker\n",
|
| - "\n",
|
| - ]
|
| -
|
| - revision_lines = [
|
| - "Subversion Revision 289799\n",
|
| - ]
|
| -
|
| - svn_diff_lines = [
|
| - "Index: Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n",
|
| - "===================================================================\n",
|
| - "--- Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n",
|
| - "+++ Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n",
|
| - "@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):\n",
|
| - ]
|
| - self.assertEqual(diff_parser.get_diff_converter(svn_diff_lines), diff_parser.svn_diff_to_svn_diff)
|
| - self.assertEqual(diff_parser.get_diff_converter(comment_lines + svn_diff_lines), diff_parser.svn_diff_to_svn_diff)
|
| - self.assertEqual(diff_parser.get_diff_converter(revision_lines + svn_diff_lines), diff_parser.svn_diff_to_svn_diff)
|
| -
|
| - git_diff_lines = [
|
| - ("diff --git a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py "
|
| - "b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n"),
|
| - "index 3c5b45b..0197ead 100644\n",
|
| - "--- a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n",
|
| - "+++ b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n",
|
| - "@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):\n",
|
| - ]
|
| - self.assertEqual(diff_parser.get_diff_converter(git_diff_lines), diff_parser.git_diff_to_svn_diff)
|
| - self.assertEqual(diff_parser.get_diff_converter(comment_lines + git_diff_lines), diff_parser.git_diff_to_svn_diff)
|
| - self.assertEqual(diff_parser.get_diff_converter(revision_lines + git_diff_lines), diff_parser.git_diff_to_svn_diff)
|
| -
|
| - def test_git_mnemonicprefix(self):
|
| - p = re.compile(r' ([a|b])/')
|
| -
|
| - prefixes = [
|
| - {'a': 'i', 'b': 'w'}, # git-diff (compares the (i)ndex and the (w)ork tree)
|
| - {'a': 'c', 'b': 'w'}, # git-diff HEAD (compares a (c)ommit and the (w)ork tree)
|
| - {'a': 'c', 'b': 'i'}, # git diff --cached (compares a (c)ommit and the (i)ndex)
|
| - {'a': 'o', 'b': 'w'}, # git-diff HEAD:file1 file2 (compares an (o)bject and a (w)ork tree entity)
|
| - {'a': '1', 'b': '2'}, # git diff --no-index a b (compares two non-git things (1) and (2))
|
| - ]
|
| -
|
| - for prefix in prefixes:
|
| - patch = p.sub(lambda x: " %s/" % prefix[x.group(1)], DIFF_TEST_DATA)
|
| - self.test_diff_parser(diff_parser.DiffParser(patch.splitlines()))
|
| -
|
| - def test_git_diff_to_svn_diff(self):
|
| - output = """\
|
| -Index: Tools/Scripts/webkitpy/common/checkout/diff_parser.py
|
| -===================================================================
|
| ---- Tools/Scripts/webkitpy/common/checkout/diff_parser.py
|
| -+++ Tools/Scripts/webkitpy/common/checkout/diff_parser.py
|
| -@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):
|
| - A
|
| - B
|
| - C
|
| -+D
|
| - E
|
| - F
|
| -"""
|
| -
|
| - inputfmt = StringIO.StringIO("""\
|
| -diff --git a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py
|
| -index 2ed552c4555db72df16b212547f2c125ae301a04..72870482000c0dba64ce4300ed782c03ee79b74f 100644
|
| ---- a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py
|
| -+++ b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py
|
| -@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):
|
| - A
|
| - B
|
| - C
|
| -+D
|
| - E
|
| - F
|
| -""")
|
| - shortfmt = StringIO.StringIO("""\
|
| -diff --git a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py
|
| -index b48b162..f300960 100644
|
| ---- a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py
|
| -+++ b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py
|
| -@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):
|
| - A
|
| - B
|
| - C
|
| -+D
|
| - E
|
| - F
|
| -""")
|
| -
|
| - self.assertMultiLineEqual(output, ''.join(diff_parser.git_diff_to_svn_diff(x) for x in shortfmt.readlines()))
|
| - self.assertMultiLineEqual(output, ''.join(diff_parser.git_diff_to_svn_diff(x) for x in inputfmt.readlines()))
|
| + def test_diff_parser_with_different_mnemonic_prefixes(self):
|
| + # This repeats test_diff_parser but with different versions
|
| + # of DIFF_TEST_DATA that use other prefixes instead of a/b.
|
| + prefixes = (
|
| + ('i', 'w'), # git-diff (compares the (i)ndex and the (w)ork tree)
|
| + ('c', 'w'), # git-diff HEAD (compares a (c)ommit and the (w)ork tree)
|
| + ('c', 'i'), # git diff --cached (compares a (c)ommit and the (i)ndex)
|
| + ('o', 'w'), # git-diff HEAD:file1 file2 (compares an (o)bject and a (w)ork tree entity)
|
| + ('1', '2'), # git diff --no-index a b (compares two non-git things (1) and (2))
|
| + )
|
| + for a_replacement, b_replacement in prefixes:
|
| + patch = self._patch(a_replacement, b_replacement)
|
| + self.test_diff_parser(DiffParser(patch.splitlines()))
|
| +
|
| + @staticmethod
|
| + def _patch(a_replacement='a', b_replacement='b'):
|
| + """Returns a version of the example patch with mnemonic prefixes a/b changed."""
|
| + patch = re.sub(r' a/', ' %s/' % a_replacement, DIFF_TEST_DATA)
|
| + return re.sub(r' b/', ' %s/' % b_replacement, patch)
|
|
|