Generate weigher tests from Kotlin base
This commit is contained in:
@@ -2,4 +2,9 @@
|
|||||||
<item name='com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase com.intellij.psi.PsiManager getPsiManager()'>
|
<item name='com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase com.intellij.psi.PsiManager getPsiManager()'>
|
||||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
</item>
|
</item>
|
||||||
|
<item name='com.intellij.testFramework.fixtures.CodeInsightTestFixture void assertPreferredCompletionItems(int, java.lang.String...)'>
|
||||||
|
<annotation name='jet.runtime.typeinfo.KotlinSignature'>
|
||||||
|
<val name="value" val=""fun assertPreferredCompletionItems(selected: Int, vararg expected: String)""/>
|
||||||
|
</annotation>
|
||||||
|
</item>
|
||||||
</root>
|
</root>
|
||||||
@@ -45,12 +45,12 @@ public final class InTextDirectivesUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static String[] findArrayWithPrefixes(String fileText, String... prefixes) {
|
public static String[] findArrayWithPrefixes(@NotNull String fileText, @NotNull String... prefixes) {
|
||||||
return ArrayUtil.toStringArray(findListWithPrefixes(fileText, prefixes));
|
return ArrayUtil.toStringArray(findListWithPrefixes(fileText, prefixes));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static List<String> findListWithPrefixes(String fileText, String... prefixes) {
|
public static List<String> findListWithPrefixes(@NotNull String fileText, @NotNull String... prefixes) {
|
||||||
List<String> result = new ArrayList<String>();
|
List<String> result = new ArrayList<String>();
|
||||||
|
|
||||||
for (String line : findLinesWithPrefixesRemoved(fileText, prefixes)) {
|
for (String line : findLinesWithPrefixesRemoved(fileText, prefixes)) {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import org.jetbrains.jet.completion.AbstractJavaCompletionTest;
|
|||||||
import org.jetbrains.jet.completion.AbstractJavaWithLibCompletionTest;
|
import org.jetbrains.jet.completion.AbstractJavaWithLibCompletionTest;
|
||||||
import org.jetbrains.jet.completion.AbstractJetJSCompletionTest;
|
import org.jetbrains.jet.completion.AbstractJetJSCompletionTest;
|
||||||
import org.jetbrains.jet.completion.AbstractKeywordCompletionTest;
|
import org.jetbrains.jet.completion.AbstractKeywordCompletionTest;
|
||||||
|
import org.jetbrains.jet.completion.weighers.AbstractCompletionWeigherTest;
|
||||||
import org.jetbrains.jet.descriptors.serialization.AbstractDescriptorSerializationTest;
|
import org.jetbrains.jet.descriptors.serialization.AbstractDescriptorSerializationTest;
|
||||||
import org.jetbrains.jet.editor.quickDoc.AbstractJetQuickDocProviderTest;
|
import org.jetbrains.jet.editor.quickDoc.AbstractJetQuickDocProviderTest;
|
||||||
import org.jetbrains.jet.findUsages.AbstractJetFindUsagesTest;
|
import org.jetbrains.jet.findUsages.AbstractJetFindUsagesTest;
|
||||||
@@ -460,6 +461,13 @@ public class GenerateTests {
|
|||||||
testModelWithPattern("idea/testData/findUsages", "^(.+).0.kt$", "doTest")
|
testModelWithPattern("idea/testData/findUsages", "^(.+).0.kt$", "doTest")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
generateTest(
|
||||||
|
"idea/tests",
|
||||||
|
"CompletionWeigherTestGenerated",
|
||||||
|
AbstractCompletionWeigherTest.class,
|
||||||
|
testModel("idea/testData/completion/weighers", true, "doTest")
|
||||||
|
);
|
||||||
|
|
||||||
generateTest(
|
generateTest(
|
||||||
"idea/tests/",
|
"idea/tests/",
|
||||||
"ConfigureProjectByChangingFileTestGenerated",
|
"ConfigureProjectByChangingFileTestGenerated",
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
fun foo1() {}
|
fun foo1() {}
|
||||||
deprecated("Use foo3 instead") fun foo2() {}
|
deprecated("Use foo3 instead") fun foo2() {}
|
||||||
fun foo3 {}
|
fun foo3() {}
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
<caret>
|
foo<caret>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ORDER: foo1, foo3, foo2
|
||||||
@@ -2,5 +2,7 @@ val initGlobal = 12
|
|||||||
|
|
||||||
fun test(initParam : Int) {
|
fun test(initParam : Int) {
|
||||||
val initLocal = "Test"
|
val initLocal = "Test"
|
||||||
<caret>
|
init<caret>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ORDER: initLocal, initParam, initGlobal
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
fun test() {
|
fun test() {
|
||||||
val a = 12
|
val a = 12
|
||||||
<caret>
|
a<caret>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ORDER: a, as
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
fun test(fals: Int) {
|
fun test(fals: Int) {
|
||||||
val falt = 111
|
val falt = 111
|
||||||
f<caret>
|
fa<caret>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ORDER: fals, falt, false
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
fun bar(fo: Int) {
|
fun bar(fop: Int) {
|
||||||
<caret>
|
fo<caret>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ORDER: fop, for (... in ...) {...}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
fun main(variables: Array<String>) {
|
fun main(variables: Array<String>) {
|
||||||
val values = ""
|
val values = ""
|
||||||
<caret>
|
va<caret>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ORDER: values, variables, val ... = ..., var ... = ..., vararg
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* 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.completion.weighers
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.completion.CompletionType
|
||||||
|
import org.jetbrains.jet.InTextDirectivesUtils
|
||||||
|
import java.io.File
|
||||||
|
import org.jetbrains.jet.plugin.PluginTestCaseBase
|
||||||
|
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||||
|
import org.testng.Assert
|
||||||
|
|
||||||
|
public abstract class AbstractCompletionWeigherTest() : LightCodeInsightFixtureTestCase() {
|
||||||
|
fun doTest(path: String) {
|
||||||
|
val fixture = myFixture!!
|
||||||
|
|
||||||
|
fixture.configureByFile(path)
|
||||||
|
val text = fixture.getEditor()!!.getDocument().getText()
|
||||||
|
|
||||||
|
val items = InTextDirectivesUtils.findArrayWithPrefixes(text, "// ORDER:")
|
||||||
|
Assert.assertTrue(!items.isEmpty(), """Some items should be defined with "// ORDER:" directive""")
|
||||||
|
|
||||||
|
fixture.complete(CompletionType.BASIC, 1)
|
||||||
|
fixture.assertPreferredCompletionItems(0, *items)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override fun getTestDataPath() : String? {
|
||||||
|
return File(PluginTestCaseBase.getTestDataPathBase(), "/completion/weighers").getPath() + File.separator
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,62 +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.completion.weighers;
|
|
||||||
|
|
||||||
import com.intellij.codeInsight.completion.CompletionAutoPopupTestCase;
|
|
||||||
import com.intellij.openapi.application.Result;
|
|
||||||
import com.intellij.openapi.command.WriteCommandAction;
|
|
||||||
import org.jetbrains.annotations.NonNls;
|
|
||||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
|
||||||
|
|
||||||
public class CompletionWeigherTest extends CompletionAutoPopupTestCase {
|
|
||||||
public void testLocalValuesAndParams() {
|
|
||||||
doTest("init", "initLocal", "initParam", "initGlobal");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testTemplatesAndKeywordsLast() {
|
|
||||||
doTest("va", "values", "variables", "val ... = ...", "var ... = ...", "vararg");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDeprecatedFun() {
|
|
||||||
doTest("foo", "foo1", "foo3", "foo2");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testLocalsBeforeKeywords() {
|
|
||||||
doTest("a", "a", "as");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testParametersBeforeKeywords() {
|
|
||||||
doTest("fo", "fo", "for (... in ...) {...}");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testLocalsPropertiesKeywords() {
|
|
||||||
doTest("a", "fals", "falt", "false");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void doTest(String type, @NonNls String... expected) {
|
|
||||||
new WriteCommandAction(myFixture.getProject(), myFixture.getFile()) {
|
|
||||||
@Override
|
|
||||||
protected void run(Result result) throws Throwable {
|
|
||||||
myFixture.setTestDataPath(PluginTestCaseBase.getTestDataPathBase() + "/completion/weighers/");
|
|
||||||
myFixture.configureByFile(getTestName(false) + ".kt");
|
|
||||||
}
|
|
||||||
}.execute();
|
|
||||||
|
|
||||||
type(type);
|
|
||||||
myFixture.assertPreferredCompletionItems(0, expected);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* 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.completion.weighers;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
|
import org.jetbrains.jet.test.TestMetadata;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
@TestMetadata("idea/testData/completion/weighers")
|
||||||
|
public class CompletionWeigherTestGenerated extends AbstractCompletionWeigherTest {
|
||||||
|
public void testAllFilesPresentInWeighers() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/completion/weighers"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("DeprecatedFun.kt")
|
||||||
|
public void testDeprecatedFun() throws Exception {
|
||||||
|
doTest("idea/testData/completion/weighers/DeprecatedFun.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("LocalValuesAndParams.kt")
|
||||||
|
public void testLocalValuesAndParams() throws Exception {
|
||||||
|
doTest("idea/testData/completion/weighers/LocalValuesAndParams.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("LocalsBeforeKeywords.kt")
|
||||||
|
public void testLocalsBeforeKeywords() throws Exception {
|
||||||
|
doTest("idea/testData/completion/weighers/LocalsBeforeKeywords.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("LocalsPropertiesKeywords.kt")
|
||||||
|
public void testLocalsPropertiesKeywords() throws Exception {
|
||||||
|
doTest("idea/testData/completion/weighers/LocalsPropertiesKeywords.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ParametersBeforeKeywords.kt")
|
||||||
|
public void testParametersBeforeKeywords() throws Exception {
|
||||||
|
doTest("idea/testData/completion/weighers/ParametersBeforeKeywords.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("TemplatesAndKeywordsLast.kt")
|
||||||
|
public void testTemplatesAndKeywordsLast() throws Exception {
|
||||||
|
doTest("idea/testData/completion/weighers/TemplatesAndKeywordsLast.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user