summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2018-08-24 13:27:25 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2018-08-30 12:11:45 +0200
commit62e39ed058ce340ead5d878a386caa9e65676f63 (patch)
tree88471f0e8e0f4dfac54f9401633a552370eccd81 /tests
parent176e38508d077d179b73bae8fde8c350db46d606 (diff)
tests: py: Fix coloring of differences
This was surprisingly hard to get right, but this should do the trick. Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'tests')
-rwxr-xr-xtests/py/nft-test.py31
1 files changed, 14 insertions, 17 deletions
diff --git a/tests/py/nft-test.py b/tests/py/nft-test.py
index e4367adc..1b7e04c9 100755
--- a/tests/py/nft-test.py
+++ b/tests/py/nft-test.py
@@ -134,32 +134,29 @@ def print_info(reason, filename=None, lineno=None):
def color_differences(rule, other, color):
rlen = len(rule)
olen = len(other)
+ out = ""
# find equal part at start
for i in range(rlen):
if i >= olen or rule[i] != other[i]:
break
- start_idx = i
+ if i > 0:
+ out += rule[:i]
+ rule = rule[i:]
+ other = other[i:]
+ rlen = len(rule)
+ olen = len(other)
# find equal part at end
- found = False
- for i in range(-1, start_idx -rlen - 1, -1):
- if i < start_idx -olen:
- break
- if rule[i] != other[i]:
- found = True
+ for i in range(1, rlen + 1):
+ if i > olen or rule[rlen - i] != other[olen - i]:
+ i -= 1
break
- end_idx = i
- if found:
- end_idx += 1
-
- out = ""
- if start_idx > 0:
- out += rule[:start_idx]
- out += color + rule[start_idx:end_idx] + Colors.ENDC
- if end_idx < 0:
- out += rule[end_idx:]
+ if rlen > i:
+ out += color + rule[:rlen - i] + Colors.ENDC
+ rule = rule[rlen - i:]
+ out += rule
return out
def print_differences_warning(filename, lineno, rule1, rule2, cmd):