| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 import unittest | |
| 7 | |
| 8 import patching | |
| 9 | |
| 10 | |
| 11 class TestParsePatchToLines(unittest.TestCase): | |
| 12 def test_empty(self): | |
| 13 self.assertEquals([], patching.ParsePatchToLines([])) | |
| 14 | |
| 15 def test_prelude(self): | |
| 16 self.assertEquals([], patching.ParsePatchToLines(""" | |
| 17 Here goes some prelude. | |
| 18 And it continues on for some while. | |
| 19 | |
| 20 --- file | |
| 21 +++ file | |
| 22 """.splitlines())) | |
| 23 | |
| 24 def test_bad_hunk_header(self): | |
| 25 with self.assertRaises(patching.PatchParseError): | |
| 26 patching.ParsePatchToLines(""" | |
| 27 --- file | |
| 28 +++ file | |
| 29 @@ bad | |
| 30 """.splitlines()) | |
| 31 | |
| 32 def test_multiple_files(self): | |
| 33 with self.assertRaises(patching.PatchParseError): | |
| 34 patching.ParsePatchToLines(""" | |
| 35 diff -urN test1/bar test2/bar | |
| 36 --- test1/bar 2013-08-08 14:15:46.604119530 +0200 | |
| 37 +++ test2/bar 2013-08-08 14:15:49.814145535 +0200 | |
| 38 @@ -1 +1 @@ | |
| 39 -foo | |
| 40 +bar | |
| 41 diff -urN test1/foo test2/foo | |
| 42 --- test1/foo 2013-08-08 14:15:36.044033982 +0200 | |
| 43 +++ test2/foo 2013-08-08 14:15:42.204083886 +0200 | |
| 44 @@ -1 +1 @@ | |
| 45 -foo | |
| 46 +bar | |
| 47 """.splitlines()) | |
| 48 | |
| 49 def test_simple(self): | |
| 50 self.assertEquals([ | |
| 51 (1, 1, 'common line'), | |
| 52 (2, None, 'old line'), | |
| 53 (None, 2, 'new line'), | |
| 54 (3, 3, 'common line'), | |
| 55 ], patching.ParsePatchToLines(""" | |
| 56 --- old 2013-08-08 14:05:18.539090366 +0200 | |
| 57 +++ new 2013-08-08 14:05:18.539090366 +0200 | |
| 58 @@ -1,3 +1,3 @@ | |
| 59 common line | |
| 60 -old line | |
| 61 +new line | |
| 62 common line | |
| 63 """.splitlines())) | |
| 64 | |
| 65 def test_multiple_hunks(self): | |
| 66 self.assertEquals([ | |
| 67 (None, 1, 'prepended line'), | |
| 68 (1, 2, ''), | |
| 69 (2, 3, ''), | |
| 70 (3, 4, ''), | |
| 71 (8, 9, ''), | |
| 72 (9, 10, ''), | |
| 73 (10, 11, ''), | |
| 74 (None, 12, 'appended line'), | |
| 75 ], patching.ParsePatchToLines(""" | |
| 76 --- old 2013-08-08 14:10:10.391408985 +0200 | |
| 77 +++ new 2013-08-08 14:10:15.511449623 +0200 | |
| 78 @@ -1,3 +1,4 @@ | |
| 79 +prepended line | |
| 80 | |
| 81 | |
| 82 | |
| 83 @@ -8,3 +9,4 @@ | |
| 84 | |
| 85 | |
| 86 | |
| 87 +appended line | |
| 88 """.splitlines())) | |
| 89 | |
| 90 if __name__ == '__main__': | |
| 91 unittest.main() | |
| OLD | NEW |