1 # Copyright (C) 2009 Google Inc. All rights reserved. 2 # 3 # Redistribution and use in source and binary forms, with or without 4 # modification, are permitted provided that the following conditions are 5 # met: 6 # 7 # * Redistributions of source code must retain the above copyright 8 # notice, this list of conditions and the following disclaimer. 9 # * Redistributions in binary form must reproduce the above 10 # copyright notice, this list of conditions and the following disclaimer 11 # in the documentation and/or other materials provided with the 12 # distribution. 13 # * Neither the name of Google Inc. nor the names of its 14 # contributors may be used to endorse or promote products derived from 15 # this software without specific prior written permission. 16 # 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 28 29 import unittest 30 import diff_parser 31 import re 32 33 34 class DiffParserTest(unittest.TestCase): 35 36 _PATCH = '''diff --git a/WebCore/rendering/style/StyleFlexibleBoxData.h b/WebCore/rendering/style/StyleFlexibleBoxData.h 37 index f5d5e74..3b6aa92 100644 38 --- a/WebCore/rendering/style/StyleFlexibleBoxData.h 39 +++ b/WebCore/rendering/style/StyleFlexibleBoxData.h 40 @@ -47,7 +47,6 @@ public: 41 42 unsigned align : 3; // EBoxAlignment 43 unsigned pack: 3; // EBoxAlignment 44 - unsigned orient: 1; // EBoxOrient 45 unsigned lines : 1; // EBoxLines 46 47 private: 48 diff --git a/WebCore/rendering/style/StyleRareInheritedData.cpp b/WebCore/rendering/style/StyleRareInheritedData.cpp 49 index ce21720..324929e 100644 50 --- a/WebCore/rendering/style/StyleRareInheritedData.cpp 51 +++ b/WebCore/rendering/style/StyleRareInheritedData.cpp 52 @@ -39,6 +39,7 @@ StyleRareInheritedData::StyleRareInheritedData() 53 , textSizeAdjust(RenderStyle::initialTextSizeAdjust()) 54 , resize(RenderStyle::initialResize()) 55 , userSelect(RenderStyle::initialUserSelect()) 56 + , boxOrient(RenderStyle::initialBoxOrient()) 57 { 58 } 59 60 @@ -58,6 +59,7 @@ StyleRareInheritedData::StyleRareInheritedData(const StyleRareInheritedData& o) 61 , textSizeAdjust(o.textSizeAdjust) 62 , resize(o.resize) 63 , userSelect(o.userSelect) 64 + , boxOrient(o.boxOrient) 65 { 66 } 67 68 @@ -81,7 +83,8 @@ bool StyleRareInheritedData::operator==(const StyleRareInheritedData& o) const 69 && khtmlLineBreak == o.khtmlLineBreak 70 && textSizeAdjust == o.textSizeAdjust 71 && resize == o.resize 72 - && userSelect == o.userSelect; 73 + && userSelect == o.userSelect 74 + && boxOrient == o.boxOrient; 75 } 76 77 bool StyleRareInheritedData::shadowDataEquivalent(const StyleRareInheritedData& o) const 78 diff --git a/LayoutTests/platform/mac/fast/flexbox/box-orient-button-expected.checksum b/LayoutTests/platform/mac/fast/flexbox/box-orient-button-expected.checksum 79 new file mode 100644 80 index 0000000..6db26bd 81 --- /dev/null 82 +++ b/LayoutTests/platform/mac/fast/flexbox/box-orient-button-expected.checksum 83 @@ -0,0 +1 @@ 84 +61a373ee739673a9dcd7bac62b9f182e 85 \ No newline at end of file 86 ''' 87 88 def test_diff_parser(self, parser = None): 89 if not parser: 90 parser = diff_parser.DiffParser(self._PATCH.splitlines()) 91 self.assertEquals(3, len(parser.files)) 92 93 self.assertTrue('WebCore/rendering/style/StyleFlexibleBoxData.h' in parser.files) 94 diff = parser.files['WebCore/rendering/style/StyleFlexibleBoxData.h'] 95 self.assertEquals(7, len(diff.lines)) 96 # The first two unchaged lines. 97 self.assertEquals((47, 47), diff.lines[0][0:2]) 98 self.assertEquals('', diff.lines[0][2]) 99 self.assertEquals((48, 48), diff.lines[1][0:2]) 100 self.assertEquals(' unsigned align : 3; // EBoxAlignment', diff.lines[1][2]) 101 # The deleted line 102 self.assertEquals((50, 0), diff.lines[3][0:2]) 103 self.assertEquals(' unsigned orient: 1; // EBoxOrient', diff.lines[3][2]) 104 105 # The first file looks OK. Let's check the next, more complicated file. 106 self.assertTrue('WebCore/rendering/style/StyleRareInheritedData.cpp' in parser.files) 107 diff = parser.files['WebCore/rendering/style/StyleRareInheritedData.cpp'] 108 # There are 3 chunks. 109 self.assertEquals(7 + 7 + 9, len(diff.lines)) 110 # Around an added line. 111 self.assertEquals((60, 61), diff.lines[9][0:2]) 112 self.assertEquals((0, 62), diff.lines[10][0:2]) 113 self.assertEquals((61, 63), diff.lines[11][0:2]) 114 # Look through the last chunk, which contains both add's and delete's. 115 self.assertEquals((81, 83), diff.lines[14][0:2]) 116 self.assertEquals((82, 84), diff.lines[15][0:2]) 117 self.assertEquals((83, 85), diff.lines[16][0:2]) 118 self.assertEquals((84, 0), diff.lines[17][0:2]) 119 self.assertEquals((0, 86), diff.lines[18][0:2]) 120 self.assertEquals((0, 87), diff.lines[19][0:2]) 121 self.assertEquals((85, 88), diff.lines[20][0:2]) 122 self.assertEquals((86, 89), diff.lines[21][0:2]) 123 self.assertEquals((87, 90), diff.lines[22][0:2]) 124 125 # Check if a newly added file is correctly handled. 126 diff = parser.files['LayoutTests/platform/mac/fast/flexbox/box-orient-button-expected.checksum'] 127 self.assertEquals(1, len(diff.lines)) 128 self.assertEquals((0, 1), diff.lines[0][0:2]) 129 130 def test_git_mnemonicprefix(self): 131 p = re.compile(r' ([a|b])/') 132 133 prefixes = [ 134 { 'a' : 'i', 'b' : 'w' }, # git-diff (compares the (i)ndex and the (w)ork tree) 135 { 'a' : 'c', 'b' : 'w' }, # git-diff HEAD (compares a (c)ommit and the (w)ork tree) 136 { 'a' : 'c', 'b' : 'i' }, # git diff --cached (compares a (c)ommit and the (i)ndex) 137 { 'a' : 'o', 'b' : 'w' }, # git-diff HEAD:file1 file2 (compares an (o)bject and a (w)ork tree entity) 138 { 'a' : '1', 'b' : '2' }, # git diff --no-index a b (compares two non-git things (1) and (2)) 139 ] 140 141 for prefix in prefixes: 142 patch = p.sub(lambda x: " %s/" % prefix[x.group(1)], self._PATCH) 143 self.test_diff_parser(diff_parser.DiffParser(patch.splitlines())) 144 145 if __name__ == '__main__': 146 unittest.main() 147