-
Notifications
You must be signed in to change notification settings - Fork 8
/
view_test.go
132 lines (102 loc) · 2.23 KB
/
view_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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright 2014 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"
)
func TestClose(t *testing.T) {
ed := backend.GetEditor()
l := len(ed.Windows())
w := ed.NewWindow()
ed.CommandHandler().RunWindowCommand(w, "close", nil)
if got, exp := len(ed.Windows()), l; got != exp {
t.Error("When there is no view the window should close")
t.Errorf("Expected %d windows, but got %d", exp, got)
}
l = len(w.Views())
w.NewFile()
ed.CommandHandler().RunWindowCommand(w, "close", nil)
if len(w.Views()) != l {
t.Errorf("Expected %d view, but got %d", l, len(w.Views()))
}
for _, v := range w.Views() {
v.SetScratch(true)
v.Close()
}
}
func TestNextView(t *testing.T) {
ed := backend.GetEditor()
w := ed.NewWindow()
defer w.Close()
v0 := w.NewFile()
defer func() {
v0.SetScratch(true)
v0.Close()
}()
v1 := w.NewFile()
defer func() {
v1.SetScratch(true)
v1.Close()
}()
v2 := w.NewFile()
defer func() {
v2.SetScratch(true)
v2.Close()
}()
v3 := w.NewFile()
defer func() {
v3.SetScratch(true)
v3.Close()
}()
w.SetActiveView(v1)
ed.CommandHandler().RunWindowCommand(w, "next_view", nil)
av := w.ActiveView()
if av != v2 {
t.Error("Expected to get v2, but didn't")
}
w.SetActiveView(v3)
ed.CommandHandler().RunWindowCommand(w, "next_view", nil)
av = w.ActiveView()
if av != v0 {
t.Error("Expected to get v0, but didn't")
}
}
func TestPrevView(t *testing.T) {
ed := backend.GetEditor()
w := ed.NewWindow()
defer w.Close()
v0 := w.NewFile()
defer func() {
v0.SetScratch(true)
v0.Close()
}()
v1 := w.NewFile()
defer func() {
v1.SetScratch(true)
v1.Close()
}()
v2 := w.NewFile()
defer func() {
v2.SetScratch(true)
v2.Close()
}()
v3 := w.NewFile()
defer func() {
v3.SetScratch(true)
v3.Close()
}()
w.SetActiveView(v2)
ed.CommandHandler().RunWindowCommand(w, "prev_view", nil)
av := w.ActiveView()
if av != v1 {
t.Error("Expected to get v1, but didn't")
}
w.SetActiveView(v0)
ed.CommandHandler().RunWindowCommand(w, "prev_view", nil)
av = w.ActiveView()
if av != v3 {
t.Error("Expected to get v3, but didn't")
}
}