Test indentation on new line in scripts.
This commit is contained in:
committed by
Andrey Breslav
parent
64b4c2d49b
commit
796611702c
@@ -0,0 +1,4 @@
|
||||
package a.b.c
|
||||
|
||||
var x = 1
|
||||
x = x + 1<caret>
|
||||
@@ -0,0 +1,5 @@
|
||||
package a.b.c
|
||||
|
||||
var x = 1
|
||||
x = x + 1
|
||||
<caret>
|
||||
@@ -0,0 +1,5 @@
|
||||
package a.b.c
|
||||
|
||||
fun fn() {
|
||||
|
||||
}<caret>
|
||||
@@ -0,0 +1,6 @@
|
||||
package a.b.c
|
||||
|
||||
fun fn() {
|
||||
|
||||
}
|
||||
<caret>
|
||||
@@ -0,0 +1,3 @@
|
||||
package a.b.c
|
||||
|
||||
import x.y.z<caret>
|
||||
@@ -0,0 +1,4 @@
|
||||
package a.b.c
|
||||
|
||||
import x.y.z
|
||||
<caret>
|
||||
@@ -0,0 +1,6 @@
|
||||
package a.b.c
|
||||
|
||||
var x = 2
|
||||
fun fn() {
|
||||
x = x + 1<caret>
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package a.b.c
|
||||
|
||||
var x = 2
|
||||
fun fn() {
|
||||
x = x + 1
|
||||
<caret>
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
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";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,8 +26,7 @@ import org.jetbrains.jet.testing.SettingsConfigurator;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class JetTypingIndentationTest extends LightCodeInsightTestCase {
|
||||
|
||||
public class JetTypingIndentationTest extends JetTypingIndentationTestBase {
|
||||
public void testAfterCatch() {
|
||||
doFileNewlineTest();
|
||||
}
|
||||
@@ -87,52 +86,5 @@ public class JetTypingIndentationTest extends LightCodeInsightTestCase {
|
||||
public void testWhile() {
|
||||
doFileNewlineTest();
|
||||
}
|
||||
|
||||
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,62 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user