-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_unit_diff.py
110 lines (103 loc) · 3.34 KB
/
test_unit_diff.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import pytest
from notes_app.diff import (
_merge,
_replace_line_endings,
_split,
_join,
merge_strings,
)
class TestDiff:
@pytest.mark.parametrize(
"left, right, result",
[
(
"is",
"this is some section.yeah",
[["this"], ["is"], ["some", "section.yeah"]],
),
(
"is",
"this some section.yeah",
[["is"], ["this", "some", "section.yeah"]],
),
("", "this is some section.yeah", [["this", "is", "some", "section.yeah"]]),
(
"",
"this is some section.yeah",
[["this", "is", "some", "section.yeah"],],
),
(
"some section text",
"this is some section.yeah",
[["this", "is"], ["some"], ["section", "text"], ["section.yeah"],],
),
(
"some section text",
"another text",
[["some", "section"], ["another"], ["text"],],
),
],
)
def test__merge(self, left, right, result):
assert [x for x in _merge(left.split(), right.split())] == result
def test__replace_line_endings(self):
assert (
_replace_line_endings(
input_text="ad \n na", line_ending="\n", line_ending_replacement="!@#"
)
== "ad !@# na"
)
assert (
_replace_line_endings(
input_text="ad na", line_ending="\n", line_ending_replacement="!@#"
)
== "ad na"
)
@pytest.mark.parametrize(
"input_text, result",
[
(
"this is some section.yeah",
["this", " ", "is", " ", "some", " ", "section", ".", "yeah"],
),
("another text", ["another", " ", "text"],),
],
)
def test__split(self, input_text, result):
assert _split(input_text) == result
@pytest.mark.parametrize(
"input_list, result",
[
(["this", "is", "some", "section.yeah"], "this is some section.yeah",),
(["another", "text"], "another text",),
],
)
def test__join(self, input_list, result):
assert _join(input_list, separator=" ") == result
@pytest.mark.parametrize(
"before, after, result",
[
("is", "this is some section.yeah", "this is some section.yeah"),
("is", "this some section.yeah", "is this some section.yeah"),
("", "this is some section.yeah", "this is some section.yeah"),
("", "this is some section.yeah", "this is some section.yeah",),
(
"some section text",
"this is some section.yeah",
"this is some section text.yeah",
),
(
"some section text",
"another text this is some section.yeah",
"another text this is some section text.yeah",
),
(
"some \n section text",
"this is some section.yeah",
"""this is some
section text.yeah""",
),
],
)
def test_merge_strings(self, before, after, result):
assert merge_strings(before, after) == result