Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/common/html_diff_unittest.py

Issue 2695993002: hmtl_diff: Show only three lines before/after a diff block. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import unittest 5 import unittest
6 6
7 from webkitpy.common.html_diff import html_diff, html_diff_body 7 from webkitpy.common.html_diff import HtmlDiffGenerator, html_diff
8 8
9 9
10 def html_diff_body(a_lines, b_lines):
11 return HtmlDiffGenerator().generate_tbody(a_lines, b_lines)
12
10 class TestHtmlDiff(unittest.TestCase): 13 class TestHtmlDiff(unittest.TestCase):
11 14
12 def test_html_diff(self): 15 def test_html_diff(self):
13 self.assertEqual( 16 self.assertEqual(
14 html_diff('one\ntoo\nthree\n', 'one\ntwo\nthree\n'), 17 html_diff('one\ntoo\nthree\n', 'one\ntwo\nthree\n'),
15 ('<html>\n' 18 ('<html>\n'
16 '<head>\n' 19 '<head>\n'
17 '<style>\n' 20 '<style>\n'
18 'pre { white-space: pre-wrap; }\n' 21 'table { white-space: pre-wrap; font-family: monospace; border-coll apse: collapse; }\n'
22 'th { color: #444; background: #eed; text-align: right; vertical-al ign: baseline; padding: 1px 4px 1px 4px; }\n'
19 '.del { background: #faa; }\n' 23 '.del { background: #faa; }\n'
20 '.add { background: #afa; }\n' 24 '.add { background: #afa; }\n'
21 '</style>\n' 25 '</style>\n'
22 '</head>\n' 26 '</head>\n'
23 '<body>\n' 27 '<body><table>'
24 '<pre>one\n' 28 '<tr><th>1<th>1<td>one\n</tr>'
25 '<span class="del">too\n' 29 '<tr><th>2<th><td class="del">too\n</tr>'
26 '</span><span class="add">two\n' 30 '<tr><th><th>2<td class="add">two\n</tr>'
27 '</span>three\n' 31 '<tr><th>3<th>3<td>three\n</tr>'
28 '</pre>\n' 32 '</table></body>\n'
29 '</body>\n'
30 '</html>\n')) 33 '</html>\n'))
31 34
32 def test_html_diff_same(self): 35 def test_html_diff_same(self):
33 self.assertEqual( 36 self.assertEqual(
34 html_diff_body(['one line\n'], ['one line\n']), 37 html_diff_body(['one line\n'], ['one line\n']),
qyearsley 2017/02/15 00:02:22 Rather than continuing to use html_diff_body, you
tkent 2017/02/15 05:08:09 Done.
35 'one line\n') 38 '<tr><th>1<th>1<td>one line\n</tr>')
36 self.assertEqual( 39 self.assertEqual(
37 html_diff_body(['<script>\n'], ['<script>\n']), 40 html_diff_body(['<script>\n'], ['<script>\n']),
38 '&lt;script&gt;\n') 41 '<tr><th>1<th>1<td>&lt;script&gt;\n</tr>')
39 42
40 def test_html_diff_delete(self): 43 def test_html_diff_delete(self):
41 self.assertEqual( 44 self.assertEqual(
42 html_diff_body(['one line\n'], []), 45 html_diff_body(['one line\n'], []),
43 '<span class="del">one line\n</span>') 46 '<tr><th>1<th><td class="del">one line\n</tr>')
44 self.assertEqual( 47 self.assertEqual(
45 html_diff_body(['</pre>\n'], []), 48 html_diff_body(['</pre>\n'], []),
46 '<span class="del">&lt;/pre&gt;\n</span>') 49 '<tr><th>1<th><td class="del">&lt;/pre&gt;\n</tr>')
47 50
48 def test_html_diff_insert(self): 51 def test_html_diff_insert(self):
49 self.assertEqual( 52 self.assertEqual(
50 html_diff_body([], ['one line\n']), 53 html_diff_body([], ['one line\n']),
51 '<span class="add">one line\n</span>') 54 '<tr><th><th>1<td class="add">one line\n</tr>')
52 self.assertEqual( 55 self.assertEqual(
53 html_diff_body([], ['<!--\n']), 56 html_diff_body([], ['<!--\n']),
54 '<span class="add">&lt;!--\n</span>') 57 '<tr><th><th>1<td class="add">&lt;!--\n</tr>')
55 58
56 def test_html_diff_ending_newline(self): 59 def test_html_diff_ending_newline(self):
57 self.assertEqual( 60 self.assertEqual(
58 html_diff_body(['one line'], ['one line\n']), 61 html_diff_body(['one line'], ['one line\n']),
59 '<span class="del">one line</span><span class="add">one line\n</span >') 62 '<tr><th>1<th><td class="del">one line</tr><tr><th><th>1<td class="a dd">one line\n</tr>')
60 63
61 def test_html_diff_replace_multiple_lines(self): 64 def test_html_diff_replace_multiple_lines(self):
62 a_lines = [ 65 a_lines = [
63 '1. Beautiful is better than ugly.\n', 66 '1. Beautiful is better than ugly.\n',
64 '2. Explicit is better than implicit.\n', 67 '2. Explicit is better than implicit.\n',
65 '3. Simple is better than complex.\n', 68 '3. Simple is better than complex.\n',
66 '4. Complex is better than complicated.\n', 69 '4. Complex is better than complicated.\n',
67 ] 70 ]
68 b_lines = [ 71 b_lines = [
69 '1. Beautiful is better than ugly.\n', 72 '1. Beautiful is better than ugly.\n',
70 '3. Simple is better than complex.\n', 73 '3. Simple is better than complex.\n',
71 '4. Complicated is better than complex.\n', 74 '4. Complicated is better than complex.\n',
72 '5. Flat is better than nested.\n', 75 '5. Flat is better than nested.\n',
73 ] 76 ]
74 self.assertEqual(html_diff_body(a_lines, b_lines), ( 77 self.assertEqual(html_diff_body(a_lines, b_lines), (
75 '1. Beautiful is better than ugly.\n' 78 '<tr><th>1<th>1<td>1. Beautiful is better than ugly.\n</tr>'
76 '<span class="del">2. Explicit is better than implicit.\n' 79 '<tr><th>2<th><td class="del">2. Explicit is better than implicit.\n </tr>'
77 '3. Simple is better than complex.\n' 80 '<tr><th>3<th><td class="del">3. Simple is better than complex.\n</t r>'
78 '4. Complex is better than complicated.\n' 81 '<tr><th>4<th><td class="del">4. Complex is better than complicated. \n</tr>'
79 '</span><span class="add">3. Simple is better than complex.\n' 82 '<tr><th><th>2<td class="add">3. Simple is better than complex.\n< /tr>'
80 '4. Complicated is better than complex.\n' 83 '<tr><th><th>3<td class="add">4. Complicated is better than complex. \n</tr>'
81 '5. Flat is better than nested.\n' 84 '<tr><th><th>4<td class="add">5. Flat is better than nested.\n</tr>' ))
82 '</span>')) 85
86 def test_html_diff_context(self):
87 a_lines = [
88 'line1\n',
89 'line2\n',
90 'line3\n',
91 'line4\n',
92 'line5\n',
93 'line6\n',
94 'line7\n',
95 'line8\n',
96 'line9a\n',
97 'line10\n',
98 'line11\n',
99 'line12\n',
100 'line13\n',
101 'line14\n',
102 'line15a\n',
103 'line16\n',
104 'line17\n',
105 'line18\n',
106 'line19\n',
107 'line20\n',
108 'line21\n',
109 'line22\n',
110 'line23\n',
111 ]
112 b_lines = [
113 'line1\n',
114 'line2\n',
115 'line3\n',
116 'line4\n',
117 'line5\n',
118 'line6\n',
119 'line7\n',
120 'line8\n',
121 'line9b\n',
122 'line10\n',
123 'line11\n',
124 'line12\n',
125 'line13\n',
126 'line14\n',
127 'line15b\n',
128 'line16\n',
129 'line17\n',
130 'line18\n',
131 'line19\n',
132 'line20\n',
133 'line21\n',
134 'line22\n',
135 'line23\n',
136 ]
137 self.assertEqual(html_diff_body(a_lines, b_lines), (
138 '<tr><td colspan=3>\n\n</tr>'
139 '<tr><th>6<th>6<td>line6\n</tr>'
140 '<tr><th>7<th>7<td>line7\n</tr>'
141 '<tr><th>8<th>8<td>line8\n</tr>'
142 '<tr><th>9<th><td class="del">line9a\n</tr>'
143 '<tr><th><th>9<td class="add">line9b\n</tr>'
144 '<tr><th>10<th>10<td>line10\n</tr>'
145 '<tr><th>11<th>11<td>line11\n</tr>'
146 '<tr><th>12<th>12<td>line12\n</tr>'
147 '<tr><th>13<th>13<td>line13\n</tr>'
148 '<tr><th>14<th>14<td>line14\n</tr>'
149 '<tr><th>15<th><td class="del">line15a\n</tr>'
150 '<tr><th><th>15<td class="add">line15b\n</tr>'
151 '<tr><th>16<th>16<td>line16\n</tr>'
152 '<tr><th>17<th>17<td>line17\n</tr>'
153 '<tr><th>18<th>18<td>line18\n</tr>'
154 '<tr><td colspan=3>\n\n</tr>'))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698