Rewrite tests for formatting during typing with auto generator

This commit is contained in:
Nikolay Krasko
2014-04-22 17:10:57 +04:00
parent 13dce4dd11
commit c42908eff7
30 changed files with 272 additions and 215 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
* Copyright 2010-2014 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.
@@ -105,6 +105,7 @@ import org.jetbrains.jet.plugin.codeInsight.AbstractJetInspectionTest
import org.jetbrains.jet.plugin.debugger.AbstractKotlinSteppingTest
import org.jetbrains.jet.completion.AbstractMultiFileJvmBasicCompletionTest
import org.jetbrains.jet.plugin.refactoring.introduce.introduceVariable.AbstractJetExtractionTest
import org.jetbrains.jet.formatter.AbstractJetTypingIndentationTestBase
import org.jetbrains.jet.plugin.debugger.evaluate.AbstractKotlinEvaluateExpressionTest
import org.jetbrains.jet.plugin.debugger.evaluate.AbstractSelectExpressionForDebuggerTest
import org.jetbrains.jet.plugin.debugger.evaluate.AbstractCodeFragmentCompletionTest
@@ -518,6 +519,13 @@ fun main(args: Array<String>) {
testMethod = "doTestInverted", testClassName = "FormatterInverted")
}
testClass(javaClass<AbstractJetTypingIndentationTestBase>()) {
model("indentationOnNewline", pattern = """^([^\.]+)\.after\.kt.*$""", testMethod = "doNewlineTest",
testClassName = "DirectSettings")
model("indentationOnNewline", pattern = """^([^\.]+)\.after\.inv\.kt.*$""", testMethod = "doNewlineTestWithInvert",
testClassName = "InvertedSettings")
}
testClass(javaClass<AbstractDiagnosticMessageTest>()) {
model("diagnosticMessage")
}
@@ -0,0 +1,85 @@
/*
* Copyright 2010-2014 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 com.intellij.openapi.editor.CaretModel;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.testFramework.EditorTestUtil;
import com.intellij.testFramework.LightCodeInsightTestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.plugin.PluginTestCaseBase;
import org.jetbrains.jet.testing.SettingsConfigurator;
import java.io.File;
public abstract class AbstractJetTypingIndentationTestBase extends LightCodeInsightTestCase {
public void doNewlineTest(String afterFilePath) throws Exception {
doNewlineTest(afterFilePath, false);
}
public void doNewlineTestWithInvert(String afterInvFilePath) throws Exception {
doNewlineTest(afterInvFilePath, true);
}
public void doNewlineTest(String afterFilePath, boolean inverted) throws Exception {
String testFileName = afterFilePath.substring(0, afterFilePath.indexOf("."));
String testFileExtension = afterFilePath.substring(afterFilePath.lastIndexOf("."));
String originFilePath = testFileName + testFileExtension;
String originalFileText = FileUtil.loadFile(new File(originFilePath), true);
try {
SettingsConfigurator configurator = JetFormatSettingsUtil.createConfigurator(originalFileText);
if (!inverted) {
configurator.configureSettings();
}
else {
configurator.configureInvertedSettings();
}
doNewlineTest(originFilePath, afterFilePath);
}
finally {
getSettings().clearCodeStyleSettings();
}
}
private void doNewlineTest(String beforeFilePath, String afterFilePath) {
configureByFile(beforeFilePath);
type('\n');
CaretModel caretModel = getEditor().getCaretModel();
int offset = caretModel.getOffset();
String actualTextWithCaret = new StringBuilder(getFile().getText()).insert(offset, EditorTestUtil.CARET_TAG).toString();
JetTestUtils.assertEqualsToFile(new File(afterFilePath), actualTextWithCaret);
}
public static CodeStyleSettings getSettings() {
return CodeStyleSettingsManager.getSettings(getProject());
}
@NotNull
@Override
protected String getTestDataPath() {
return "";
}
}
@@ -1,46 +0,0 @@
/*
* Copyright 2010-2014 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;
public class JetScriptTypingIndentationTest extends JetTypingIndentationTestBase {
public void testScriptAfterFun() {
doFileNewlineTest();
}
public void testScriptAfterImport() {
doFileNewlineTest();
}
public void testScriptAfterExpression() {
doFileNewlineTest();
}
public void testScriptInsideFun() {
doFileNewlineTest();
}
@Override
public String getBeforeFileName() {
return getTestName(false) + ".kts";
}
@Override
public String getAfterFileName() {
return getTestName(false) + "_after.kts";
}
}
@@ -1,90 +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 com.intellij.openapi.util.io.FileUtil;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.testFramework.LightCodeInsightTestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.plugin.PluginTestCaseBase;
import org.jetbrains.jet.testing.SettingsConfigurator;
import java.io.File;
public class JetTypingIndentationTest extends JetTypingIndentationTestBase {
public void testAfterCatch() {
doFileNewlineTest();
}
public void testAfterFinally() {
doFileNewlineTest();
}
public void testAfterImport() {
doFileNewlineTest();
}
public void testAfterTry() {
doFileNewlineTest();
}
public void testConsecutiveCallsAfterDot() {
doFileNewlineTest();
}
public void testDoInFun() {
doFileNewlineTest();
}
public void testEmptyParameters() {
doFileNewlineTest();
}
public void testFor() {
doFileNewlineTest();
}
public void testFunctionBlock() {
doFileNewlineTest();
}
public void testFunctionWithInference() {
doFileNewlineTest();
}
public void testIf() {
doFileNewlineTest();
}
public void testNotFirstParameter() {
doFileNewlineTest();
}
public void testPropertyWithInference() {
doFileNewlineTest();
}
public void testSettingAlignMultilineParametersInCalls() throws Exception {
doFileSettingNewLineTest();
}
public void testWhile() {
doFileNewlineTest();
}
}
@@ -1,78 +0,0 @@
/*
* Copyright 2010-2014 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 com.intellij.openapi.util.io.FileUtil;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.testFramework.LightCodeInsightTestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.plugin.PluginTestCaseBase;
import org.jetbrains.jet.testing.SettingsConfigurator;
import java.io.File;
public abstract class JetTypingIndentationTestBase extends LightCodeInsightTestCase {
public void doFileNewlineTest() {
doNewlineTest(getBeforeFileName(), getAfterFileName());
}
public String getBeforeFileName() {
return getTestName(false) + ".kt";
}
public String getAfterFileName() {
return getTestName(false) + "_after.kt";
}
public String getInvertedAfterFileName() {
return getTestName(false) + "_after_inv.kt";
}
public void doFileSettingNewLineTest() throws Exception {
String originalFileText = FileUtil.loadFile(new File(getTestDataPath(), getBeforeFileName()), true);
SettingsConfigurator configurator = JetFormatSettingsUtil.createConfigurator(originalFileText);
configurator.configureSettings();
doNewlineTest(getBeforeFileName(), getAfterFileName());
configurator.configureInvertedSettings();
doNewlineTest(getBeforeFileName(), getInvertedAfterFileName());
getSettings().clearCodeStyleSettings();
}
private void doNewlineTest(String beforeFileName, String afterFileName) {
configureByFile(beforeFileName);
type('\n');
checkResultByFile(afterFileName);
}
public static CodeStyleSettings getSettings() {
return CodeStyleSettingsManager.getSettings(getProject());
}
@NotNull
@Override
protected String getTestDataPath() {
String testRelativeDir = "indentationOnNewline";
return new File(PluginTestCaseBase.getTestDataPathBase(), testRelativeDir).getPath() +
File.separator;
}
}
@@ -0,0 +1,178 @@
/*
* Copyright 2010-2014 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.AbstractJetTypingIndentationTestBase;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@InnerTestClasses({JetTypingIndentationTestBaseGenerated.DirectSettings.class, JetTypingIndentationTestBaseGenerated.InvertedSettings.class})
public class JetTypingIndentationTestBaseGenerated extends AbstractJetTypingIndentationTestBase {
@TestMetadata("idea/testData/indentationOnNewline")
@InnerTestClasses({DirectSettings.Script.class})
public static class DirectSettings extends AbstractJetTypingIndentationTestBase {
@TestMetadata("AfterCatch.after.kt")
public void testAfterCatch() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/AfterCatch.after.kt");
}
@TestMetadata("AfterFinally.after.kt")
public void testAfterFinally() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/AfterFinally.after.kt");
}
@TestMetadata("AfterImport.after.kt")
public void testAfterImport() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/AfterImport.after.kt");
}
@TestMetadata("AfterTry.after.kt")
public void testAfterTry() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/AfterTry.after.kt");
}
public void testAllFilesPresentInDirectSettings() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/indentationOnNewline"), Pattern.compile("^([^\\.]+)\\.after\\.kt.*$"), true);
}
@TestMetadata("ConsecutiveCallsAfterDot.after.kt")
public void testConsecutiveCallsAfterDot() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/ConsecutiveCallsAfterDot.after.kt");
}
@TestMetadata("DoInFun.after.kt")
public void testDoInFun() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/DoInFun.after.kt");
}
@TestMetadata("EmptyParameters.after.kt")
public void testEmptyParameters() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/EmptyParameters.after.kt");
}
@TestMetadata("For.after.kt")
public void testFor() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/For.after.kt");
}
@TestMetadata("FunctionBlock.after.kt")
public void testFunctionBlock() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/FunctionBlock.after.kt");
}
@TestMetadata("FunctionWithInference.after.kt")
public void testFunctionWithInference() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/FunctionWithInference.after.kt");
}
@TestMetadata("If.after.kt")
public void testIf() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/If.after.kt");
}
@TestMetadata("NotFirstParameter.after.kt")
public void testNotFirstParameter() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/NotFirstParameter.after.kt");
}
@TestMetadata("PropertyWithInference.after.kt")
public void testPropertyWithInference() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/PropertyWithInference.after.kt");
}
@TestMetadata("SettingAlignMultilineParametersInCalls.after.kt")
public void testSettingAlignMultilineParametersInCalls() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/SettingAlignMultilineParametersInCalls.after.kt");
}
@TestMetadata("While.after.kt")
public void testWhile() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/While.after.kt");
}
@TestMetadata("idea/testData/indentationOnNewline/script")
public static class Script extends AbstractJetTypingIndentationTestBase {
public void testAllFilesPresentInScript() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/indentationOnNewline/script"), Pattern.compile("^([^\\.]+)\\.after\\.kt.*$"), true);
}
@TestMetadata("ScriptAfterExpression.after.kts")
public void testScriptAfterExpression() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/script/ScriptAfterExpression.after.kts");
}
@TestMetadata("ScriptAfterFun.after.kts")
public void testScriptAfterFun() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/script/ScriptAfterFun.after.kts");
}
@TestMetadata("ScriptAfterImport.after.kts")
public void testScriptAfterImport() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/script/ScriptAfterImport.after.kts");
}
@TestMetadata("ScriptInsideFun.after.kts")
public void testScriptInsideFun() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/script/ScriptInsideFun.after.kts");
}
}
public static Test innerSuite() {
TestSuite suite = new TestSuite("DirectSettings");
suite.addTestSuite(DirectSettings.class);
suite.addTestSuite(Script.class);
return suite;
}
}
@TestMetadata("idea/testData/indentationOnNewline")
@InnerTestClasses({})
public static class InvertedSettings extends AbstractJetTypingIndentationTestBase {
public void testAllFilesPresentInInvertedSettings() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/indentationOnNewline"), Pattern.compile("^([^\\.]+)\\.after\\.inv\\.kt.*$"), true);
}
@TestMetadata("SettingAlignMultilineParametersInCalls.after.inv.kt")
public void testSettingAlignMultilineParametersInCalls() throws Exception {
doNewlineTestWithInvert("idea/testData/indentationOnNewline/SettingAlignMultilineParametersInCalls.after.inv.kt");
}
public static Test innerSuite() {
TestSuite suite = new TestSuite("InvertedSettings");
suite.addTestSuite(InvertedSettings.class);
return suite;
}
}
public static Test suite() {
TestSuite suite = new TestSuite("JetTypingIndentationTestBaseGenerated");
suite.addTest(DirectSettings.innerSuite());
suite.addTest(InvertedSettings.innerSuite());
return suite;
}
}