Пример #1
0
 def test_empty_lines_with_insertion(self):
     self.assertEqual(list(side_by_side_diff("\n\n\n",
                                             "\n\nnew\n")),
                      [("", ""),
                       ("", ""),
                       ("", "<ins>new</ins>"),
                       ("", "")])
Пример #2
0
 def test_empty_lines_with_deletion(self):
     self.assertEqual(list(side_by_side_diff("\n\nold\n",
                                             "\n\n\n")),
                      [("", ""),
                       ("", ""),
                       ("<del>old</del>", ""),
                       ("", "")])
Пример #3
0
    def test_context_excludes_bordering_unchanged(self):
        lines = [("line %d" % i) for i in range(10)]
        changed_lines = lines[:4] + ['one line', 'another line'] + lines[6:]

        diff = side_by_side_diff('\n'.join(lines), '\n'.join(changed_lines))
        diff, diff_clone = itertools.tee(diff)

        self.assertEqual(list(context_diff(diff)),
                         [(2, 2, list(diff_clone)[2:8])])
Пример #4
0
    def test_context_excludes_final_unchanged(self):
        lines = [("line %d" % i) for i in range(5)]
        changed_lines = ['one line', 'another line'] + lines[2:]

        diff = side_by_side_diff('\n'.join(lines), '\n'.join(changed_lines))
        diff, diff_clone = itertools.tee(diff)

        self.assertEqual(list(context_diff(diff)),
                         [(0, 0, list(diff_clone)[:-1])])
Пример #5
0
    def test_context_excludes_initial_unchanged(self):
        lines = [("line %d" % i) for i in range(5)]
        changed_lines = lines[:3] + ['one line', 'another line']

        diff = side_by_side_diff('\n'.join(lines), '\n'.join(changed_lines))
        diff, diff_clone = itertools.tee(diff)

        self.assertEqual(list(context_diff(diff)),
                         [(1, 1, list(diff_clone)[1:])])
Пример #6
0
    def test_user_defined_context(self):
        lines = [("line %d" % i) for i in range(12)]
        changed_lines = lines[:5] + ['one line', 'another line'] + lines[7:]

        diff = side_by_side_diff('\n'.join(lines), '\n'.join(changed_lines))
        diff, diff_clone = itertools.tee(diff)

        self.assertEqual(list(context_diff(diff, context=4)),
                         [(1, 1, list(diff_clone)[1:11])])
Пример #7
0
    def test_bordering_contexts_are_merged(self):
        lines = [("line %d" % i) for i in range(12)]
        changed_lines = (lines[:3] + ['one line'] + lines[4:8]
                         + ['another one'] + lines[9:])

        diff = side_by_side_diff('\n'.join(lines), '\n'.join(changed_lines))
        diff, diff_clone = itertools.tee(diff)

        self.assertEqual(list(context_diff(diff)),
                         [(1, 1, list(diff_clone)[1:11])])
Пример #8
0
    def test_deletion_context(self):
        lines = [("line %d" % i) for i in range(15)]
        changed_lines = (lines[:3] + lines[5:10]
                         + ['third line', 'forth line'] + lines[12:])

        diff = side_by_side_diff('\n'.join(lines), '\n'.join(changed_lines))
        diff, diff_clone = itertools.tee(diff)
        diff_clone = list(diff_clone)

        self.assertEqual(list(context_diff(diff)),
                         [(1, 1, diff_clone[1:7]),
                          (8, 6, diff_clone[8:14])])
Пример #9
0
    def test_multiple_contexts(self):
        lines = [("line %d" % i) for i in range(20)]
        changed_lines = (lines[:4] + ['one line', 'another line'] + lines[6:14]
                         + ['third line', 'forth line'] + lines[16:])

        diff = side_by_side_diff('\n'.join(lines), '\n'.join(changed_lines))
        diff, diff_clone = itertools.tee(diff)
        diff_clone = list(diff_clone)

        self.assertEqual(list(context_diff(diff)),
                         [(2, 2, diff_clone[2:8]),
                          (12, 12, diff_clone[12:18])])
Пример #10
0
    def test_insertion_context(self):
        lines = [("line %d" % i) for i in range(13)]
        changed_lines = (lines[:3] + ['one line', 'another line'] + lines[3:8]
                         + ['third line', 'forth line'] + lines[10:])

        diff = side_by_side_diff('\n'.join(lines), '\n'.join(changed_lines))
        diff, diff_clone = itertools.tee(diff)
        diff_clone = list(diff_clone)

        self.assertEqual(list(context_diff(diff)),
                         [(1, 1, diff_clone[1:7]),
                          (6, 8, diff_clone[8:14])])
Пример #11
0
    def test_full_change_merged_contexts(self):
        lines = [("line %d" % i) for i in range(30)]
        changed_lines = (lines[:3] + ['one line', 'another line'] + lines[5:9]
                         + ['third line', 'forth line'] + lines[9:13]
                         + ['one more line', 'yet another'] + lines[15:19]
                         + lines[21:25]
                         + ['nearly last', 'possibly last line'] + lines[27:])

        diff = side_by_side_diff('\n'.join(lines), '\n'.join(changed_lines))
        diff, diff_clone = itertools.tee(diff)
        diff_clone = list(diff_clone)

        self.assertEqual(list(context_diff(diff)),
                         [(1, 1, diff_clone[1:31])])
Пример #12
0
    def test_full_change_contexts(self):
        lines = [("line %d" % i) for i in range(34)]
        changed_lines = (lines[:3] + ['one line', 'another line'] + lines[5:10]
                         + ['third line', 'forth line'] + lines[10:15]
                         + ['one more line', 'yet another'] + lines[17:22]
                         + lines[24:29]
                         + ['nearly last', 'possibly last line'] + lines[31:])

        diff = side_by_side_diff('\n'.join(lines), '\n'.join(changed_lines))
        diff, diff_clone = itertools.tee(diff)
        diff_clone = list(diff_clone)

        self.assertEqual(list(context_diff(diff)),
                         [(1, 1, diff_clone[1:7]),
                          (8, 8, diff_clone[8:14]),
                          (13, 15, diff_clone[15:21]),
                          (20, 22, diff_clone[22:28]),
                          (27, 27, diff_clone[29:35])])
Пример #13
0
    def render(self, context):
        try:
            old_value = self.old_value.resolve(context)
        except VariableDoesNotExist:
            raise TemplateSyntaxError('"cache" tag got an unknown variable: %r'
                                      % self.old_value)
        try:
            new_value = self.new_value.resolve(context)
        except VariableDoesNotExist:
            raise TemplateSyntaxError('"cache" tag got an unknown variable: %r'
                                      % self.old_value)

        old_text = force_unicode(old_value) if old_value else ''
        new_text = force_unicode(new_value) if new_value else ''
        diff = side_by_side_diff(old_text, new_text)
        contextual_diff = context_diff(diff, context=self.context_width)

        context.push()
        diff_str = render_to_string('wikify/contextual_diff_tr.html',
                                    {'context_diff': contextual_diff},
                                    context)
        context.pop()
        return diff_str
Пример #14
0
 def test_line_insertion_at_end(self):
     self.assertEqual(list(side_by_side_diff("line",
                                             "line\nnew text")),
                      [("line", "line"),
                       (None, "<ins>new text</ins>")])
Пример #15
0
 def test_two_lines_without_change(self):
     self.assertEqual(list(side_by_side_diff("text\nline",
                                             "text\nline")),
                      [("text", "text"),
                       ("line", "line")])
Пример #16
0
 def test_line_insertion_at_beginning(self):
     self.assertEqual(list(side_by_side_diff("line",
                                             "new text\nline")),
                      [(None, "<ins>new text</ins>"),
                       ("line", "line")])
Пример #17
0
 def test_that_inserted_newline_keeps_changes_minimal(self):
     self.assertEqual(list(side_by_side_diff("a long line with words",
                                             "a long line\nwith words")),
                      [("a long line<del> </del>with words", "a long line"),
                       (None, "with words")])
Пример #18
0
 def test_two_lines_with_one_change(self):
     self.assertEqual(list(side_by_side_diff("old text\nline",
                                             "new text\nline")),
                      [("<del>old</del> text", "<ins>new</ins> text"),
                       ("line", "line")])
Пример #19
0
 def test_text_with_full_deletion(self):
     self.assertEqual(list(side_by_side_diff("old",
                                             "")),
                      [("<del>old</del>", None)])
Пример #20
0
 def test_line_with_full_deletion(self):
     self.assertEqual(list(side_by_side_diff("old\n",
                                             "\n")),
                      [("<del>old</del>", ""),
                       ("", "")])
Пример #21
0
 def test_empty_text_with_insertion(self):
     self.assertEqual(list(side_by_side_diff("",
                                             "new")),
                      [(None, "<ins>new</ins>")])
Пример #22
0
 def test_inserted_newline_with_text_change(self):
     self.assertEqual(list(side_by_side_diff("a long line with words",
                                             "a long line\nand words")),
                      [("a long line<del> with</del> words", "a long line"),
                       (None, "<ins>and</ins> words")])
Пример #23
0
 def test_one_line_without_change(self):
     self.assertEqual(list(side_by_side_diff("text",
                                             "text")),
                      [("text", "text")])
Пример #24
0
 def test_empty_text_without_change_has_no_diff(self):
     self.assertEqual(list(side_by_side_diff("",
                                             "")),
                      [])
Пример #25
0
 def test_small_change_is_included(self):
     diff = side_by_side_diff("old text",
                              "new text")
     diff, diff_clone = itertools.tee(diff)
     self.assertEqual(list(context_diff(diff)),
                      [(0, 0, list(diff_clone))])
Пример #26
0
 def test_multi_line_change_is_included(self):
     diff = side_by_side_diff("old text\nline\nanother line",
                              "new text\nline\nsome line")
     diff, diff_clone = itertools.tee(diff)
     self.assertEqual(list(context_diff(diff)),
                      [(0, 0, list(diff_clone))])
Пример #27
0
 def test_one_line_with_deletion(self):
     self.assertEqual(list(side_by_side_diff("old text",
                                             "text")),
                      [("<del>old </del>text", "text")])
Пример #28
0
 def test_line_insertion_in_middle(self):
     self.assertEqual(list(side_by_side_diff("line\nanother line",
                                             "line\nnew text\nanother line")),
                      [("line", "line"),
                       (None, "<ins>new text</ins>"),
                       ("another line", "another line")])
Пример #29
0
 def test_one_line_with_insertion(self):
     self.assertEqual(list(side_by_side_diff("text",
                                             "new text")),
                      [("text", "<ins>new </ins>text")])