MCPcopy
hub / github.com/micro-editor/micro / check

Function check

internal/buffer/buffer_test.go:29–97  ·  view source on GitHub ↗
(t *testing.T, before []string, operations []operation, after []string)

Source from the content-addressed store, hash-verified

27}
28
29func check(t *testing.T, before []string, operations []operation, after []string) {
30 assert := assert.New(t)
31
32 b := NewBufferFromString(strings.Join(before, "\n"), "", BTDefault)
33
34 assert.NotEqual("", b.GetName())
35 assert.Equal(false, b.ExternallyModified())
36 assert.Equal(false, b.Modified())
37 assert.Equal(1, b.NumCursors())
38
39 checkText := func(lines []string) {
40 assert.Equal([]byte(strings.Join(lines, "\n")), b.Bytes())
41 assert.Equal(len(lines), b.LinesNum())
42 for i, s := range lines {
43 assert.Equal(s, b.Line(i))
44 assert.Equal([]byte(s), b.LineBytes(i))
45 }
46 }
47
48 checkText(before)
49
50 var cursors []*Cursor
51
52 for _, op := range operations {
53 cursor := NewCursor(b, op.start)
54 cursor.SetSelectionStart(op.start)
55 cursor.SetSelectionEnd(op.end)
56 b.AddCursor(cursor)
57 cursors = append(cursors, cursor)
58 }
59
60 assert.Equal(1+len(operations), b.NumCursors())
61
62 for i, op := range operations {
63 cursor := cursors[i]
64 b.SetCurCursor(cursor.Num)
65 cursor.DeleteSelection()
66 b.Insert(cursor.Loc, strings.Join(op.text, "\n"))
67 }
68
69 checkText(after)
70
71 // must have exactly two events per operation (delete and insert)
72 for range operations {
73 b.UndoOneEvent()
74 b.UndoOneEvent()
75 }
76
77 checkText(before)
78
79 for i, op := range operations {
80 cursor := cursors[i]
81 if op.start == op.end {
82 assert.Equal(op.start, cursor.Loc)
83 } else {
84 assert.Equal(op.start, cursor.CurSelection[0])
85 assert.Equal(op.end, cursor.CurSelection[1])
86 }

Callers 15

TestAuto1Function · 0.70
TestAuto2Function · 0.70
TestAuto3Function · 0.70
TestAuto4Function · 0.70
TestBug19872UndoIsFunkyFunction · 0.70
TestInsertEmptyTextFunction · 0.70
TestLastOpIsNoOpFunction · 0.70
TestInsertOneNewlineFunction · 0.70

Calls 15

SetSelectionStartMethod · 0.95
SetSelectionEndMethod · 0.95
DeleteSelectionMethod · 0.95
NewBufferFromStringFunction · 0.85
NewCursorFunction · 0.85
JoinMethod · 0.80
GetNameMethod · 0.80
ExternallyModifiedMethod · 0.80
ModifiedMethod · 0.80
NumCursorsMethod · 0.80
BytesMethod · 0.80
LineMethod · 0.80

Tested by

no test coverage detected