-
Notifications
You must be signed in to change notification settings - Fork 8
/
comment_test.go
121 lines (101 loc) · 1.69 KB
/
comment_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
// Copyright 2015 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 TestToggleComment(t *testing.T) {
tests := []struct {
r []text.Region
in string
exp string
}{
{
[]text.Region{{0, 3}},
"test",
"// test",
},
{
[]text.Region{{0, 6}},
"// test",
"test",
},
{
[]text.Region{{0, 5}},
"//test",
"test",
},
{
[]text.Region{{0, 8}},
"// test",
" test",
},
{
[]text.Region{{0, 7}},
" test",
" // test",
},
{
[]text.Region{{0, 10}},
" // test",
" test",
},
{
[]text.Region{{0, 9}},
" //test",
" test",
},
{
[]text.Region{{0, 12}},
" // test",
" test",
},
{
[]text.Region{{0, 8}},
"\t test",
"\t // test",
},
{
[]text.Region{{0, 11}},
"\t // test",
"\t test",
},
{
[]text.Region{{0, 10}},
"\t //test",
"\t test",
},
{
[]text.Region{{0, 13}},
"\t // test",
"\t test",
},
}
ed := backend.GetEditor()
w := ed.NewWindow()
defer w.Close()
for i, test := range tests {
v := w.NewFile()
defer func() {
v.SetScratch(true)
v.Close()
}()
e := v.BeginEdit()
v.Insert(e, 0, test.in)
v.EndEdit(e)
v.Sel().Clear()
if test.r != nil {
for _, r := range test.r {
v.Sel().Add(r)
}
}
ed.CommandHandler().RunTextCommand(v, "toggle_comment", nil)
sr := v.Substr(text.Region{0, v.Size()})
if sr != test.exp {
t.Errorf("%s test %d failed: %v, %+v", "toggle_comment", i, sr, test)
}
}
}