|
@@ -74,26 +74,136 @@ class TestPatchStream(unittest.TestCase):
|
74
|
74
|
|
75
|
75
|
class TestHunk(unittest.TestCase):
|
76
|
76
|
|
77
|
|
- def test_mdiff(self):
|
78
|
|
- pass
|
79
|
|
-
|
80
|
77
|
def test_get_old_text(self):
|
81
|
|
- pass
|
|
78
|
+ hunk = cdiff.Hunk([], '@@ -1,2 +1,2 @@', (1,2), (1,2))
|
|
79
|
+ hunk.append(('-', 'foo\n'))
|
|
80
|
+ hunk.append(('+', 'bar\n'))
|
|
81
|
+ hunk.append((' ', 'common\n'))
|
|
82
|
+ self.assertEqual(
|
|
83
|
+ hunk._get_old_text(),
|
|
84
|
+ ['foo\n', 'common\n'])
|
82
|
85
|
|
83
|
86
|
def test_get_new_text(self):
|
84
|
|
- pass
|
|
87
|
+ hunk = cdiff.Hunk([], '@@ -1,2 +1,2 @@', (1,2), (1,2))
|
|
88
|
+ hunk.append(('-', 'foo\n'))
|
|
89
|
+ hunk.append(('+', 'bar\n'))
|
|
90
|
+ hunk.append((' ', 'common\n'))
|
|
91
|
+ self.assertEqual(
|
|
92
|
+ hunk._get_new_text(),
|
|
93
|
+ ['bar\n', 'common\n'])
|
85
|
94
|
|
86
|
95
|
|
87
|
96
|
class TestDiff(unittest.TestCase):
|
88
|
97
|
|
|
98
|
+ def _init_diff(self):
|
|
99
|
+ hunk = cdiff.Hunk([], '@@ -1,2 +1,2 @@\n', (1,2), (1,2))
|
|
100
|
+ hunk.append(('-', 'hella\n'))
|
|
101
|
+ hunk.append(('+', 'hello\n'))
|
|
102
|
+ hunk.append((' ', 'world\n'))
|
|
103
|
+ diff = cdiff.Diff(['header\n'], '--- old\n', '+++ new\n', [hunk])
|
|
104
|
+ return diff
|
|
105
|
+
|
89
|
106
|
def test_markup_mix(self):
|
90
|
|
- pass
|
|
107
|
+ line = 'foo \x00-del\x01 \x00+add\x01 \x00^chg\x01 bar'
|
|
108
|
+ base_color = 'red'
|
|
109
|
+ diff = cdiff.Diff(None, None, None, None)
|
|
110
|
+ self.assertEqual(diff._markup_mix(line, base_color),
|
|
111
|
+ '\x1b[31mfoo \x1b[7m\x1b[31mdel\x1b[0m\x1b[31m '
|
|
112
|
+ '\x1b[7m\x1b[31madd\x1b[0m\x1b[31m '
|
|
113
|
+ '\x1b[4m\x1b[31mchg\x1b[0m\x1b[31m bar\x1b[0m')
|
91
|
114
|
|
92
|
115
|
def test_markup_traditional(self):
|
93
|
|
- pass
|
94
|
|
-
|
95
|
|
- def test_markup_side_by_side(self):
|
96
|
|
- pass
|
|
116
|
+ diff = self._init_diff()
|
|
117
|
+ out = list(diff.markup_traditional())
|
|
118
|
+ self.assertEqual(len(out), 7)
|
|
119
|
+
|
|
120
|
+ sys.stdout.write('\n')
|
|
121
|
+ for markup in out:
|
|
122
|
+ sys.stdout.write(markup)
|
|
123
|
+
|
|
124
|
+ self.assertEqual(out[0], '\x1b[36mheader\n\x1b[0m')
|
|
125
|
+ self.assertEqual(out[1], '\x1b[33m--- old\n\x1b[0m')
|
|
126
|
+ self.assertEqual(out[2], '\x1b[33m+++ new\n\x1b[0m')
|
|
127
|
+ self.assertEqual(out[3], '\x1b[1;34m@@ -1,2 +1,2 @@\n\x1b[0m')
|
|
128
|
+ self.assertEqual(out[4],
|
|
129
|
+ '\x1b[1;31m-\x1b[0m\x1b[31mhell\x1b[4m'
|
|
130
|
+ '\x1b[31ma\x1b[0m\x1b[31m\n\x1b[0m')
|
|
131
|
+ self.assertEqual(out[5],
|
|
132
|
+ '\x1b[1;32m+\x1b[0m\x1b[32mhell\x1b[4m'
|
|
133
|
+ '\x1b[32mo\x1b[0m\x1b[32m\n\x1b[0m')
|
|
134
|
+ self.assertEqual(out[6], '\x1b[0m world\n\x1b[0m')
|
|
135
|
+
|
|
136
|
+ def test_markup_side_by_side_padded(self):
|
|
137
|
+ diff = self._init_diff()
|
|
138
|
+ out = list(diff.markup_side_by_side(6))
|
|
139
|
+ self.assertEqual(len(out), 6)
|
|
140
|
+
|
|
141
|
+ sys.stdout.write('\n')
|
|
142
|
+ for markup in out:
|
|
143
|
+ sys.stdout.write(markup)
|
|
144
|
+
|
|
145
|
+ self.assertEqual(out[0], '\x1b[36mheader\n\x1b[0m')
|
|
146
|
+ self.assertEqual(out[1], '\x1b[33m--- old\n\x1b[0m')
|
|
147
|
+ self.assertEqual(out[2], '\x1b[33m+++ new\n\x1b[0m')
|
|
148
|
+ self.assertEqual(out[3], '\x1b[1;34m@@ -1,2 +1,2 @@\n\x1b[0m')
|
|
149
|
+ self.assertEqual(out[4],
|
|
150
|
+ '\x1b[33m1\x1b[0m '
|
|
151
|
+ '\x1b[31mhell\x1b[4m\x1b[31ma\x1b[0m\x1b[31m\x1b[0m '
|
|
152
|
+ '\x1b[0m\x1b[33m1\x1b[0m '
|
|
153
|
+ '\x1b[32mhell\x1b[4m\x1b[32mo\x1b[0m\x1b[32m\x1b[0m\n')
|
|
154
|
+ self.assertEqual(out[5],
|
|
155
|
+ '\x1b[33m2\x1b[0m '
|
|
156
|
+ '\x1b[0mworld\x1b[0m '
|
|
157
|
+ '\x1b[0m\x1b[33m2\x1b[0m '
|
|
158
|
+ '\x1b[0mworld\x1b[0m\n')
|
|
159
|
+
|
|
160
|
+ def test_markup_side_by_side_off_by_one(self):
|
|
161
|
+ diff = self._init_diff()
|
|
162
|
+ out = list(diff.markup_side_by_side(5))
|
|
163
|
+ self.assertEqual(len(out), 6)
|
|
164
|
+
|
|
165
|
+ sys.stdout.write('\n')
|
|
166
|
+ for markup in out:
|
|
167
|
+ sys.stdout.write(markup)
|
|
168
|
+
|
|
169
|
+ self.assertEqual(out[0], '\x1b[36mheader\n\x1b[0m')
|
|
170
|
+ self.assertEqual(out[1], '\x1b[33m--- old\n\x1b[0m')
|
|
171
|
+ self.assertEqual(out[2], '\x1b[33m+++ new\n\x1b[0m')
|
|
172
|
+ self.assertEqual(out[3], '\x1b[1;34m@@ -1,2 +1,2 @@\n\x1b[0m')
|
|
173
|
+ self.assertEqual(out[4],
|
|
174
|
+ '\x1b[33m1\x1b[0m '
|
|
175
|
+ '\x1b[31mhell\x1b[4m\x1b[31ma\x1b[0m '
|
|
176
|
+ '\x1b[0m\x1b[33m1\x1b[0m '
|
|
177
|
+ '\x1b[32mhell\x1b[4m\x1b[32mo\x1b[0m\n')
|
|
178
|
+ self.assertEqual(out[5],
|
|
179
|
+ '\x1b[33m2\x1b[0m '
|
|
180
|
+ '\x1b[0mworld\x1b[0m '
|
|
181
|
+ '\x1b[0m\x1b[33m2\x1b[0m '
|
|
182
|
+ '\x1b[0mworld\x1b[0m\n')
|
|
183
|
+
|
|
184
|
+ def test_markup_side_by_side_wrapped(self):
|
|
185
|
+ diff = self._init_diff()
|
|
186
|
+ out = list(diff.markup_side_by_side(4))
|
|
187
|
+ self.assertEqual(len(out), 6)
|
|
188
|
+
|
|
189
|
+ sys.stdout.write('\n')
|
|
190
|
+ for markup in out:
|
|
191
|
+ sys.stdout.write(markup)
|
|
192
|
+
|
|
193
|
+ self.assertEqual(out[0], '\x1b[36mheader\n\x1b[0m')
|
|
194
|
+ self.assertEqual(out[1], '\x1b[33m--- old\n\x1b[0m')
|
|
195
|
+ self.assertEqual(out[2], '\x1b[33m+++ new\n\x1b[0m')
|
|
196
|
+ self.assertEqual(out[3], '\x1b[1;34m@@ -1,2 +1,2 @@\n\x1b[0m')
|
|
197
|
+ self.assertEqual(out[4],
|
|
198
|
+ '\x1b[33m1\x1b[0m '
|
|
199
|
+ '\x1b[31mhel\x1b[0m\x1b[1;35m>\x1b[0m '
|
|
200
|
+ '\x1b[0m\x1b[33m1\x1b[0m '
|
|
201
|
+ '\x1b[32mhel\x1b[0m\x1b[1;35m>\x1b[0m\n')
|
|
202
|
+ self.assertEqual(out[5],
|
|
203
|
+ '\x1b[33m2\x1b[0m '
|
|
204
|
+ '\x1b[0mwor\x1b[0m\x1b[1;35m>\x1b[0m '
|
|
205
|
+ '\x1b[0m\x1b[33m2\x1b[0m '
|
|
206
|
+ '\x1b[0mwor\x1b[0m\x1b[1;35m>\x1b[0m\n')
|
97
|
207
|
|
98
|
208
|
|
99
|
209
|
class TestUdiff(unittest.TestCase):
|