-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
49 lines (46 loc) · 1.24 KB
/
main_test.go
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
package main
import (
"reflect"
"testing"
)
func TestMyersDiff(t *testing.T) {
tests := []struct {
name string
aLines []string
bLines []string
expected []EditAction
}{
{
name: "No changes",
aLines: []string{"line1", "line2", "line3"},
bLines: []string{"line1", "line2", "line3"},
expected: []EditAction{Keep{"line1"}, Keep{"line2"}, Keep{"line3"}},
},
{
name: "Insertion",
aLines: []string{"line1", "line2"},
bLines: []string{"line1", "line2", "line3"},
expected: []EditAction{Keep{"line1"}, Keep{"line2"}, Insert{"line3"}},
},
{
name: "Removal",
aLines: []string{"line1", "line2", "line3"},
bLines: []string{"line1", "line2"},
expected: []EditAction{Keep{"line1"}, Keep{"line2"}, Remove{"line3"}},
},
{
name: "Replacement",
aLines: []string{"line1", "line2", "line3"},
bLines: []string{"line1", "newLine2", "line3"},
expected: []EditAction{Keep{"line1"}, Remove{"line2"}, Insert{"newLine2"}, Keep{"line3"}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := myersDiff(tt.aLines, tt.bLines)
if !reflect.DeepEqual(result, tt.expected) {
t.Errorf("myersDiff() = %v, want %v", result, tt.expected)
}
})
}
}