| 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 |
| 11 # in the documentation and/or other materials provided with the | 11 # in the documentation and/or other materials provided with the |
| 12 # distribution. | 12 # distribution. |
| 13 # * Neither the name of Google Inc. nor the names of its | 13 # * Neither the name of Google Inc. nor the names of its |
| 14 # contributors may be used to endorse or promote products derived from | 14 # contributors may be used to endorse or promote products derived from |
| 15 # this software without specific prior written permission. | 15 # this software without specific prior written permission. |
| 16 # | 16 # |
| 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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 |
| 31 import re | 31 import re |
| 32 import unittest | 32 import unittest |
| 33 | 33 |
| 34 from webkitpy.common.checkout import diff_parser |
| 34 from webkitpy.common.checkout.diff_test_data import DIFF_TEST_DATA | 35 from webkitpy.common.checkout.diff_test_data import DIFF_TEST_DATA |
| 35 | 36 |
| 36 | 37 |
| 37 class DiffParserTest(unittest.TestCase): | 38 class DiffParserTest(unittest.TestCase): |
| 38 maxDiff = None | 39 maxDiff = None |
| 39 | 40 |
| 40 def test_diff_parser(self, parser=None): | 41 def test_diff_parser(self, parser=None): |
| 41 if not parser: | 42 if not parser: |
| 42 parser = diff_parser.DiffParser(DIFF_TEST_DATA.splitlines()) | 43 parser = diff_parser.DiffParser(DIFF_TEST_DATA.splitlines()) |
| 43 self.assertEqual(3, len(parser.files)) | 44 self.assertEqual(3, len(parser.files)) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 "===================================================================
\n", | 99 "===================================================================
\n", |
| 99 "--- Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", | 100 "--- Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", |
| 100 "+++ Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", | 101 "+++ Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", |
| 101 "@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):\n", | 102 "@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):\n", |
| 102 ] | 103 ] |
| 103 self.assertEqual(diff_parser.get_diff_converter(svn_diff_lines), diff_pa
rser.svn_diff_to_svn_diff) | 104 self.assertEqual(diff_parser.get_diff_converter(svn_diff_lines), diff_pa
rser.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) | 105 self.assertEqual(diff_parser.get_diff_converter(comment_lines + svn_diff
_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) | 106 self.assertEqual(diff_parser.get_diff_converter(revision_lines + svn_dif
f_lines), diff_parser.svn_diff_to_svn_diff) |
| 106 | 107 |
| 107 git_diff_lines = [ | 108 git_diff_lines = [ |
| 108 "diff --git a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py
b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", | 109 ("diff --git a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py
" |
| 110 "b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n"), |
| 109 "index 3c5b45b..0197ead 100644\n", | 111 "index 3c5b45b..0197ead 100644\n", |
| 110 "--- a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", | 112 "--- a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", |
| 111 "+++ b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", | 113 "+++ b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", |
| 112 "@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):\n", | 114 "@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):\n", |
| 113 ] | 115 ] |
| 114 self.assertEqual(diff_parser.get_diff_converter(git_diff_lines), diff_pa
rser.git_diff_to_svn_diff) | 116 self.assertEqual(diff_parser.get_diff_converter(git_diff_lines), diff_pa
rser.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) | 117 self.assertEqual(diff_parser.get_diff_converter(comment_lines + git_diff
_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) | 118 self.assertEqual(diff_parser.get_diff_converter(revision_lines + git_dif
f_lines), diff_parser.git_diff_to_svn_diff) |
| 117 | 119 |
| 118 def test_git_mnemonicprefix(self): | 120 def test_git_mnemonic_prefix(self): |
| 119 p = re.compile(r' ([a|b])/') | 121 pattern = re.compile(r' ([a|b])/') |
| 120 | 122 |
| 121 prefixes = [ | 123 prefixes = [ |
| 122 {'a': 'i', 'b': 'w'}, # git-diff (compares the (i)ndex and the (w)o
rk tree) | 124 {'a': 'i', 'b': 'w'}, # git-diff (compares the (i)ndex and the (w)o
rk tree) |
| 123 {'a': 'c', 'b': 'w'}, # git-diff HEAD (compares a (c)ommit and the
(w)ork tree) | 125 {'a': 'c', 'b': 'w'}, # git-diff HEAD (compares a (c)ommit and the
(w)ork tree) |
| 124 {'a': 'c', 'b': 'i'}, # git diff --cached (compares a (c)ommit and
the (i)ndex) | 126 {'a': 'c', 'b': 'i'}, # git diff --cached (compares a (c)ommit and
the (i)ndex) |
| 125 {'a': 'o', 'b': 'w'}, # git-diff HEAD:file1 file2 (compares an (o)b
ject and a (w)ork tree entity) | 127 {'a': 'o', 'b': 'w'}, # git-diff HEAD:file1 file2 (compares an (o)b
ject and a (w)ork tree entity) |
| 126 {'a': '1', 'b': '2'}, # git diff --no-index a b (compares two non-g
it things (1) and (2)) | 128 {'a': '1', 'b': '2'}, # git diff --no-index a b (compares two non-g
it things (1) and (2)) |
| 127 ] | 129 ] |
| 128 | 130 |
| 131 def patch(prefix): |
| 132 return pattern.sub(lambda match: " %s/" % prefix[match.group(1)], DI
FF_TEST_DATA) |
| 133 |
| 129 for prefix in prefixes: | 134 for prefix in prefixes: |
| 130 patch = p.sub(lambda x: " %s/" % prefix[x.group(1)], DIFF_TEST_DATA) | 135 self.test_diff_parser(diff_parser.DiffParser(patch(prefix).splitline
s())) |
| 131 self.test_diff_parser(diff_parser.DiffParser(patch.splitlines())) | |
| 132 | 136 |
| 133 def test_git_diff_to_svn_diff(self): | 137 def test_git_diff_to_svn_diff(self): |
| 134 output = """\ | 138 output = """\ |
| 135 Index: Tools/Scripts/webkitpy/common/checkout/diff_parser.py | 139 Index: Tools/Scripts/webkitpy/common/checkout/diff_parser.py |
| 136 =================================================================== | 140 =================================================================== |
| 137 --- Tools/Scripts/webkitpy/common/checkout/diff_parser.py | 141 --- Tools/Scripts/webkitpy/common/checkout/diff_parser.py |
| 138 +++ Tools/Scripts/webkitpy/common/checkout/diff_parser.py | 142 +++ Tools/Scripts/webkitpy/common/checkout/diff_parser.py |
| 139 @@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line): | 143 @@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line): |
| 140 A | 144 A |
| 141 B | 145 B |
| (...skipping 25 matching lines...) Expand all Loading... |
| 167 A | 171 A |
| 168 B | 172 B |
| 169 C | 173 C |
| 170 +D | 174 +D |
| 171 E | 175 E |
| 172 F | 176 F |
| 173 """) | 177 """) |
| 174 | 178 |
| 175 self.assertMultiLineEqual(output, ''.join(diff_parser.git_diff_to_svn_di
ff(x) for x in shortfmt.readlines())) | 179 self.assertMultiLineEqual(output, ''.join(diff_parser.git_diff_to_svn_di
ff(x) for x in shortfmt.readlines())) |
| 176 self.assertMultiLineEqual(output, ''.join(diff_parser.git_diff_to_svn_di
ff(x) for x in inputfmt.readlines())) | 180 self.assertMultiLineEqual(output, ''.join(diff_parser.git_diff_to_svn_di
ff(x) for x in inputfmt.readlines())) |
| OLD | NEW |