forked from scala-ide/scala-ide
/
TestBracketStrategy.scala
112 lines (77 loc) · 3.22 KB
/
TestBracketStrategy.scala
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
package scala.tools.eclipse.ui
import org.junit.Test
import org.junit.Assert._
import org.eclipse.jdt.internal.core.util.SimpleDocument
import org.eclipse.jface.text.DocumentCommand
import org.eclipse.jface.text.IDocument
import org.eclipse.jface.text.TextViewer
class TestCommand(cOffset: Int, cLength: Int, cText: String, cCaretOffset: Int, cShiftsCaret: Boolean, cDoIt: Boolean) extends DocumentCommand {
caretOffset = cCaretOffset
doit = cDoIt
length = cLength
offset = cOffset
text = cText
shiftsCaret = cShiftsCaret
}
/**
* Those are not real test (does not check the document after applying the change), just regression tests.
*/
class TestBracketStrategy {
@Test
def autoAddClosing() {
val document = new SimpleDocument("------")
val command = new TestCommand(3, 0, "{", -1, true, true)
new AutoCloseBracketStrategy().customizeDocumentCommand(document, command)
checkCommand(3, 0, "{}", 4, false, true, command)
}
@Test
def jumpClosing() {
val document = new SimpleDocument("---}---")
val command = new TestCommand(3, 0, "}", -1, true, true)
new AutoCloseBracketStrategy().customizeDocumentCommand(document, command)
checkCommand(3, 0, "", 4, true, true, command)
}
@Test
def addClosing() {
val document = new SimpleDocument("---}---")
val command = new TestCommand(4, 0, "}", -1, true, true)
new AutoCloseBracketStrategy().customizeDocumentCommand(document, command)
checkCommand(4, 0, "}", -1, true, true, command)
}
@Test
def addClosingEndOfFile() {
val document = new SimpleDocument("------")
val command = new TestCommand(6, 0, "}", -1, true, true)
new AutoCloseBracketStrategy().customizeDocumentCommand(document, command)
checkCommand(6, 0, "}", -1, true, true, command)
}
@Test
def autoDeleteClosing() {
val document = new SimpleDocument("---{}---")
val command = new TestCommand(3, 1, "", -1, true, true)
new AutoCloseBracketStrategy().customizeDocumentCommand(document, command)
checkCommand(3, 2, "", -1, true, true, command)
}
@Test
def deleteSingleOpening() {
val document = new SimpleDocument("---{----")
val command = new TestCommand(3, 1, "", -1, true, true)
new AutoCloseBracketStrategy().customizeDocumentCommand(document, command)
checkCommand(3, 1, "", -1, true, true, command)
}
@Test
def deleteSingleOpeningEndOfFile() {
val document = new SimpleDocument("------{")
val command = new TestCommand(6, 1, "", -1, true, true)
new AutoCloseBracketStrategy().customizeDocumentCommand(document, command)
checkCommand(6, 1, "", -1, true, true, command)
}
def checkCommand(offset: Int, length: Int, text: String, caretOffset: Int, shiftsCaret: Boolean, doit: Boolean, command: DocumentCommand) {
assertEquals("Bad resulting offset", offset, command.offset)
assertEquals("Bad resulting lenght", length, command.length)
assertEquals("Bad resulting text", text, command.text)
assertEquals("Bad resulting carretOffset", caretOffset, command.caretOffset)
assertEquals("Bad resulting shiftsCaret", shiftsCaret, command.shiftsCaret)
assertEquals("Bad resulting doit", doit, command.doit)
}
}