Пример #1
0
    def _init_diff(self):
        """Return a minimal diff contains all required samples
            header
            --- old
            +++ new
            hunk header
            @@ -1,5 +1,5 @@
            -hhello
            +helloo
            +spammm
             world
            -garb
            -Again
            -	tabbed
            +again
            + spaced
        """

        hunk = ydiff.Hunk(['hunk header\n'], '@@ -1,5 +1,5 @@\n', (1, 5),
                          (1, 5))
        hunk.append(('-', 'hhello\n'))
        hunk.append(('+', 'helloo\n'))
        hunk.append(('+', 'spammm\n'))
        hunk.append((' ', 'world\n'))
        hunk.append(('-', 'garb\n'))
        hunk.append(('-', 'Again\n'))
        hunk.append(('-', '	tabbed\n'))
        hunk.append(('+', 'again\n'))
        hunk.append(('+', ' spaced\n'))
        diff = ydiff.UnifiedDiff(['header\n'], '--- old\n', '+++ new\n',
                                 [hunk])
        return diff
Пример #2
0
    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')
Пример #3
0
    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')
Пример #4
0
    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')
Пример #5
0
 def test_get_new_text(self):
     hunk = ydiff.Hunk([], '@@ -1,2 +1,2 @@', (1, 2), (1, 2))
     hunk.append(('-', 'foo\n'))
     hunk.append(('+', 'bar\n'))
     hunk.append((' ', 'common\n'))
     self.assertEqual(hunk._get_new_text(), ['bar\n', 'common\n'])