Skip to content

Commit

Permalink
Reintroduces ignored formatter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kordyjan committed Oct 22, 2018
1 parent b1bfdb4 commit ae3cd60
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.eclipse.core.resources.IProject
import org.eclipse.core.resources.ProjectScope
import org.jetbrains.kotlin.core.formatting.KotlinCodeStyleManager
import org.jetbrains.kotlin.core.preferences.KotlinCodeStyleProperties
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings
import java.util.*
import kotlin.reflect.KFunction
Expand All @@ -21,16 +22,24 @@ object CodeStyleConfigurator {

KotlinCodeStyleManager.getOrCreate(generatedId) {
val kotlinSettings = getCustomSettings(KotlinCodeStyleSettings::class.java)
val commonSettings = getCommonSettings(KotlinLanguage.INSTANCE)

fun setDynamic(prop: String, value: Any) {
kotlinSettings.setDynamic(prop, value) or commonSettings.setDynamic(prop, value)
}

InTextDirectivesUtils.findListWithPrefixes(fileText, "SET_TRUE:")
.forEach { kotlinSettings[it] = true }
.forEach { setDynamic(it, true) }

InTextDirectivesUtils.findListWithPrefixes(fileText, "SET_FALSE:")
.forEach { kotlinSettings[it] = false }
.forEach { setDynamic(it, false) }

InTextDirectivesUtils.findListWithPrefixes(fileText, "SET_INT:")
.map { it.split("=", limit = 2) }
.forEach { (prop, value) -> kotlinSettings[prop] = value.toInt() }
.forEach { (prop, value) -> setDynamic(prop, value.trim().toInt()) }

InTextDirectivesUtils.findStringWithPrefixes(fileText, "RIGHT_MARGIN: ")
?.also { commonSettings.RIGHT_MARGIN = it.trim().toInt() }
}
}

Expand All @@ -42,13 +51,17 @@ object CodeStyleConfigurator {
}
}

private operator fun Any.set(name: String, value: Any) {
this::class.members.single { it.name in setOf(name) }.let {
when (it) {
is KMutableProperty -> it.setter.call(this, value)
is KFunction -> it.call(this, value)
else -> throw AssertionError("Field or method with name $name does not exist")
}
}
}
private fun Any.setDynamic(name: String, value: Any): Boolean =
this::class.members.singleOrNull { it.name in setOf(name) }
?.let {
when (it) {
is KMutableProperty -> it.setter
is KFunction -> it
else -> null
}
}
?.call(this, value)
?.let { true }
?: false

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jetbrains.kotlin.ui.tests.editors.formatter;

import org.junit.Ignore;
import org.junit.Test;

public class KotlinIdeaFormatActionTest extends KotlinFormatActionTestCase {
Expand Down Expand Up @@ -34,25 +33,21 @@ public void ArrayAccess() {
doAutoTest();
}

@Ignore
@Test
public void BinaryExpressionAlignmentSpread() {
doAutoTest();
}

@Ignore
@Test
public void BinaryExpressions() {
doAutoTest();
}

@Ignore
@Test
public void BinaryExpressionsBoolean() {
doAutoTest();
}

@Ignore
@Test
public void BinaryExpressionsWithoutAlignment() {
doAutoTest();
Expand All @@ -63,7 +58,6 @@ public void BlockFor() {
doAutoTest();
}

@Ignore
@Test
public void CatchFinallyOnNewLine() {
doAutoTest();
Expand Down Expand Up @@ -94,19 +88,6 @@ public void CommentInFunctionLiteral() {
doAutoTest();
}

@Ignore
@Test
public void ConsecutiveCalls() {
doAutoTest();
}

@Ignore
@Test
public void ConsecutiveSafeCallsIndent() {
doAutoTest();
}

@Ignore
@Test
public void DelegationList() {
doAutoTest();
Expand All @@ -127,13 +108,11 @@ public void DoWhileSpacing() {
doAutoTest();
}

@Ignore
@Test
public void ElseOnNewLine() {
doAutoTest();
}

@Ignore
@Test
public void Elvis() {
doAutoTest();
Expand Down Expand Up @@ -164,7 +143,6 @@ public void EmptyLineBetweenClasses() {
doAutoTest();
}

@Ignore
@Test
public void EmptyLineBetweenEnumEntries() {
doAutoTest();
Expand All @@ -190,13 +168,11 @@ public void ForLineBreak() {
doAutoTest();
}

@Ignore
@Test
public void FormatFirstColumnComments() {
doAutoTest();
}

@Ignore
@Test
public void FormatFirstColumnCommentsBeforeDeclaration() {
doAutoTest();
Expand All @@ -217,7 +193,6 @@ public void FunctionalType() {
doAutoTest();
}

@Ignore
@Test
public void FunctionCallParametersAlign() {
doAutoTest();
Expand All @@ -237,13 +212,7 @@ public void FunctionExpression() {
public void FunctionLineBreak() {
doAutoTest();
}

@Ignore
@Test
public void FunctionLiteralsInChainCalls() {
doAutoTest();
}


@Test
public void FunctionWithInference() {
doAutoTest();
Expand Down Expand Up @@ -364,7 +333,6 @@ public void ReturnExpression() {
doAutoTest();
}

@Ignore
@Test
public void RightBracketOnNewLine() {
doAutoTest();
Expand Down Expand Up @@ -415,13 +383,11 @@ public void SpacedInsideParans() {
doAutoTest();
}

@Ignore
@Test
public void SpacesAroundOperations() {
doAutoTest();
}

@Ignore
@Test
public void SpacesAroundUnaryOperations() {
doAutoTest();
Expand Down Expand Up @@ -482,7 +448,6 @@ public void WhileLineBreak() {
doAutoTest();
}

@Ignore
@Test
public void WhileOnNewLine() {
doAutoTest();
Expand Down

0 comments on commit ae3cd60

Please sign in to comment.