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
|
// Copyright 2024 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package covermerger
import (
"testing"
"github.com/stretchr/testify/assert"
)
var (
textBase = `line1
line2
line3`
textBaseWithNewLine = `line0
line1
line2
line3`
textBaseWOLine = `line2
line3`
textBaseChangedLine = `lineX
line2
line3`
)
func TestMatching(t *testing.T) {
type Test struct {
name string
textFrom string
textTo string
lineFrom int
lineTo int
}
tests := []Test{
{
name: "same text matching",
textFrom: textBase,
textTo: textBase,
lineFrom: 0,
lineTo: 0,
},
{
name: "diff matching with the new line",
textFrom: textBase,
textTo: textBaseWithNewLine,
lineFrom: 0,
lineTo: 1,
},
{
name: "diff matching with the removed line",
textFrom: textBase,
textTo: textBaseWOLine,
lineFrom: 0,
lineTo: -1,
},
{
name: "diff matching with the changed line",
textFrom: textBase,
textTo: textBaseChangedLine,
lineFrom: 0,
lineTo: -1,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
m := makeLineToLineMatcher(test.textFrom, test.textTo)
assert.NotNil(t, m)
got := m.SameLinePos(test.lineFrom)
if got != test.lineTo {
t.Fatalf("expected to see line %d instread of %d", test.lineTo, got)
}
})
}
}
|