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(b.ExternallyModified(), false)
52 assert.Equal(b.Modified(), false)
53 assert.Equal(b.NumCursors(), 1)
55 checkText := func(lines []string) {
56 assert.Equal(b.Bytes(), []byte(strings.Join(lines, "\n")))
57 assert.Equal(b.LinesNum(), len(lines))
58 for i, s := range lines {
59 assert.Equal(b.Line(i), s)
60 assert.Equal(b.LineBytes(i), []byte(s))
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(b.NumCursors(), 1+len(operations))
78 for i, op := range operations {
80 cursor.DeleteSelection()
81 b.Insert(cursor.Loc, strings.Join(op.text, "\n"))
86 for _ = range operations {
93 for i, op := range operations {
95 assert.Equal(cursor.Loc, op.start)
96 assert.Equal(cursor.CurSelection[0], op.start)
97 assert.Equal(cursor.CurSelection[1], op.end)
100 for _ = range operations {