-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff_markup_test.go
More file actions
172 lines (130 loc) · 3.86 KB
/
diff_markup_test.go
File metadata and controls
172 lines (130 loc) · 3.86 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
Golang test helper library: sztest.
Copyright (C) 2023-2025 Leslie Dancsecs
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package sztest
import (
"strings"
"testing"
)
func testDiffMarkupPrerequisites(t *testing.T) {
t.Run("InternalMarkup", testSzTestInternalMarkup)
t.Run("MarkupForTerminal", testSzTestMarkupForTerminal)
t.Run("GotWant", testSzTestGotWant)
}
func testSzTestInternalMarkup(t *testing.T) {
const (
area = "internal markup"
msg = "<-- MSG -->"
)
var got, wnt string
got = w(msg)
wnt = markWntOn + labelWant + ": " + markWntOff + msg
if got != wnt {
t.Error(errGotWnt(area, got, wnt))
}
got = g(msg)
wnt = markGotOn + labelGot + ": " + markGotOff + msg
if got != wnt {
t.Error(errGotWnt(area, got, wnt))
}
got = markAsIns(msg)
wnt = markInsOn + msg + markInsOff
if got != wnt {
t.Error(errGotWnt(area, got, wnt))
}
got = markAsDel(msg)
wnt = markDelOn + msg + markDelOff
if got != wnt {
t.Error(errGotWnt(area, got, wnt))
}
got = markAsChg(msg, strings.ToLower(msg), diffGot)
wnt = markChgOn + msg + markChgOff
if got != wnt {
t.Error(errGotWnt(area, got, wnt))
}
got = markAsChg(msg, strings.ToLower(msg), diffWant)
wnt = markChgOn + strings.ToLower(msg) + markChgOff
if got != wnt {
t.Error(errGotWnt(area, got, wnt))
}
got = markAsChg(msg, strings.ToLower(msg), diffMerge)
wnt = markDelOn + strings.ToLower(msg) + markDelOff +
markSepOn + "/" + markSepOff +
markInsOn + msg + markInsOff
if got != wnt {
t.Error(errGotWnt(area, got, wnt))
}
}
func testSzTestMarkupForTerminal(t *testing.T) {
const (
area = "markup for terminal"
tstStr1 = "ABC"
tstStr2 = "DEF"
)
var got, wnt string
got = resolveMarksForDisplay(markAsIns(tstStr1))
wnt = settingMarkInsOn + tstStr1 + settingMarkInsOff
if got != wnt {
t.Error(errGotWnt(area, got, wnt))
}
got = resolveMarksForDisplay(markAsDel(tstStr1))
wnt = settingMarkDelOn + tstStr1 + settingMarkDelOff
if got != wnt {
t.Error(errGotWnt(area, got, wnt))
}
got = resolveMarksForDisplay(markAsChg(tstStr1, tstStr2, diffGot))
wnt = settingMarkChgOn + tstStr1 + settingMarkChgOff
if got != wnt {
t.Error(errGotWnt(area, got, wnt))
}
got = resolveMarksForDisplay(markAsChg(tstStr1, tstStr2, diffWant))
wnt = settingMarkChgOn + tstStr2 + settingMarkChgOff
if got != wnt {
t.Error(errGotWnt(area, got, wnt))
}
got = resolveMarksForDisplay(markAsChg(tstStr1, tstStr2, diffMerge))
wnt = "" +
settingMarkDelOn + tstStr2 + settingMarkDelOff +
settingMarkSepOn + "/" + settingMarkSepOff +
settingMarkInsOn + tstStr1 + settingMarkInsOff
if got != wnt {
t.Error(errGotWnt(area, got, wnt))
}
got = resolveMarksForDisplay(markAsMsg(tstStr1))
wnt = "" +
settingMarkMsgOn + tstStr1 + settingMarkMsgOff
if got != wnt {
t.Error(errGotWnt(area, got, wnt))
}
}
func testSzTestGotWant(t *testing.T) {
const area = "gotWnt"
var got, wnt string
got = gotWntDiff("ABC", "ADC", 1)
wnt = "" +
g("A"+markAsChg("B", "D", diffGot)+"C") +
"\n" +
w("A"+markAsChg("B", "D", diffWant)+"C")
if got != wnt {
t.Error(errGotWnt(area, got, wnt))
}
got = gotWntDiff("AB\n", "AC\n", 3)
wnt = "" +
g("\n"+markAsChg("AB\n", "AC\n", diffGot)) +
"\n" +
w("\n"+markAsChg("AB\n", "AC\n", diffWant))
if got != wnt {
t.Error(errGotWnt(area, got, wnt))
}
}