MCPcopy Create free account
hub / github.com/cogentcore/core / TestDiff

Function TestDiff

texteditor/text/diff_test.go:11–55  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestDiff(t *testing.T) {
12 astr := []string{"foo", "bar", "baz"}
13 bstr := []string{"foo", "bar1", "asdf", "baz"}
14
15 dfs := DiffLines(astr, bstr)
16 // fmt.Printf("diffs: %v", dfs)
17 if len(dfs) != 3 {
18 t.Errorf("diffs != 3")
19 }
20
21 pt := dfs.ToPatch(bstr)
22 nb := pt.Apply(astr)
23
24 bln := pt.NumBlines()
25 // fmt.Printf("num blines: %d\n", bln)
26 if bln != 2 {
27 t.Errorf("num blines != 2\n")
28 }
29
30 // for _, pr := range pt {
31 // fmt.Printf("%v blines: %v\n", pr.Op, pr.Blines)
32 // }
33
34 // fmt.Printf("nb: %v\n", nb)
35 for i := range nb {
36 if nb[i] != bstr[i] {
37 t.Errorf("Line: %d\t orig: %s != %s", i, bstr[i], nb[i])
38 }
39 }
40
41 rd := dfs.Reverse()
42
43 // fmt.Printf("rev diffs: %v\n", rd)
44
45 ptr := rd.ToPatch(astr)
46 na := ptr.Apply(bstr)
47
48 // fmt.Printf("na: %v\n", na)
49 for i := range na {
50 if na[i] != astr[i] {
51 t.Errorf("Line: %d\t orig: %s != %s", i, astr[i], na[i])
52 }
53 }
54
55}

Callers

nothing calls this directly

Calls 6

DiffLinesFunction · 0.85
ToPatchMethod · 0.80
NumBlinesMethod · 0.80
ReverseMethod · 0.80
ErrorfMethod · 0.65
ApplyMethod · 0.65

Tested by

no test coverage detected