-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff_iterator_test.go
61 lines (52 loc) · 2.02 KB
/
diff_iterator_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
50
51
52
53
54
55
56
57
58
59
60
61
package go_three_way_merge
import (
"testing"
"github.com/sergi/go-diff/diffmatchpatch"
)
func getIterator(base, newVersion string) diffIterator {
dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(base, newVersion, false)
return newDiffIterator(diffs)
}
func testNextIteration(t *testing.T, iterator *diffIterator, expectedValue string, expectedType int) {
if iterator.value() != expectedValue {
t.Errorf("Expected value '%s', got '%s'.", expectedValue, iterator.value())
}
if iterator.diffType() != expectedType {
t.Errorf("Expected diff type %d, got %d for expected value '%s'", expectedType, iterator.diffType(), expectedValue)
}
if iterator.isFinished() {
t.Error("Iterator should not finish.")
}
iterator.next()
}
func TestBasicIterator(t *testing.T) {
iterator := getIterator("abcde fg", "acdefghij")
testNextIteration(t, &iterator, "a", diffEqual)
testNextIteration(t, &iterator, "b", diffDelete)
testNextIteration(t, &iterator, "c", diffEqual)
testNextIteration(t, &iterator, "d", diffEqual)
testNextIteration(t, &iterator, "e", diffEqual)
testNextIteration(t, &iterator, " ", diffDelete)
testNextIteration(t, &iterator, "f", diffEqual)
testNextIteration(t, &iterator, "g", diffEqual)
testNextIteration(t, &iterator, "h", diffInsert)
testNextIteration(t, &iterator, "i", diffInsert)
testNextIteration(t, &iterator, "j", diffInsert)
if !iterator.isFinished() {
t.Error("Iterator should be finished by now.")
}
}
func TestUnicodeSupport(t *testing.T) {
iterator := getIterator("ùéçà$¤", "ùèça€ĸ")
testNextIteration(t, &iterator, "ù", diffEqual)
testNextIteration(t, &iterator, "é", diffDelete)
testNextIteration(t, &iterator, "è", diffInsert)
testNextIteration(t, &iterator, "ç", diffEqual)
testNextIteration(t, &iterator, "à", diffDelete)
testNextIteration(t, &iterator, "$", diffDelete)
testNextIteration(t, &iterator, "¤", diffDelete)
testNextIteration(t, &iterator, "a", diffInsert)
testNextIteration(t, &iterator, "€", diffInsert)
testNextIteration(t, &iterator, "ĸ", diffInsert)
}