From c42908eff756cd70fdd5d16ef993555f42804d97 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Tue, 22 Apr 2014 17:10:57 +0400 Subject: [PATCH] Rewrite tests for formatting during typing with auto generator --- .../jet/generators/tests/GenerateTests.kt | 10 +- ...fterCatch_after.kt => AfterCatch.after.kt} | 0 ...Finally_after.kt => AfterFinally.after.kt} | 0 ...erImport_after.kt => AfterImport.after.kt} | 0 .../{AfterTry_after.kt => AfterTry.after.kt} | 0 ...r.kt => ConsecutiveCallsAfterDot.after.kt} | 0 .../{DoInFun_after.kt => DoInFun.after.kt} | 0 ...ters_after.kt => EmptyParameters.after.kt} | 0 .../{For_after.kt => For.after.kt} | 0 ...nBlock_after.kt => FunctionBlock.after.kt} | 0 ...fter.kt => FunctionWithInference.after.kt} | 0 .../{If_after.kt => If.after.kt} | 0 ...er_after.kt => NotFirstParameter.after.kt} | 0 ...fter.kt => PropertyWithInference.after.kt} | 0 ...gnMultilineParametersInCalls.after.inv.kt} | 0 ...gAlignMultilineParametersInCalls.after.kt} | 0 .../{While_after.kt => While.after.kt} | 0 .../ScriptAfterExpression.after.kts} | 0 .../{ => script}/ScriptAfterExpression.kts | 0 .../ScriptAfterFun.after.kts} | 0 .../{ => script}/ScriptAfterFun.kts | 0 .../ScriptAfterImport.after.kts} | 0 .../{ => script}/ScriptAfterImport.kts | 0 .../ScriptInsideFun.after.kts} | 0 .../{ => script}/ScriptInsideFun.kts | 0 .../AbstractJetTypingIndentationTestBase.java | 85 +++++++++ .../JetScriptTypingIndentationTest.java | 46 ----- .../formatter/JetTypingIndentationTest.java | 90 --------- .../JetTypingIndentationTestBase.java | 78 -------- ...JetTypingIndentationTestBaseGenerated.java | 178 ++++++++++++++++++ 30 files changed, 272 insertions(+), 215 deletions(-) rename idea/testData/indentationOnNewline/{AfterCatch_after.kt => AfterCatch.after.kt} (100%) rename idea/testData/indentationOnNewline/{AfterFinally_after.kt => AfterFinally.after.kt} (100%) rename idea/testData/indentationOnNewline/{AfterImport_after.kt => AfterImport.after.kt} (100%) rename idea/testData/indentationOnNewline/{AfterTry_after.kt => AfterTry.after.kt} (100%) rename idea/testData/indentationOnNewline/{ConsecutiveCallsAfterDot_after.kt => ConsecutiveCallsAfterDot.after.kt} (100%) rename idea/testData/indentationOnNewline/{DoInFun_after.kt => DoInFun.after.kt} (100%) rename idea/testData/indentationOnNewline/{EmptyParameters_after.kt => EmptyParameters.after.kt} (100%) rename idea/testData/indentationOnNewline/{For_after.kt => For.after.kt} (100%) rename idea/testData/indentationOnNewline/{FunctionBlock_after.kt => FunctionBlock.after.kt} (100%) rename idea/testData/indentationOnNewline/{FunctionWithInference_after.kt => FunctionWithInference.after.kt} (100%) rename idea/testData/indentationOnNewline/{If_after.kt => If.after.kt} (100%) rename idea/testData/indentationOnNewline/{NotFirstParameter_after.kt => NotFirstParameter.after.kt} (100%) rename idea/testData/indentationOnNewline/{PropertyWithInference_after.kt => PropertyWithInference.after.kt} (100%) rename idea/testData/indentationOnNewline/{SettingAlignMultilineParametersInCalls_after_inv.kt => SettingAlignMultilineParametersInCalls.after.inv.kt} (100%) rename idea/testData/indentationOnNewline/{SettingAlignMultilineParametersInCalls_after.kt => SettingAlignMultilineParametersInCalls.after.kt} (100%) rename idea/testData/indentationOnNewline/{While_after.kt => While.after.kt} (100%) rename idea/testData/indentationOnNewline/{ScriptAfterExpression_after.kts => script/ScriptAfterExpression.after.kts} (100%) rename idea/testData/indentationOnNewline/{ => script}/ScriptAfterExpression.kts (100%) rename idea/testData/indentationOnNewline/{ScriptAfterFun_after.kts => script/ScriptAfterFun.after.kts} (100%) rename idea/testData/indentationOnNewline/{ => script}/ScriptAfterFun.kts (100%) rename idea/testData/indentationOnNewline/{ScriptAfterImport_after.kts => script/ScriptAfterImport.after.kts} (100%) rename idea/testData/indentationOnNewline/{ => script}/ScriptAfterImport.kts (100%) rename idea/testData/indentationOnNewline/{ScriptInsideFun_after.kts => script/ScriptInsideFun.after.kts} (100%) rename idea/testData/indentationOnNewline/{ => script}/ScriptInsideFun.kts (100%) create mode 100644 idea/tests/org/jetbrains/jet/formatter/AbstractJetTypingIndentationTestBase.java delete mode 100644 idea/tests/org/jetbrains/jet/formatter/JetScriptTypingIndentationTest.java delete mode 100644 idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTest.java delete mode 100644 idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTestBase.java create mode 100644 idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTestBaseGenerated.java diff --git a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt index 0d657958d76..77782ebd9ae 100644 --- a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt @@ -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) { testMethod = "doTestInverted", testClassName = "FormatterInverted") } + testClass(javaClass()) { + model("indentationOnNewline", pattern = """^([^\.]+)\.after\.kt.*$""", testMethod = "doNewlineTest", + testClassName = "DirectSettings") + model("indentationOnNewline", pattern = """^([^\.]+)\.after\.inv\.kt.*$""", testMethod = "doNewlineTestWithInvert", + testClassName = "InvertedSettings") + } + testClass(javaClass()) { model("diagnosticMessage") } diff --git a/idea/testData/indentationOnNewline/AfterCatch_after.kt b/idea/testData/indentationOnNewline/AfterCatch.after.kt similarity index 100% rename from idea/testData/indentationOnNewline/AfterCatch_after.kt rename to idea/testData/indentationOnNewline/AfterCatch.after.kt diff --git a/idea/testData/indentationOnNewline/AfterFinally_after.kt b/idea/testData/indentationOnNewline/AfterFinally.after.kt similarity index 100% rename from idea/testData/indentationOnNewline/AfterFinally_after.kt rename to idea/testData/indentationOnNewline/AfterFinally.after.kt diff --git a/idea/testData/indentationOnNewline/AfterImport_after.kt b/idea/testData/indentationOnNewline/AfterImport.after.kt similarity index 100% rename from idea/testData/indentationOnNewline/AfterImport_after.kt rename to idea/testData/indentationOnNewline/AfterImport.after.kt diff --git a/idea/testData/indentationOnNewline/AfterTry_after.kt b/idea/testData/indentationOnNewline/AfterTry.after.kt similarity index 100% rename from idea/testData/indentationOnNewline/AfterTry_after.kt rename to idea/testData/indentationOnNewline/AfterTry.after.kt diff --git a/idea/testData/indentationOnNewline/ConsecutiveCallsAfterDot_after.kt b/idea/testData/indentationOnNewline/ConsecutiveCallsAfterDot.after.kt similarity index 100% rename from idea/testData/indentationOnNewline/ConsecutiveCallsAfterDot_after.kt rename to idea/testData/indentationOnNewline/ConsecutiveCallsAfterDot.after.kt diff --git a/idea/testData/indentationOnNewline/DoInFun_after.kt b/idea/testData/indentationOnNewline/DoInFun.after.kt similarity index 100% rename from idea/testData/indentationOnNewline/DoInFun_after.kt rename to idea/testData/indentationOnNewline/DoInFun.after.kt diff --git a/idea/testData/indentationOnNewline/EmptyParameters_after.kt b/idea/testData/indentationOnNewline/EmptyParameters.after.kt similarity index 100% rename from idea/testData/indentationOnNewline/EmptyParameters_after.kt rename to idea/testData/indentationOnNewline/EmptyParameters.after.kt diff --git a/idea/testData/indentationOnNewline/For_after.kt b/idea/testData/indentationOnNewline/For.after.kt similarity index 100% rename from idea/testData/indentationOnNewline/For_after.kt rename to idea/testData/indentationOnNewline/For.after.kt diff --git a/idea/testData/indentationOnNewline/FunctionBlock_after.kt b/idea/testData/indentationOnNewline/FunctionBlock.after.kt similarity index 100% rename from idea/testData/indentationOnNewline/FunctionBlock_after.kt rename to idea/testData/indentationOnNewline/FunctionBlock.after.kt diff --git a/idea/testData/indentationOnNewline/FunctionWithInference_after.kt b/idea/testData/indentationOnNewline/FunctionWithInference.after.kt similarity index 100% rename from idea/testData/indentationOnNewline/FunctionWithInference_after.kt rename to idea/testData/indentationOnNewline/FunctionWithInference.after.kt diff --git a/idea/testData/indentationOnNewline/If_after.kt b/idea/testData/indentationOnNewline/If.after.kt similarity index 100% rename from idea/testData/indentationOnNewline/If_after.kt rename to idea/testData/indentationOnNewline/If.after.kt diff --git a/idea/testData/indentationOnNewline/NotFirstParameter_after.kt b/idea/testData/indentationOnNewline/NotFirstParameter.after.kt similarity index 100% rename from idea/testData/indentationOnNewline/NotFirstParameter_after.kt rename to idea/testData/indentationOnNewline/NotFirstParameter.after.kt diff --git a/idea/testData/indentationOnNewline/PropertyWithInference_after.kt b/idea/testData/indentationOnNewline/PropertyWithInference.after.kt similarity index 100% rename from idea/testData/indentationOnNewline/PropertyWithInference_after.kt rename to idea/testData/indentationOnNewline/PropertyWithInference.after.kt diff --git a/idea/testData/indentationOnNewline/SettingAlignMultilineParametersInCalls_after_inv.kt b/idea/testData/indentationOnNewline/SettingAlignMultilineParametersInCalls.after.inv.kt similarity index 100% rename from idea/testData/indentationOnNewline/SettingAlignMultilineParametersInCalls_after_inv.kt rename to idea/testData/indentationOnNewline/SettingAlignMultilineParametersInCalls.after.inv.kt diff --git a/idea/testData/indentationOnNewline/SettingAlignMultilineParametersInCalls_after.kt b/idea/testData/indentationOnNewline/SettingAlignMultilineParametersInCalls.after.kt similarity index 100% rename from idea/testData/indentationOnNewline/SettingAlignMultilineParametersInCalls_after.kt rename to idea/testData/indentationOnNewline/SettingAlignMultilineParametersInCalls.after.kt diff --git a/idea/testData/indentationOnNewline/While_after.kt b/idea/testData/indentationOnNewline/While.after.kt similarity index 100% rename from idea/testData/indentationOnNewline/While_after.kt rename to idea/testData/indentationOnNewline/While.after.kt diff --git a/idea/testData/indentationOnNewline/ScriptAfterExpression_after.kts b/idea/testData/indentationOnNewline/script/ScriptAfterExpression.after.kts similarity index 100% rename from idea/testData/indentationOnNewline/ScriptAfterExpression_after.kts rename to idea/testData/indentationOnNewline/script/ScriptAfterExpression.after.kts diff --git a/idea/testData/indentationOnNewline/ScriptAfterExpression.kts b/idea/testData/indentationOnNewline/script/ScriptAfterExpression.kts similarity index 100% rename from idea/testData/indentationOnNewline/ScriptAfterExpression.kts rename to idea/testData/indentationOnNewline/script/ScriptAfterExpression.kts diff --git a/idea/testData/indentationOnNewline/ScriptAfterFun_after.kts b/idea/testData/indentationOnNewline/script/ScriptAfterFun.after.kts similarity index 100% rename from idea/testData/indentationOnNewline/ScriptAfterFun_after.kts rename to idea/testData/indentationOnNewline/script/ScriptAfterFun.after.kts diff --git a/idea/testData/indentationOnNewline/ScriptAfterFun.kts b/idea/testData/indentationOnNewline/script/ScriptAfterFun.kts similarity index 100% rename from idea/testData/indentationOnNewline/ScriptAfterFun.kts rename to idea/testData/indentationOnNewline/script/ScriptAfterFun.kts diff --git a/idea/testData/indentationOnNewline/ScriptAfterImport_after.kts b/idea/testData/indentationOnNewline/script/ScriptAfterImport.after.kts similarity index 100% rename from idea/testData/indentationOnNewline/ScriptAfterImport_after.kts rename to idea/testData/indentationOnNewline/script/ScriptAfterImport.after.kts diff --git a/idea/testData/indentationOnNewline/ScriptAfterImport.kts b/idea/testData/indentationOnNewline/script/ScriptAfterImport.kts similarity index 100% rename from idea/testData/indentationOnNewline/ScriptAfterImport.kts rename to idea/testData/indentationOnNewline/script/ScriptAfterImport.kts diff --git a/idea/testData/indentationOnNewline/ScriptInsideFun_after.kts b/idea/testData/indentationOnNewline/script/ScriptInsideFun.after.kts similarity index 100% rename from idea/testData/indentationOnNewline/ScriptInsideFun_after.kts rename to idea/testData/indentationOnNewline/script/ScriptInsideFun.after.kts diff --git a/idea/testData/indentationOnNewline/ScriptInsideFun.kts b/idea/testData/indentationOnNewline/script/ScriptInsideFun.kts similarity index 100% rename from idea/testData/indentationOnNewline/ScriptInsideFun.kts rename to idea/testData/indentationOnNewline/script/ScriptInsideFun.kts diff --git a/idea/tests/org/jetbrains/jet/formatter/AbstractJetTypingIndentationTestBase.java b/idea/tests/org/jetbrains/jet/formatter/AbstractJetTypingIndentationTestBase.java new file mode 100644 index 00000000000..cc6d9f54911 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/formatter/AbstractJetTypingIndentationTestBase.java @@ -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 ""; + } +} diff --git a/idea/tests/org/jetbrains/jet/formatter/JetScriptTypingIndentationTest.java b/idea/tests/org/jetbrains/jet/formatter/JetScriptTypingIndentationTest.java deleted file mode 100644 index ec970794d0e..00000000000 --- a/idea/tests/org/jetbrains/jet/formatter/JetScriptTypingIndentationTest.java +++ /dev/null @@ -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"; - } - -} diff --git a/idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTest.java b/idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTest.java deleted file mode 100644 index ef9dc9cbadb..00000000000 --- a/idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTest.java +++ /dev/null @@ -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(); - } -} - diff --git a/idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTestBase.java b/idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTestBase.java deleted file mode 100644 index 53c3c57775b..00000000000 --- a/idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTestBase.java +++ /dev/null @@ -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; - } -} diff --git a/idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTestBaseGenerated.java b/idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTestBaseGenerated.java new file mode 100644 index 00000000000..cf86cda8a20 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTestBaseGenerated.java @@ -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; + } +}