def __test_markup_side_by_side_neg_width(self): diff = self._init_diff() marker = ydiff.DiffMarker(side_by_side=True, width=-1) out = list(marker.markup(diff)) self.assertEqual(len(out), 11) self.assertEqual(out[0], '\x1b[36mheader\n\x1b[0m') self.assertEqual(out[1], '\x1b[33m--- old\n\x1b[0m') self.assertEqual(out[2], '\x1b[33m+++ new\n\x1b[0m') self.assertEqual(out[3], '\x1b[1;36mhunk header\n\x1b[0m') self.assertEqual(out[4], '\x1b[1;34m@@ -1,4 +1,4 @@\n\x1b[0m') self.assertEqual( out[5], '\x1b[33m1\x1b[0m ' '\x1b[31m\x1b[7m\x1b[31mh\x1b[0m\x1b[31mhello\x1b[0m ' + (' ' * 74) + '\x1b[0m\x1b[33m1\x1b[0m ' '\x1b[32mhello\x1b[7m\x1b[32mo\x1b[0m\x1b[32m\x1b[0m\n') self.assertEqual( out[6], '\x1b[33m ' '\x1b[0m ' + (' ' * 80) + '\x1b[0m\x1b[33m2\x1b[0m ' '\x1b[32mspammm\x1b[0m\n') self.assertEqual( out[7], '\x1b[33m2\x1b[0m ' '\x1b[0mworld\x1b[0m ' + (' ' * 75) + '\x1b[0m\x1b[33m3\x1b[0m ' '\x1b[0mworld\x1b[0m\n') self.assertEqual( out[8], '\x1b[33m3\x1b[0m ' '\x1b[1;31mgarb\x1b[0m ' '\x1b[0m\x1b[33m ' '\x1b[0m \n') self.assertEqual( out[9], '\x1b[33m4\x1b[0m ' '\x1b[31m\x1b[4m\x1b[31mA\x1b[0m\x1b[31mgain\x1b[0m ' + (' ' * 75) + '\x1b[0m\x1b[33m4\x1b[0m ' '\x1b[32m\x1b[4m\x1b[32ma\x1b[0m\x1b[32mgain\x1b[0m\n')
def test_markup_traditional_hunk_header(self): hunk = ydiff.Hunk(['hunk header\n'], '@@ -0 +0 @@\n', (0, 0), (0, 0)) diff = ydiff.UnifiedDiff([], '--- old\n', '+++ new\n', [hunk]) marker = ydiff.DiffMarker() out = list(marker.markup(diff)) self.assertEqual(len(out), 4) self.assertEqual(out[0], '\x1b[33m--- old\n\x1b[0m') self.assertEqual(out[1], '\x1b[33m+++ new\n\x1b[0m') self.assertEqual(out[2], '\x1b[1;36mhunk header\n\x1b[0m') self.assertEqual(out[3], '\x1b[1;34m@@ -0 +0 @@\n\x1b[0m')
def test_markup_side_by_side_padded(self): diff = self._init_diff() marker = ydiff.DiffMarker(side_by_side=True, width=7) out = list(marker.markup(diff)) self.assertEqual(len(out), 11) sys.stdout.write('\n') for markup in out: sys.stdout.write(markup) self.assertEqual(out[0], '\x1b[36mheader\n\x1b[0m') self.assertEqual(out[1], '\x1b[33m--- old\n\x1b[0m') self.assertEqual(out[2], '\x1b[33m+++ new\n\x1b[0m') self.assertEqual(out[3], '\x1b[1;36mhunk header\n\x1b[0m') self.assertEqual(out[4], '\x1b[1;34m@@ -1,5 +1,5 @@\n\x1b[0m') self.assertEqual( out[5], '\x1b[33m1\x1b[0m ' '\x1b[31m\x1b[7m\x1b[31mh\x1b[0m\x1b[31mhello\x1b[0m ' '\x1b[0m\x1b[33m1\x1b[0m ' '\x1b[32mhello\x1b[7m\x1b[32mo\x1b[0m\n') self.assertEqual( out[6], '\x1b[33m ' '\x1b[0m ' '\x1b[0m\x1b[33m2\x1b[0m ' '\x1b[32mspammm\x1b[0m\n') self.assertEqual( out[7], '\x1b[33m2\x1b[0m ' '\x1b[0mworld\x1b[0m ' '\x1b[0m\x1b[33m3\x1b[0m ' '\x1b[0mworld\x1b[0m\n') self.assertEqual( out[8], '\x1b[33m3\x1b[0m ' '\x1b[1;31mgarb\x1b[0m ' '\x1b[0m\x1b[33m ' '\x1b[0m \n') self.assertEqual( out[9], '\x1b[33m4\x1b[0m ' '\x1b[31m\x1b[4m\x1b[31mA\x1b[0m\x1b[31mgain\x1b[0m ' '\x1b[0m\x1b[33m4\x1b[0m ' '\x1b[32m\x1b[4m\x1b[32ma\x1b[0m\x1b[32mgain\x1b[0m\n') self.assertEqual( out[10], '\x1b[33m5\x1b[0m ' '\x1b[31m\x1b[7m\x1b[31m \x1b[0m\x1b[1;35m>\x1b[0m ' '\x1b[0m\x1b[33m5\x1b[0m ' '\x1b[32m\x1b[7m\x1b[32m spaced\x1b[0m\n')
def test_markup_traditional_new_changed(self): hunk = ydiff.Hunk([], '@@ -0,0 +1 @@\n', (0, 0), (1, 0)) hunk.append(('+', 'spam\n')) diff = ydiff.UnifiedDiff([], '--- old\n', '+++ new\n', [hunk]) marker = ydiff.DiffMarker() out = list(marker.markup(diff)) self.assertEqual(len(out), 4) self.assertEqual(out[0], '\x1b[33m--- old\n\x1b[0m') self.assertEqual(out[1], '\x1b[33m+++ new\n\x1b[0m') self.assertEqual(out[2], '\x1b[1;34m@@ -0,0 +1 @@\n\x1b[0m') self.assertEqual(out[3], '\x1b[32m+spam\n\x1b[0m')
def test_markup_traditional_both_changed(self): hunk = ydiff.Hunk([], '@@ -1,2 +1,2 @@\n', (1, 2), (1, 2)) hunk.append(('-', 'hella\n')) hunk.append(('+', 'hello\n')) hunk.append((' ', 'common\n')) diff = ydiff.UnifiedDiff([], '--- old\n', '+++ new\n', [hunk]) marker = ydiff.DiffMarker() out = list(marker.markup(diff)) self.assertEqual(len(out), 6) self.assertEqual(out[0], '\x1b[33m--- old\n\x1b[0m') self.assertEqual(out[1], '\x1b[33m+++ new\n\x1b[0m') self.assertEqual(out[2], '\x1b[1;34m@@ -1,2 +1,2 @@\n\x1b[0m') self.assertEqual( out[3], '\x1b[1;31m-\x1b[0m\x1b[31mhell' '\x1b[4m\x1b[31ma\x1b[0m\x1b[31m\n\x1b[0m') self.assertEqual( out[4], '\x1b[32m+\x1b[0m\x1b[32mhell' '\x1b[4m\x1b[32mo\x1b[0m\x1b[32m\n\x1b[0m') self.assertEqual(out[5], '\x1b[0m common\n\x1b[0m')