Skip to content

Commit 947cf89

Browse files
committed
fix: duplicate word is last word
Signed-off-by: Abirdcfly <[email protected]>
1 parent aa17437 commit 947cf89

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

dupword.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,12 @@ func CheckOneKey(raw, key string) (new string, findWord string, find bool) {
238238
} else if i == len(raw)-1 {
239239
// last position
240240
word := raw[wordStart:]
241-
if !(((key != "" && word == key) || key == "") && word == preWord) {
241+
if ((key != "" && word == key) || key == "") && word == preWord {
242+
if !ExcludeWords(word) {
243+
find = true
244+
findWordMap[word] = true
245+
}
246+
} else {
242247
newLine.WriteString(lastSpace)
243248
newLine.WriteString(word)
244249
}

dupword_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ func Test_checkOneKey(t *testing.T) {
151151
wantKey: "the",
152152
wantFind: true,
153153
},
154+
{
155+
name: "duplicate word is last word",
156+
args: args{
157+
raw: "this line include duplicate word and\nand",
158+
},
159+
wantNew: "this line include duplicate word and",
160+
wantKey: "and",
161+
wantFind: true,
162+
},
154163
}
155164
for _, tt := range tests {
156165
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)