mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-09 05:35:19 +02:00
find common prefix and suffix of two strings
This commit is contained in:
23
kitty_tests/diff.py
Normal file
23
kitty_tests/diff.py
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
|
||||
from . import BaseTest
|
||||
|
||||
|
||||
class TestDiff(BaseTest):
|
||||
|
||||
def test_changed_center(self):
|
||||
from kittens.diff.diff_speedup import changed_center
|
||||
for left, right, prefix, suffix in [
|
||||
('abc', 'def', '', ''),
|
||||
('', 'def', '', ''),
|
||||
('abc', '', '', ''),
|
||||
('abc', 'abc', 'abc', ''),
|
||||
('abc', 'abcdef', 'abc', ''),
|
||||
('aa111bb', 'aa2bb', 'aa', 'bb'),
|
||||
]:
|
||||
pc, sc = changed_center(left, right)
|
||||
for src in (left, right):
|
||||
self.assertEqual((prefix, suffix), (src[:pc], src[-sc:] if sc else ''))
|
||||
Reference in New Issue
Block a user