-
Notifications
You must be signed in to change notification settings - Fork 250
/
RSyntaxTextAreaEditorKitInsertBreakActionTest.java
109 lines (81 loc) · 3.58 KB
/
RSyntaxTextAreaEditorKitInsertBreakActionTest.java
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
/*
* 08/22/2015
*
* This library is distributed under a modified BSD license. See the included
* LICENSE file for details.
*/
package org.fife.ui.rsyntaxtextarea;
import org.fife.ui.SwingRunnerExtension;
import org.fife.ui.rtextarea.RTextArea;
import org.fife.ui.rtextarea.RTextAreaEditorKit;
import org.fife.ui.rtextarea.RecordableTextAction;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import java.awt.event.ActionEvent;
/**
* Unit tests for the {@link RSyntaxTextAreaEditorKit.InsertBreakAction} class.
*
* @author Robert Futrell
* @version 1.0
*/
@ExtendWith(SwingRunnerExtension.class)
class RSyntaxTextAreaEditorKitInsertBreakActionTest extends AbstractRSyntaxTextAreaTest {
@Test
void testActionPerformedImpl_notEditable() {
RTextArea textArea = new RTextArea("hello world");
textArea.setCaretPosition(textArea.getText().indexOf(' '));
textArea.setEditable(false);
ActionEvent e = new ActionEvent(textArea, 0, "command");
new RSyntaxTextAreaEditorKit.InsertBreakAction().actionPerformedImpl(e, textArea);
Assertions.assertEquals("hello world", textArea.getText());
}
@Test
void testActionPerformedImpl_notEnabled() {
RTextArea textArea = new RTextArea("hello world");
textArea.setCaretPosition(textArea.getText().indexOf(' '));
textArea.setEnabled(false);
ActionEvent e = new ActionEvent(textArea, 0, "command");
new RSyntaxTextAreaEditorKit.InsertBreakAction().actionPerformedImpl(e, textArea);
Assertions.assertEquals("hello world", textArea.getText());
}
@Test
void testActionPerformedImpl_closingCurlyBraceAdded() {
String origContent = "public void foo() {";
RSyntaxTextArea textArea = createTextArea(SyntaxConstants.SYNTAX_STYLE_JAVA, origContent);
textArea.setCaretPosition(origContent.length());
RecordableTextAction a = new RSyntaxTextAreaEditorKit.InsertBreakAction();
ActionEvent e = createActionEvent(textArea, RSyntaxTextAreaEditorKit.insertBreakAction);
a.actionPerformedImpl(e, textArea);
String expectedResultContent = origContent + "\n\t\n}\n";
Assertions.assertEquals(expectedResultContent, textArea.getText());
}
@Test
void testActionPerformedImpl_allWhiteSpaceLineCleared() {
String origContent = "public void foo() {\n\t";
RSyntaxTextArea textArea = createTextArea(SyntaxConstants.SYNTAX_STYLE_JAVA, origContent);
textArea.setCaretPosition(origContent.length());
RecordableTextAction a = new RSyntaxTextAreaEditorKit.InsertBreakAction();
ActionEvent e = createActionEvent(textArea, RSyntaxTextAreaEditorKit.insertBreakAction);
a.actionPerformedImpl(e, textArea);
String expectedResultContent = "public void foo() {\n\n\t";
Assertions.assertEquals(expectedResultContent, textArea.getText());
}
@Test
void testActionPerformedImpl_autoIndentNotEnabled() {
String origContent = "public void foo() {";
RSyntaxTextArea textArea = createTextArea(SyntaxConstants.SYNTAX_STYLE_JAVA, origContent);
textArea.setAutoIndentEnabled(false);
textArea.setCaretPosition(origContent.length());
RecordableTextAction a = new RSyntaxTextAreaEditorKit.InsertBreakAction();
ActionEvent e = createActionEvent(textArea, RSyntaxTextAreaEditorKit.insertBreakAction);
a.actionPerformedImpl(e, textArea);
String expectedResultContent = "public void foo() {\n\n}\n";
Assertions.assertEquals(expectedResultContent, textArea.getText());
}
@Test
void testGetMacroId() {
RSyntaxTextAreaEditorKit.InsertBreakAction a = new RSyntaxTextAreaEditorKit.InsertBreakAction();
Assertions.assertEquals(RSyntaxTextAreaEditorKit.insertBreakAction, a.getMacroID());
}
}