[meld] test_filediff: New test for new text filtering approach



commit 75d5258fd50543136437ca8217b4ff46b2ba23cb
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Dec 6 09:21:41 2015 +1000

    test_filediff: New test for new text filtering approach

 test/test_filediff.py |   87 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)
---
diff --git a/test/test_filediff.py b/test/test_filediff.py
new file mode 100644
index 0000000..0e605e2
--- /dev/null
+++ b/test/test_filediff.py
@@ -0,0 +1,87 @@
+
+import pytest
+
+import mock
+from gi.repository import Gtk
+
+from meld.filediff import FileDiff
+from meld.filters import FilterEntry
+
+
+ pytest mark parametrize("text, ignored_ranges", [
+    #    0123456789012345678901234567890123456789012345678901234567890123456789
+    # Matching without groups
+    (
+        "# asdasdasdasdsad",
+        [(0, 17)],
+    ),
+    # Matching with single group
+    (
+        "asdasdasdasdsab",
+        [(1, 14)],
+    ),
+    # Matching with multiple groups
+    (
+        "xasdyasdz",
+        [(1, 4), (5, 8)],
+    ),
+    # Matching with multiple partially overlapping filters
+    (
+        "qaqxqbyqzq",
+        [(2, 6), (7, 8)],
+    ),
+    # Matching with multiple fully overlapping filters
+    (
+        "qaqxqybqzq",
+        [(2, 8)],
+    ),
+    # Matching with and without groups, with single dominated match
+    (
+        "# asdasdasdasdsab",
+        [(0, 17)],
+    ),
+    # Non-matching with groups
+    (
+        "xasdyasdx",
+        [],
+    ),
+])
+def test_filter_text(text, ignored_ranges):
+    filter_patterns = [
+        '#.*',
+        '/\*.*\*/',
+        'a(.*)b',
+        'x(.*)y(.*)z',
+    ]
+    filters = [
+        FilterEntry.new_from_gsetting(("name", True, f), FilterEntry.REGEX)
+        for f in filter_patterns
+    ]
+
+    filediff = mock.MagicMock()
+    filediff.text_filters = filters
+    filter_text = FileDiff._filter_text.__func__
+
+    buf = Gtk.TextBuffer()
+    buf.create_tag("inline")
+    buf.create_tag("dimmed")
+    buf.set_text(text)
+    start, end = buf.get_bounds()
+
+    text = filter_text(
+        filediff, buf.get_text(start, end, False), buf, start, end)
+
+    # Find ignored ranges
+    tag = buf.get_tag_table().lookup("dimmed")
+    toggles = []
+    it = start.copy()
+    if it.toggles_tag(tag):
+        toggles.append(it.get_offset())
+    while it.forward_to_tag_toggle(tag):
+        toggles.append(it.get_offset())
+    toggles = zip(toggles[::2], toggles[1::2])
+
+    print("Text:", text)
+    print("Toggles:", toggles)
+
+    assert toggles == ignored_ranges


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]