|
| 1 | +import io |
| 2 | + |
| 3 | +from mypy.test.helpers import Suite, diff_ranges, render_diff_range |
| 4 | + |
| 5 | + |
| 6 | +class DiffHelperSuite(Suite): |
| 7 | + def test_render_diff_range(self) -> None: |
| 8 | + expected = ["hello", "world"] |
| 9 | + actual = ["goodbye", "world"] |
| 10 | + |
| 11 | + expected_ranges, actual_ranges = diff_ranges(expected, actual) |
| 12 | + |
| 13 | + output = io.StringIO() |
| 14 | + render_diff_range(expected_ranges, expected, output=output) |
| 15 | + assert output.getvalue() == " hello (diff)\n world\n" |
| 16 | + output = io.StringIO() |
| 17 | + render_diff_range(actual_ranges, actual, output=output) |
| 18 | + assert output.getvalue() == " goodbye (diff)\n world\n" |
| 19 | + |
| 20 | + expected = ["a", "b", "c", "d", "e", "f", "g", "h", "circle", "i", "j"] |
| 21 | + actual = ["a", "b", "c", "d", "e", "f", "g", "h", "square", "i", "j"] |
| 22 | + |
| 23 | + expected_ranges, actual_ranges = diff_ranges(expected, actual) |
| 24 | + |
| 25 | + output = io.StringIO() |
| 26 | + render_diff_range(expected_ranges, expected, output=output, indent=0) |
| 27 | + assert output.getvalue() == "a\nb\nc\n...\nf\ng\nh\ncircle (diff)\ni\nj\n" |
| 28 | + output = io.StringIO() |
| 29 | + render_diff_range(actual_ranges, actual, output=output, indent=0) |
| 30 | + assert output.getvalue() == "a\nb\nc\n...\nf\ng\nh\nsquare (diff)\ni\nj\n" |
| 31 | + |
| 32 | + def test_diff_ranges(self) -> None: |
| 33 | + a = ["hello", "world"] |
| 34 | + b = ["hello", "world"] |
| 35 | + |
| 36 | + assert diff_ranges(a, b) == ( |
| 37 | + [(0, 0), (0, 2), (2, 2), (2, 2)], |
| 38 | + [(0, 0), (0, 2), (2, 2), (2, 2)], |
| 39 | + ) |
| 40 | + |
| 41 | + a = ["hello", "world"] |
| 42 | + b = ["goodbye", "world"] |
| 43 | + |
| 44 | + assert diff_ranges(a, b) == ( |
| 45 | + [(0, 1), (1, 2), (2, 2), (2, 2)], |
| 46 | + [(0, 1), (1, 2), (2, 2), (2, 2)], |
| 47 | + ) |
0 commit comments