| OLD | NEW |
| 1 # Copyright (C) 2009 Google Inc. All rights reserved. | 1 # Copyright (C) 2009 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 import cStringIO as StringIO | 29 import cStringIO as StringIO |
| 30 import diff_parser | 30 import diff_parser |
| 31 import re | 31 import re |
| 32 import unittest | 32 import unittest |
| 33 | 33 |
| 34 from webkitpy.common.checkout.diff_test_data import DIFF_TEST_DATA | 34 from webkitpy.common.checkout.diff_test_data import DIFF_TEST_DATA |
| 35 | 35 |
| 36 |
| 36 class DiffParserTest(unittest.TestCase): | 37 class DiffParserTest(unittest.TestCase): |
| 37 maxDiff = None | 38 maxDiff = None |
| 38 | 39 |
| 39 def test_diff_parser(self, parser = None): | 40 def test_diff_parser(self, parser=None): |
| 40 if not parser: | 41 if not parser: |
| 41 parser = diff_parser.DiffParser(DIFF_TEST_DATA.splitlines()) | 42 parser = diff_parser.DiffParser(DIFF_TEST_DATA.splitlines()) |
| 42 self.assertEqual(3, len(parser.files)) | 43 self.assertEqual(3, len(parser.files)) |
| 43 | 44 |
| 44 self.assertTrue('WebCore/style/StyleFlexibleBoxData.h' in parser.files) | 45 self.assertTrue('WebCore/style/StyleFlexibleBoxData.h' in parser.files) |
| 45 diff = parser.files['WebCore/style/StyleFlexibleBoxData.h'] | 46 diff = parser.files['WebCore/style/StyleFlexibleBoxData.h'] |
| 46 self.assertEqual(7, len(diff.lines)) | 47 self.assertEqual(7, len(diff.lines)) |
| 47 # The first two unchaged lines. | 48 # The first two unchaged lines. |
| 48 self.assertEqual((47, 47), diff.lines[0][0:2]) | 49 self.assertEqual((47, 47), diff.lines[0][0:2]) |
| 49 self.assertEqual('', diff.lines[0][2]) | 50 self.assertEqual('', diff.lines[0][2]) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 79 self.assertEqual((0, 1), diff.lines[0][0:2]) | 80 self.assertEqual((0, 1), diff.lines[0][0:2]) |
| 80 | 81 |
| 81 def test_diff_converter(self): | 82 def test_diff_converter(self): |
| 82 comment_lines = [ | 83 comment_lines = [ |
| 83 "Hey guys,\n", | 84 "Hey guys,\n", |
| 84 "\n", | 85 "\n", |
| 85 "See my awesome patch below!\n", | 86 "See my awesome patch below!\n", |
| 86 "\n", | 87 "\n", |
| 87 " - Cool Hacker\n", | 88 " - Cool Hacker\n", |
| 88 "\n", | 89 "\n", |
| 89 ] | 90 ] |
| 90 | 91 |
| 91 revision_lines = [ | 92 revision_lines = [ |
| 92 "Subversion Revision 289799\n", | 93 "Subversion Revision 289799\n", |
| 93 ] | 94 ] |
| 94 | 95 |
| 95 svn_diff_lines = [ | 96 svn_diff_lines = [ |
| 96 "Index: Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", | 97 "Index: Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", |
| 97 "===================================================================
\n", | 98 "===================================================================
\n", |
| 98 "--- Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", | 99 "--- Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", |
| 99 "+++ Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", | 100 "+++ Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", |
| 100 "@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):\n", | 101 "@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):\n", |
| 101 ] | 102 ] |
| 102 self.assertEqual(diff_parser.get_diff_converter(svn_diff_lines), diff_pa
rser.svn_diff_to_svn_diff) | 103 self.assertEqual(diff_parser.get_diff_converter(svn_diff_lines), diff_pa
rser.svn_diff_to_svn_diff) |
| 103 self.assertEqual(diff_parser.get_diff_converter(comment_lines + svn_diff
_lines), diff_parser.svn_diff_to_svn_diff) | 104 self.assertEqual(diff_parser.get_diff_converter(comment_lines + svn_diff
_lines), diff_parser.svn_diff_to_svn_diff) |
| 104 self.assertEqual(diff_parser.get_diff_converter(revision_lines + svn_dif
f_lines), diff_parser.svn_diff_to_svn_diff) | 105 self.assertEqual(diff_parser.get_diff_converter(revision_lines + svn_dif
f_lines), diff_parser.svn_diff_to_svn_diff) |
| 105 | 106 |
| 106 git_diff_lines = [ | 107 git_diff_lines = [ |
| 107 "diff --git a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py
b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", | 108 "diff --git a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py
b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", |
| 108 "index 3c5b45b..0197ead 100644\n", | 109 "index 3c5b45b..0197ead 100644\n", |
| 109 "--- a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", | 110 "--- a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", |
| 110 "+++ b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", | 111 "+++ b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", |
| 111 "@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):\n", | 112 "@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):\n", |
| 112 ] | 113 ] |
| 113 self.assertEqual(diff_parser.get_diff_converter(git_diff_lines), diff_pa
rser.git_diff_to_svn_diff) | 114 self.assertEqual(diff_parser.get_diff_converter(git_diff_lines), diff_pa
rser.git_diff_to_svn_diff) |
| 114 self.assertEqual(diff_parser.get_diff_converter(comment_lines + git_diff
_lines), diff_parser.git_diff_to_svn_diff) | 115 self.assertEqual(diff_parser.get_diff_converter(comment_lines + git_diff
_lines), diff_parser.git_diff_to_svn_diff) |
| 115 self.assertEqual(diff_parser.get_diff_converter(revision_lines + git_dif
f_lines), diff_parser.git_diff_to_svn_diff) | 116 self.assertEqual(diff_parser.get_diff_converter(revision_lines + git_dif
f_lines), diff_parser.git_diff_to_svn_diff) |
| 116 | 117 |
| 117 def test_git_mnemonicprefix(self): | 118 def test_git_mnemonicprefix(self): |
| 118 p = re.compile(r' ([a|b])/') | 119 p = re.compile(r' ([a|b])/') |
| 119 | 120 |
| 120 prefixes = [ | 121 prefixes = [ |
| 121 { 'a' : 'i', 'b' : 'w' }, # git-diff (compares the (i)ndex and the (
w)ork tree) | 122 {'a': 'i', 'b': 'w'}, # git-diff (compares the (i)ndex and the (w)o
rk tree) |
| 122 { 'a' : 'c', 'b' : 'w' }, # git-diff HEAD (compares a (c)ommit and t
he (w)ork tree) | 123 {'a': 'c', 'b': 'w'}, # git-diff HEAD (compares a (c)ommit and the
(w)ork tree) |
| 123 { 'a' : 'c', 'b' : 'i' }, # git diff --cached (compares a (c)ommit a
nd the (i)ndex) | 124 {'a': 'c', 'b': 'i'}, # git diff --cached (compares a (c)ommit and
the (i)ndex) |
| 124 { 'a' : 'o', 'b' : 'w' }, # git-diff HEAD:file1 file2 (compares an (
o)bject and a (w)ork tree entity) | 125 {'a': 'o', 'b': 'w'}, # git-diff HEAD:file1 file2 (compares an (o)b
ject and a (w)ork tree entity) |
| 125 { 'a' : '1', 'b' : '2' }, # git diff --no-index a b (compares two no
n-git things (1) and (2)) | 126 {'a': '1', 'b': '2'}, # git diff --no-index a b (compares two non-g
it things (1) and (2)) |
| 126 ] | 127 ] |
| 127 | 128 |
| 128 for prefix in prefixes: | 129 for prefix in prefixes: |
| 129 patch = p.sub(lambda x: " %s/" % prefix[x.group(1)], DIFF_TEST_DATA) | 130 patch = p.sub(lambda x: " %s/" % prefix[x.group(1)], DIFF_TEST_DATA) |
| 130 self.test_diff_parser(diff_parser.DiffParser(patch.splitlines())) | 131 self.test_diff_parser(diff_parser.DiffParser(patch.splitlines())) |
| 131 | 132 |
| 132 def test_git_diff_to_svn_diff(self): | 133 def test_git_diff_to_svn_diff(self): |
| 133 output = """\ | 134 output = """\ |
| 134 Index: Tools/Scripts/webkitpy/common/checkout/diff_parser.py | 135 Index: Tools/Scripts/webkitpy/common/checkout/diff_parser.py |
| 135 =================================================================== | 136 =================================================================== |
| (...skipping 30 matching lines...) Expand all Loading... |
| 166 A | 167 A |
| 167 B | 168 B |
| 168 C | 169 C |
| 169 +D | 170 +D |
| 170 E | 171 E |
| 171 F | 172 F |
| 172 """) | 173 """) |
| 173 | 174 |
| 174 self.assertMultiLineEqual(output, ''.join(diff_parser.git_diff_to_svn_di
ff(x) for x in shortfmt.readlines())) | 175 self.assertMultiLineEqual(output, ''.join(diff_parser.git_diff_to_svn_di
ff(x) for x in shortfmt.readlines())) |
| 175 self.assertMultiLineEqual(output, ''.join(diff_parser.git_diff_to_svn_di
ff(x) for x in inputfmt.readlines())) | 176 self.assertMultiLineEqual(output, ''.join(diff_parser.git_diff_to_svn_di
ff(x) for x in inputfmt.readlines())) |
| OLD | NEW |