Formatter test is generated now

This commit is contained in:
Andrey Breslav
2013-09-20 15:02:44 +04:00
parent 9d7b3a7a96
commit 8952365ae3
80 changed files with 276 additions and 229 deletions
@@ -35,6 +35,7 @@ import org.jetbrains.jet.completion.weighers.AbstractCompletionWeigherTest;
import org.jetbrains.jet.descriptors.serialization.AbstractDescriptorSerializationTest;
import org.jetbrains.jet.editor.quickDoc.AbstractJetQuickDocProviderTest;
import org.jetbrains.jet.findUsages.AbstractJetFindUsagesTest;
import org.jetbrains.jet.formatter.AbstractJetFormatterTest;
import org.jetbrains.jet.jvm.compiler.*;
import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveDescriptorRendererTest;
import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveNamespaceComparingTest;
@@ -484,6 +485,13 @@ public class GenerateTests {
new SimpleTestClassModel(new File("idea/testData/configuration/gradle"), true, Pattern.compile("(\\w+)_before\\.gradle$"), "doTestGradle"),
testModelWithDirectories("idea/testData/configuration/maven", "doTestWithMaven")
);
generateTest(
"idea/tests/",
"JetFormatterTestGenerated",
AbstractJetFormatterTest.class,
testModelWithPattern("idea/testData/formatter", "^([^\\.]+)\\.kt$", "doTest")
);
}
private static SimpleTestClassModel testModel(@NotNull String rootPath) {
@@ -0,0 +1,39 @@
class Some {
fun some() {
var int: Int = 0
int = 12
int += 12
int -= 12
int *= 12
int /= 12
int %= 12
true && true
true || false
12 === 3
12 !== 3
12 == 3
12 != 3
12 <= 3
12 >= 3
12 < 3
12 > 3
12 + 3 - 12
12 % 3 * 12 / 3
!true
int++
++int
int--
--int
+12
-12
1..2
}
}
@@ -19,7 +19,6 @@ package org.jetbrains.jet.formatter;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.impl.DocumentImpl;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.openapi.util.TextRange;
@@ -32,7 +31,9 @@ import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.testFramework.LightIdeaTestCase;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.plugin.PluginTestCaseBase;
import org.jetbrains.jet.testing.SettingsConfigurator;
import java.io.File;
import java.util.EnumMap;
@@ -76,23 +77,11 @@ public abstract class AbstractJetFormatterTest extends LightIdeaTestCase {
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.HIGHEST);
}
public void doTest() throws Exception {
doTest(getTestName(false) + ".kt", getTestName(false) + "_after.kt");
public void doTextTest(@NonNls String text, File fileAfter) throws IncorrectOperationException {
doTextTest(Action.REFORMAT, text, fileAfter);
}
public void doTest(@NonNls String fileNameBefore, @NonNls String fileNameAfter) throws Exception {
doTextTest(Action.REFORMAT, loadFile(fileNameBefore), loadFile(fileNameAfter), "");
}
public void doTextTest(@NonNls String text, @NonNls String textAfter, String commentToTextCompare) throws IncorrectOperationException {
doTextTest(Action.REFORMAT, text, textAfter, commentToTextCompare);
}
public void doIndentTextTest(@NonNls String text, @NonNls String textAfter) throws IncorrectOperationException {
doTextTest(Action.INDENT, text, textAfter, "");
}
public void doTextTest(final Action action, final String text, String textAfter, String commentToTextCompare) throws IncorrectOperationException {
public void doTextTest(final Action action, final String text, File fileAfter) throws IncorrectOperationException {
final PsiFile file = createFile("A.kt", text);
if (myLineRange != null) {
@@ -132,34 +121,9 @@ public abstract class AbstractJetFormatterTest extends LightIdeaTestCase {
fail("Don't expect the document to be null");
return;
}
assertEquals(commentToTextCompare, prepareText(textAfter), prepareText(document.getText()));
JetTestUtils.assertEqualsToFile(fileAfter, document.getText());
manager.commitDocument(document);
assertEquals(commentToTextCompare, prepareText(textAfter), prepareText(file.getText()));
}
private static String prepareText(String actual) {
if (actual.startsWith("\n")) {
actual = actual.substring(1);
}
if (actual.startsWith("\n")) {
actual = actual.substring(1);
}
// Strip trailing spaces
final Document doc = EditorFactory.getInstance().createDocument(actual);
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
((DocumentImpl)doc).stripTrailingSpaces();
}
});
}
}, "formatting", null);
return doc.getText();
JetTestUtils.assertEqualsToFile(fileAfter, file.getText());
}
protected static String loadFile(String name) throws Exception {
@@ -167,4 +131,21 @@ public abstract class AbstractJetFormatterTest extends LightIdeaTestCase {
text = StringUtil.convertLineSeparators(text);
return text;
}
public void doTest(String testFileNameWithExtension) throws Exception {
String testFileName = FileUtil.getNameWithoutExtension(testFileNameWithExtension);
String originalFileText = FileUtil.loadFile(new File(testFileName + ".kt"), true);
SettingsConfigurator configurator = JetFormatSettingsUtil.createConfigurator(originalFileText, JetFormatSettingsUtil.getSettings());
configurator.configureSettings();
doTextTest(originalFileText, new File(testFileName + ".after.kt"));
String afterInvertedFileName = testFileName + ".after_inv.kt";
if (new File(afterInvertedFileName).exists()) {
configurator.configureInvertedSettings();
doTextTest(originalFileText, new File(afterInvertedFileName));
}
JetFormatSettingsUtil.getSettings().clearCodeStyleSettings();
}
}
@@ -1,185 +0,0 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.formatter;
import org.jetbrains.jet.testing.SettingsConfigurator;
/**
* Based on com.intellij.psi.formatter.java.JavaFormatterTest
*/
public class JetFormatterTest extends AbstractJetFormatterTest {
public void testBlockFor() throws Exception {
doTest();
}
public void testClass() throws Exception {
doTest();
}
public void testCommentInFunctionLiteral() throws Exception {
doTest();
}
public void testConsecutiveCalls() throws Exception {
doTest();
}
public void testEmptyLineAfterPackage() throws Exception {
doTest();
}
public void testForNoBraces() throws Exception {
doTest();
}
public void testFunctionCallParametersAlign() throws Exception {
doTest();
}
public void testFunctionDefParametersAlign() throws Exception {
doTest();
}
public void testFunctionWithInference() throws Exception {
doTest();
}
public void testFunctionWithNewLineBrace() throws Exception {
doTest();
}
public void testGetterAndSetter() throws Exception {
doTest();
}
public void testIf() throws Exception {
doTest();
}
public void testKDoc() throws Exception {
doTest();
}
public void testMultilineFunctionLiteral() throws Exception {
doTest();
}
public void testMultilineFunctionLiteralWithParams() throws Exception {
doTestWithInvert();
}
public void testParameters() throws Exception {
doTestWithInvert();
}
public void testPropertyWithInference() throws Exception {
doTest();
}
public void testRightBracketOnNewLine() throws Exception {
doTestWithInvert();
}
public void testSaveSpacesInDocComments() throws Exception {
doTest();
}
public void testSingleLineFunctionLiteral() throws Exception {
doTestWithInvert();
}
public void testSpaceAroundExtendColon() throws Exception {
doTestWithInvert();
}
public void testSpaceBeforeFunctionLiteral() throws Exception {
doTest();
}
public void testSpacesAroundOperations() throws Exception {
doTestWithInvert();
}
public void testSpacesAroundUnaryOperations() throws Exception {
doTestWithInvert();
}
public void testUnnecessarySpacesInParametersLists() throws Exception {
doTest();
}
public void testWhen() throws Exception {
doTestWithInvert();
}
public void testWhenEntryExpr() throws Exception {
doTest();
}
public void testWhenArrow() throws Exception {
doTestWithInvert();
}
public void testWhenLinesBeforeLbrace() throws Exception {
doTest();
}
public void testFunctionalType() throws Exception {
doTestWithInvert();
}
public void testLambdaArrow() throws Exception {
doTestWithInvert();
}
public void testReferenceExpressionFunctionLiteral() throws Exception {
doTest();
}
@Override
public void doTest() throws Exception {
String originalFileText = AbstractJetFormatterTest.loadFile(getTestName(false) + ".kt");
String afterFileName = getTestName(false) + "_after.kt";
String afterText = AbstractJetFormatterTest.loadFile(afterFileName);
SettingsConfigurator configurator = JetFormatSettingsUtil.createConfigurator(originalFileText);
configurator.configureSettings();
doTextTest(originalFileText, afterText, String.format("Failure in NORMAL file: %s", afterFileName));
JetFormatSettingsUtil.getSettings().clearCodeStyleSettings();
}
public void doTestWithInvert() throws Exception {
String originalFileText = AbstractJetFormatterTest.loadFile(getTestName(false) + ".kt");
SettingsConfigurator configurator = JetFormatSettingsUtil.createConfigurator(originalFileText, JetFormatSettingsUtil.getSettings());
String afterFileName = getTestName(false) + "_after.kt";
String afterText = AbstractJetFormatterTest.loadFile(afterFileName);
configurator.configureSettings();
doTextTest(originalFileText, afterText, String.format("Failure in NORMAL file: %s", afterFileName));
String afterInvertedFileName = getTestName(false) + "_after_inv.kt";
String afterInvertedText = AbstractJetFormatterTest.loadFile(afterInvertedFileName);
configurator.configureInvertedSettings();
doTextTest(originalFileText, afterInvertedText, String.format("Failure in INVERTED file: %s", afterInvertedFileName));
JetFormatSettingsUtil.getSettings().clearCodeStyleSettings();
}
}
@@ -0,0 +1,204 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.formatter;
import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestSuite;
import java.io.File;
import java.util.regex.Pattern;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import org.jetbrains.jet.formatter.AbstractJetFormatterTest;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/formatter")
public class JetFormatterTestGenerated extends AbstractJetFormatterTest {
public void testAllFilesPresentInFormatter() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/formatter"), Pattern.compile("^([^\\.]+)\\.kt$"), true);
}
@TestMetadata("BlockFor.kt")
public void testBlockFor() throws Exception {
doTest("idea/testData/formatter/BlockFor.kt");
}
@TestMetadata("Class.kt")
public void testClass() throws Exception {
doTest("idea/testData/formatter/Class.kt");
}
@TestMetadata("CommentInFunctionLiteral.kt")
public void testCommentInFunctionLiteral() throws Exception {
doTest("idea/testData/formatter/CommentInFunctionLiteral.kt");
}
@TestMetadata("ConsecutiveCalls.kt")
public void testConsecutiveCalls() throws Exception {
doTest("idea/testData/formatter/ConsecutiveCalls.kt");
}
@TestMetadata("EmptyLineAfterPackage.kt")
public void testEmptyLineAfterPackage() throws Exception {
doTest("idea/testData/formatter/EmptyLineAfterPackage.kt");
}
@TestMetadata("ForNoBraces.kt")
public void testForNoBraces() throws Exception {
doTest("idea/testData/formatter/ForNoBraces.kt");
}
@TestMetadata("FunctionCallParametersAlign.kt")
public void testFunctionCallParametersAlign() throws Exception {
doTest("idea/testData/formatter/FunctionCallParametersAlign.kt");
}
@TestMetadata("FunctionDefParametersAlign.kt")
public void testFunctionDefParametersAlign() throws Exception {
doTest("idea/testData/formatter/FunctionDefParametersAlign.kt");
}
@TestMetadata("FunctionWithInference.kt")
public void testFunctionWithInference() throws Exception {
doTest("idea/testData/formatter/FunctionWithInference.kt");
}
@TestMetadata("FunctionWithNewLineBrace.kt")
public void testFunctionWithNewLineBrace() throws Exception {
doTest("idea/testData/formatter/FunctionWithNewLineBrace.kt");
}
@TestMetadata("FunctionalType.kt")
public void testFunctionalType() throws Exception {
doTest("idea/testData/formatter/FunctionalType.kt");
}
@TestMetadata("GetterAndSetter.kt")
public void testGetterAndSetter() throws Exception {
doTest("idea/testData/formatter/GetterAndSetter.kt");
}
@TestMetadata("If.kt")
public void testIf() throws Exception {
doTest("idea/testData/formatter/If.kt");
}
@TestMetadata("KDoc.kt")
public void testKDoc() throws Exception {
doTest("idea/testData/formatter/KDoc.kt");
}
@TestMetadata("LambdaArrow.kt")
public void testLambdaArrow() throws Exception {
doTest("idea/testData/formatter/LambdaArrow.kt");
}
@TestMetadata("MultilineFunctionLiteral.kt")
public void testMultilineFunctionLiteral() throws Exception {
doTest("idea/testData/formatter/MultilineFunctionLiteral.kt");
}
@TestMetadata("MultilineFunctionLiteralWithParams.kt")
public void testMultilineFunctionLiteralWithParams() throws Exception {
doTest("idea/testData/formatter/MultilineFunctionLiteralWithParams.kt");
}
@TestMetadata("Parameters.kt")
public void testParameters() throws Exception {
doTest("idea/testData/formatter/Parameters.kt");
}
@TestMetadata("PropertyWithInference.kt")
public void testPropertyWithInference() throws Exception {
doTest("idea/testData/formatter/PropertyWithInference.kt");
}
@TestMetadata("ReferenceExpressionFunctionLiteral.kt")
public void testReferenceExpressionFunctionLiteral() throws Exception {
doTest("idea/testData/formatter/ReferenceExpressionFunctionLiteral.kt");
}
@TestMetadata("RemoveSpacesAroundOperations.kt")
public void testRemoveSpacesAroundOperations() throws Exception {
doTest("idea/testData/formatter/RemoveSpacesAroundOperations.kt");
}
@TestMetadata("RightBracketOnNewLine.kt")
public void testRightBracketOnNewLine() throws Exception {
doTest("idea/testData/formatter/RightBracketOnNewLine.kt");
}
@TestMetadata("SaveSpacesInDocComments.kt")
public void testSaveSpacesInDocComments() throws Exception {
doTest("idea/testData/formatter/SaveSpacesInDocComments.kt");
}
@TestMetadata("SingleLineFunctionLiteral.kt")
public void testSingleLineFunctionLiteral() throws Exception {
doTest("idea/testData/formatter/SingleLineFunctionLiteral.kt");
}
@TestMetadata("SpaceAroundExtendColon.kt")
public void testSpaceAroundExtendColon() throws Exception {
doTest("idea/testData/formatter/SpaceAroundExtendColon.kt");
}
@TestMetadata("SpaceBeforeFunctionLiteral.kt")
public void testSpaceBeforeFunctionLiteral() throws Exception {
doTest("idea/testData/formatter/SpaceBeforeFunctionLiteral.kt");
}
@TestMetadata("SpacesAroundOperations.kt")
public void testSpacesAroundOperations() throws Exception {
doTest("idea/testData/formatter/SpacesAroundOperations.kt");
}
@TestMetadata("SpacesAroundUnaryOperations.kt")
public void testSpacesAroundUnaryOperations() throws Exception {
doTest("idea/testData/formatter/SpacesAroundUnaryOperations.kt");
}
@TestMetadata("UnnecessarySpacesInParametersLists.kt")
public void testUnnecessarySpacesInParametersLists() throws Exception {
doTest("idea/testData/formatter/UnnecessarySpacesInParametersLists.kt");
}
@TestMetadata("When.kt")
public void testWhen() throws Exception {
doTest("idea/testData/formatter/When.kt");
}
@TestMetadata("WhenArrow.kt")
public void testWhenArrow() throws Exception {
doTest("idea/testData/formatter/WhenArrow.kt");
}
@TestMetadata("WhenEntryExpr.kt")
public void testWhenEntryExpr() throws Exception {
doTest("idea/testData/formatter/WhenEntryExpr.kt");
}
@TestMetadata("WhenLinesBeforeLbrace.kt")
public void testWhenLinesBeforeLbrace() throws Exception {
doTest("idea/testData/formatter/WhenLinesBeforeLbrace.kt");
}
}
@@ -131,7 +131,7 @@ public class JetTypingIndentationTest extends LightCodeInsightTestCase {
@NotNull
@Override
protected String getTestDataPath() {
String testRelativeDir = "formatter/IndentationOnNewline";
String testRelativeDir = "indentationOnNewline";
return new File(PluginTestCaseBase.getTestDataPathBase(), testRelativeDir).getPath() +
File.separator;
}