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

Function TestGroupedOpCodes

texteditor/difflib/bytes/bytes_test.go:88–130  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

86}
87
88func TestGroupedOpCodes(t *testing.T) {
89 a := [][]byte{}
90 for i := 0; i != 39; i++ {
91 a = append(a, []byte(fmt.Sprintf("%02d", i)))
92 }
93 b := [][]byte{}
94 b = append(b, a[:8]...)
95 b = append(b, []byte(" i"))
96 b = append(b, a[8:19]...)
97 b = append(b, []byte(" x"))
98 b = append(b, a[20:22]...)
99 b = append(b, a[27:34]...)
100 b = append(b, []byte(" y"))
101 b = append(b, a[35:]...)
102 s := NewMatcher(a, b)
103 w := &bytes.Buffer{}
104 for _, g := range s.GetGroupedOpCodes(-1) {
105 fmt.Fprintf(w, "group\n")
106 for _, op := range g {
107 fmt.Fprintf(w, " %s, %d, %d, %d, %d\n", string(op.Tag),
108 op.I1, op.I2, op.J1, op.J2)
109 }
110 }
111 result := w.String()
112 expected := `group
113 e, 5, 8, 5, 8
114 i, 8, 8, 8, 9
115 e, 8, 11, 9, 12
116group
117 e, 16, 19, 17, 20
118 r, 19, 20, 20, 21
119 e, 20, 22, 21, 23
120 d, 22, 27, 23, 23
121 e, 27, 30, 23, 26
122group
123 e, 31, 34, 27, 30
124 r, 34, 35, 30, 31
125 e, 35, 38, 31, 34
126`
127 if expected != result {
128 t.Errorf("unexpected op codes: \n%s", result)
129 }
130}
131
132func ExampleGetUnifiedDiffString() {
133 a := `one

Callers

nothing calls this directly

Calls 4

StringMethod · 0.95
NewMatcherFunction · 0.70
ErrorfMethod · 0.65
GetGroupedOpCodesMethod · 0.45

Tested by

no test coverage detected