|
| 1 | +package processing.app; |
| 2 | + |
| 3 | +import org.fest.swing.fixture.JMenuItemFixture; |
| 4 | +import org.junit.Test; |
| 5 | +import processing.app.helpers.RSyntaxTextAreaFixture; |
| 6 | + |
| 7 | +import static org.junit.Assert.assertEquals; |
| 8 | +import static org.junit.Assert.assertNotEquals; |
| 9 | + |
| 10 | +public class AutoformatProducesOneUndoActionTest extends AbstractGUITest { |
| 11 | + |
| 12 | + public static final String SOURCE_BEFORE = "void setup() {\n" + |
| 13 | + " // put your setup code here, to run once:\n" + |
| 14 | + "\n" + |
| 15 | + "}\n" + |
| 16 | + "\n" + |
| 17 | + "void loop() {\n" + |
| 18 | + " // put your main code here, to run repeatedly:\n" + |
| 19 | + "\n" + |
| 20 | + "}"; |
| 21 | + public static final String SOURCE_AFTER = "void setup() {\n" + |
| 22 | + " // put your setup code here, to run once:\n" + |
| 23 | + "\n" + |
| 24 | + "}\n" + |
| 25 | + "\n" + |
| 26 | + "void loop() {\n" + |
| 27 | + " // put your main code here, to run repeatedly:\n" + |
| 28 | + "\n" + |
| 29 | + "}"; |
| 30 | + |
| 31 | + @Test |
| 32 | + public void shouldSaveCaretPositionAfterAutoformat() { |
| 33 | + JMenuItemFixture menuEditUndo = window.menuItem("menuEditUndo"); |
| 34 | + menuEditUndo.requireDisabled(); |
| 35 | + |
| 36 | + JMenuItemFixture menuToolsAutoFormat = window.menuItem("menuToolsAutoFormat"); |
| 37 | + menuToolsAutoFormat.requireEnabled(); |
| 38 | + |
| 39 | + RSyntaxTextAreaFixture editor = window.RSyntaxTextArea("editor"); |
| 40 | + editor.setText(SOURCE_BEFORE); |
| 41 | + |
| 42 | + editor.setCaretPosition(29); // right before the first // (double slash) |
| 43 | + |
| 44 | + menuToolsAutoFormat.click(); |
| 45 | + |
| 46 | + String formattedText = editor.getText(); |
| 47 | + assertEquals(SOURCE_AFTER, formattedText); |
| 48 | + |
| 49 | + assertEquals(29, editor.getCaretPosition()); |
| 50 | + |
| 51 | + menuEditUndo.requireEnabled(); |
| 52 | + menuEditUndo.click(); |
| 53 | + assertEquals(SOURCE_BEFORE, editor.getText()); |
| 54 | + } |
| 55 | + |
| 56 | +} |
0 commit comments