diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 22c18a9f7..c7e6c8a1c 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -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); diff --git a/app/test/processing/app/AutoformatTest.java b/app/test/processing/app/AutoformatTest.java new file mode 100644 index 000000000..51fdc35d6 --- /dev/null +++ b/app/test/processing/app/AutoformatTest.java @@ -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); + + } +}