7 testifyAssert "github.com/stretchr/testify/assert"
8 lua "github.com/yuin/gopher-lua"
10 ulua "github.com/zyedidia/micro/internal/lua"
13 type operation struct {
19 type asserter interface {
20 Equal(interface{}, interface{}, ...interface{}) bool
21 NotEqual(interface{}, interface{}, ...interface{}) bool
24 type noOpAsserter struct {
27 func (a *noOpAsserter) Equal(interface{}, interface{}, ...interface{}) bool {
31 func (a *noOpAsserter) NotEqual(interface{}, interface{}, ...interface{}) bool {
36 ulua.L = lua.NewState()
39 func check(t *testing.T, before []string, operations []operation, after []string) {
42 // Benchmark mode; don't perform assertions
43 assert = &noOpAsserter{}
45 assert = testifyAssert.New(t)
48 b := NewBufferFromString(strings.Join(before, "\n"), "", BTDefault)
50 assert.NotEqual("", b.GetName())
51 assert.Equal(false, b.ExternallyModified())
52 assert.Equal(false, b.Modified())
53 assert.Equal(1, b.NumCursors())
55 checkText := func(lines []string) {
56 assert.Equal([]byte(strings.Join(lines, "\n")), b.Bytes())
57 assert.Equal(len(lines), b.LinesNum())
58 for i, s := range lines {
59 assert.Equal(s, b.Line(i))
60 assert.Equal([]byte(s), b.LineBytes(i))
68 for _, op := range operations {
69 cursor := NewCursor(b, op.start)
70 cursor.SetSelectionStart(op.start)
71 cursor.SetSelectionEnd(op.end)
73 cursors = append(cursors, cursor)
76 assert.Equal(1+len(operations), b.NumCursors())
78 for i, op := range operations {
80 b.SetCurCursor(cursor.Num)
81 cursor.DeleteSelection()
82 b.Insert(cursor.Loc, strings.Join(op.text, "\n"))
87 // must have exactly two events per operation (delete and insert)
88 for range operations {
95 for i, op := range operations {
97 if op.start == op.end {
98 assert.Equal(op.start, cursor.Loc)
100 assert.Equal(op.start, cursor.CurSelection[0])
101 assert.Equal(op.end, cursor.CurSelection[1])
105 for range operations {