-
Notifications
You must be signed in to change notification settings - Fork 91
/
AceTest.kt
175 lines (114 loc) · 4.65 KB
/
AceTest.kt
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import com.intellij.openapi.actionSystem.IdeActions.ACTION_EDITOR_ENTER
import com.intellij.openapi.actionSystem.IdeActions.ACTION_EDITOR_START_NEW_LINE
import com.intellij.openapi.editor.actions.EnterAction
import org.acejump.action.AceAction
import org.acejump.config.AceConfig
import org.acejump.test.util.BaseTest
/**
* Functional test cases and end-to-end performance tests.
*
* TODO: Add more structure to test cases, use test resources to define files.
*/
class AceTest : BaseTest() {
fun `test that scanner finds all occurrences of single character`() =
assertEquals("test test test".search("t"), setOf(0, 3, 5, 8, 10, 13))
fun `test empty results for an absent query`() =
assertEmpty("test test test".search("best"))
fun `test sticky results on a query with extra characters`() =
assertEquals("test test test".search("testz"), setOf(0, 5, 10))
fun `test a query inside text with some variations`() =
assertEquals("abcd dabc cdab".search("cd"), setOf(2, 10))
fun `test a query containing a space character`() =
assertEquals("abcd dabc cdab".search("cd "), setOf(2))
fun `test a query containing a { character`() =
assertEquals("abcd{dabc cdab".search("cd{"), setOf(2))
fun `test that jumping to first occurrence succeeds`() {
"<caret>testing 1234".search("1")
takeAction(ACTION_EDITOR_ENTER)
myFixture.checkResult("testing <caret>1234")
}
fun `test that jumping to second occurrence succeeds`() {
"<caret>testing 1234".search("ti")
takeAction(ACTION_EDITOR_ENTER)
myFixture.checkResult("tes<caret>ting 1234")
}
fun `test that jumping to previous occurrence succeeds`() {
"te<caret>sting 1234".search("t")
takeAction(ACTION_EDITOR_START_NEW_LINE)
myFixture.checkResult("<caret>testing 1234")
}
fun `test tag selection`() {
"<caret>testing 1234".search("g")
typeAndWaitForResults(session.tags[0].key)
myFixture.checkResult("testin<caret>g 1234")
}
fun `test shift selection`() {
"<caret>testing 1234".search("4")
typeAndWaitForResults(session.tags[0].key.uppercase())
myFixture.checkResult("<selection>testing 123<caret></selection>4")
}
fun `test words before caret action`() {
makeEditor("test words <caret> before caret is two")
takeAction(AceAction.StartAllWordsBackwardsMode())
assertEquals(2, session.tags.size)
}
fun `test words after caret action`() {
makeEditor("test words <caret> after caret is four")
takeAction(AceAction.StartAllWordsForwardMode())
assertEquals(4, session.tags.size)
}
fun `test word mode`() {
makeEditor("test word action")
takeAction(AceAction.StartAllWordsMode())
assertEquals(3, session.tags.size)
typeAndWaitForResults(session.tags[1].key)
myFixture.checkResult("test <caret>word action")
}
fun `test target mode`() {
"<caret>test target action".search("target")
takeAction(AceAction.ToggleTargetMode())
typeAndWaitForResults(session.tags[0].key)
myFixture.checkResult("test <selection>target<caret></selection> action")
}
fun `test cache invalidation`() {
"first line".search("first")
typeAndWaitForResults(session.tags[0].key)
repeat(3) { takeAction(EnterAction()) }
takeAction(AceAction.ToggleTargetMode())
typeAndWaitForResults("first")
typeAndWaitForResults(session.tags[0].key)
myFixture.checkResult("\n\n\n<selection>first<caret></selection> line")
}
fun `test line mode`() {
makeEditor(" test\n three\n lines")
takeAction(AceAction.StartAllLineMarksMode())
assertEquals(9, session.tags.size)
}
fun `test chinese selection`() {
AceConfig.settings.mapToASCII = true
"test 拼音 selection".search("py")
takeAction(AceAction.ToggleTargetMode())
typeAndWaitForResults(session.tags[0].key)
myFixture.checkResult("test <selection>拼音<caret></selection> selection")
}
fun `test japanese selection`() {
AceConfig.settings.mapToASCII = true
"あみだにょらい".search("am")
takeAction(AceAction.ToggleTargetMode())
typeAndWaitForResults(session.tags[0].key)
myFixture.checkResult("<selection>あみだにょらい<caret></selection>")
}
fun `test query repitition`() {
"test test test".search("t")
typeAndWaitForResults("t")
typeAndWaitForResults(session.tags[1].key)
myFixture.checkResult("tes<caret>t test test")
}
// https://github.com/acejump/AceJump/issues/355
fun `ignore test a word that is difficult to tag`() {
makeEditor("aaCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
takeAction(AceAction.ActivateOrCycleMode())
typeAndWaitForResults("c")
assertEquals(2, session.tags.size)
}
}