forked from limetext/commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglue_test.go
107 lines (98 loc) · 3.88 KB
/
glue_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package commands
import (
"testing"
"github.com/limetext/backend"
"github.com/limetext/text"
)
func TestGlueCmds(t *testing.T) {
ed := backend.GetEditor()
ch := ed.CommandHandler()
w := ed.NewWindow()
defer w.Close()
v := w.NewFile()
defer func() {
v.SetScratch(true)
v.Close()
}()
v.SetScratch(true)
e := v.BeginEdit()
v.Insert(e, 0, "Hello World!\nTest123123\nAbrakadabra\n")
v.EndEdit(e)
v.SetScratch(false)
ch.RunTextCommand(v, "mark_undo_groups_for_gluing", nil)
ch.RunTextCommand(v, "insert", backend.Args{"characters": "a"})
ch.RunTextCommand(v, "insert", backend.Args{"characters": "b"})
ch.RunTextCommand(v, "insert", backend.Args{"characters": "c"})
ch.RunTextCommand(v, "glue_marked_undo_groups", nil)
if v.UndoStack().Position() != 1 {
t.Error(v.UndoStack().Position())
} else if d := v.Substr(text.Region{A: 0, B: v.Size()}); d != "Hello World!\nTest123123\nAbrakadabra\nabc" {
t.Error(d)
}
ch.RunTextCommand(v, "undo", nil)
if d := v.Substr(text.Region{A: 0, B: v.Size()}); d != "Hello World!\nTest123123\nAbrakadabra\n" {
t.Error(d)
}
ch.RunTextCommand(v, "redo", nil)
if d := v.Substr(text.Region{A: 0, B: v.Size()}); d != "Hello World!\nTest123123\nAbrakadabra\nabc" {
t.Error(d)
}
if v.UndoStack().Position() != 1 {
t.Error(v.UndoStack().Position())
} else if d := v.Substr(text.Region{A: 0, B: v.Size()}); d != "Hello World!\nTest123123\nAbrakadabra\nabc" {
t.Error(d)
}
ch.RunTextCommand(v, "undo", nil)
if d := v.Substr(text.Region{A: 0, B: v.Size()}); d != "Hello World!\nTest123123\nAbrakadabra\n" {
t.Error(d)
}
ch.RunTextCommand(v, "maybe_mark_undo_groups_for_gluing", nil)
ch.RunTextCommand(v, "insert", backend.Args{"characters": "a"})
ch.RunTextCommand(v, "maybe_mark_undo_groups_for_gluing", nil)
ch.RunTextCommand(v, "insert", backend.Args{"characters": "b"})
ch.RunTextCommand(v, "maybe_mark_undo_groups_for_gluing", nil)
ch.RunTextCommand(v, "insert", backend.Args{"characters": "c"})
ch.RunTextCommand(v, "maybe_mark_undo_groups_for_gluing", nil)
ch.RunTextCommand(v, "glue_marked_undo_groups", nil)
if v.UndoStack().Position() != 1 {
t.Error(v.UndoStack().Position())
} else if d := v.Substr(text.Region{A: 0, B: v.Size()}); d != "Hello World!\nTest123123\nAbrakadabra\nabc" {
t.Error(d)
}
ch.RunTextCommand(v, "undo", nil)
if d := v.Substr(text.Region{A: 0, B: v.Size()}); d != "Hello World!\nTest123123\nAbrakadabra\n" {
t.Error(d)
}
ch.RunTextCommand(v, "redo", nil)
if d := v.Substr(text.Region{A: 0, B: v.Size()}); d != "Hello World!\nTest123123\nAbrakadabra\nabc" {
t.Error(d)
}
if v.UndoStack().Position() != 1 {
t.Error(v.UndoStack().Position())
} else if d := v.Substr(text.Region{A: 0, B: v.Size()}); d != "Hello World!\nTest123123\nAbrakadabra\nabc" {
t.Error(d)
}
ch.RunTextCommand(v, "mark_undo_groups_for_gluing", nil)
ch.RunTextCommand(v, "move", backend.Args{"forward": false, "extend": true, "by": "lines"})
ch.RunTextCommand(v, "move", backend.Args{"forward": false, "extend": true, "by": "lines"})
ch.RunTextCommand(v, "move", backend.Args{"forward": false, "extend": true, "by": "lines"})
ch.RunTextCommand(v, "left_delete", nil)
ch.RunTextCommand(v, "insert", backend.Args{"characters": "a"})
ch.RunTextCommand(v, "insert", backend.Args{"characters": "b"})
ch.RunTextCommand(v, "insert", backend.Args{"characters": "c"})
ch.RunTextCommand(v, "glue_marked_undo_groups", nil)
if v.UndoStack().Position() != 2 {
t.Error(v.UndoStack().Position())
} else if d := v.Substr(text.Region{A: 0, B: v.Size()}); d != "Helabc" {
t.Error(d)
}
ch.RunTextCommand(v, "undo", nil)
if v.UndoStack().Position() != 1 {
t.Error(v.UndoStack().Position())
} else if d := v.Substr(text.Region{A: 0, B: v.Size()}); d != "Hello World!\nTest123123\nAbrakadabra\nabc" {
t.Error(d)
}
}