(t *testing.T, before []string, operations []operation, after []string)
| 27 | } |
| 28 | |
| 29 | func 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 | } |
no test coverage detected