Adding AutoformatTest

This commit is contained in:
Federico Fissore 2013-10-15 18:09:09 +02:00
parent 995f0faf46
commit f7f616c3bb
2 changed files with 42 additions and 0 deletions

View File

@ -903,6 +903,7 @@ public class Editor extends JFrame implements RunnerListener {
JMenuItem item;
item = createToolMenuItem("cc.arduino.packages.formatter.AStyle");
item.setName("menuToolsAutoFormat");
int modifiers = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
item.setAccelerator(KeyStroke.getKeyStroke('T', modifiers));
menu.add(item);

View File

@ -0,0 +1,41 @@
package processing.app;
import org.fest.swing.fixture.JMenuItemFixture;
import org.junit.Test;
import processing.app.helpers.JEditTextAreaFixture;
import static org.junit.Assert.assertEquals;
public class AutoformatTest extends AbstractGUITest {
@Test
public void shouldProduceNicelyFormattedCode() throws Exception {
JMenuItemFixture menuToolsAutoFormat = window.menuItem("menuToolsAutoFormat");
menuToolsAutoFormat.requireEnabled();
JEditTextAreaFixture editor = window.jEditTextArea("editor");
editor.setText("void setup() {\n" +
"// put your setup code here, to run once:\n" +
"int foo[] = { 1, 2, 3, 4, 5};\n" +
"int foo[2][5] = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}};\n" +
"}\n" +
"\n" +
"void loop() {\n" +
"// put your main code here, to run repeatedly:\n" +
"}");
menuToolsAutoFormat.click();
String formattedText = editor.getText();
assertEquals("void setup() {\n" +
" // put your setup code here, to run once:\n" +
" int foo[] = { 1, 2, 3, 4, 5};\n" +
" int foo[2][5] = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}};\n" +
"}\n" +
"\n" +
"void loop() {\n" +
" // put your main code here, to run repeatedly:\n" +
"}", formattedText);
}
}