Skip to content

Commit f7f616c

Browse files
author
Federico Fissore
committed
Adding AutoformatTest
1 parent 995f0fa commit f7f616c

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

app/src/processing/app/Editor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,7 @@ protected JMenu addInternalTools(JMenu menu) {
903903
JMenuItem item;
904904

905905
item = createToolMenuItem("cc.arduino.packages.formatter.AStyle");
906+
item.setName("menuToolsAutoFormat");
906907
int modifiers = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
907908
item.setAccelerator(KeyStroke.getKeyStroke('T', modifiers));
908909
menu.add(item);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package processing.app;
2+
3+
import org.fest.swing.fixture.JMenuItemFixture;
4+
import org.junit.Test;
5+
import processing.app.helpers.JEditTextAreaFixture;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class AutoformatTest extends AbstractGUITest {
10+
11+
@Test
12+
public void shouldProduceNicelyFormattedCode() throws Exception {
13+
JMenuItemFixture menuToolsAutoFormat = window.menuItem("menuToolsAutoFormat");
14+
menuToolsAutoFormat.requireEnabled();
15+
16+
JEditTextAreaFixture editor = window.jEditTextArea("editor");
17+
editor.setText("void setup() {\n" +
18+
"// put your setup code here, to run once:\n" +
19+
"int foo[] = { 1, 2, 3, 4, 5};\n" +
20+
"int foo[2][5] = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}};\n" +
21+
"}\n" +
22+
"\n" +
23+
"void loop() {\n" +
24+
"// put your main code here, to run repeatedly:\n" +
25+
"}");
26+
27+
menuToolsAutoFormat.click();
28+
29+
String formattedText = editor.getText();
30+
assertEquals("void setup() {\n" +
31+
" // put your setup code here, to run once:\n" +
32+
" int foo[] = { 1, 2, 3, 4, 5};\n" +
33+
" int foo[2][5] = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}};\n" +
34+
"}\n" +
35+
"\n" +
36+
"void loop() {\n" +
37+
" // put your main code here, to run repeatedly:\n" +
38+
"}", formattedText);
39+
40+
}
41+
}

0 commit comments

Comments
 (0)