Usage highlighting test
This commit is contained in:
@@ -66,10 +66,7 @@ import org.jetbrains.kotlin.idea.decompiler.textBuilder.AbstractDecompiledTextTe
|
||||
import org.jetbrains.kotlin.idea.editor.quickDoc.AbstractJetQuickDocProviderTest
|
||||
import org.jetbrains.kotlin.idea.folding.AbstractKotlinFoldingTest
|
||||
import org.jetbrains.kotlin.idea.hierarchy.AbstractHierarchyTest
|
||||
import org.jetbrains.kotlin.idea.highlighter.AbstractDiagnosticMessageJsTest
|
||||
import org.jetbrains.kotlin.idea.highlighter.AbstractDiagnosticMessageTest
|
||||
import org.jetbrains.kotlin.idea.highlighter.AbstractHighlightExitPointsTest
|
||||
import org.jetbrains.kotlin.idea.highlighter.AbstractHighlightingTest
|
||||
import org.jetbrains.kotlin.idea.highlighter.*
|
||||
import org.jetbrains.kotlin.idea.imports.AbstractOptimizeImportsTest
|
||||
import org.jetbrains.kotlin.idea.intentions.AbstractIntentionTest
|
||||
import org.jetbrains.kotlin.idea.intentions.AbstractMultiFileIntentionTest
|
||||
@@ -395,6 +392,10 @@ fun main(args: Array<String>) {
|
||||
model("highlighter")
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractUsageHighlightingTest>()) {
|
||||
model("usageHighlighter")
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractKotlinFoldingTest>()) {
|
||||
model("folding/noCollapse")
|
||||
model("folding/checkCollapse", testMethod = "doSettingsFoldingTest")
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun test() {
|
||||
val <info descr="null">a</info> = 12
|
||||
foo(<info descr="null">~a</info>)
|
||||
}
|
||||
|
||||
fun foo(a: Int) = a
|
||||
|
||||
val a = 1
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.kotlin.idea.highlighter
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfoType
|
||||
import com.intellij.codeInsight.highlighting.actions.HighlightUsagesAction
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
import com.intellij.testFramework.ExpectedHighlightingData
|
||||
import org.jetbrains.kotlin.idea.test.JetLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.JetLightProjectDescriptor
|
||||
|
||||
public abstract class AbstractUsageHighlightingTest: JetLightCodeInsightFixtureTestCase() {
|
||||
companion object {
|
||||
// Not standard <caret> to leave it in text after configureByFile and remove manually after collecting highlighting information
|
||||
val CARET_TAG = "~"
|
||||
}
|
||||
|
||||
protected fun doTest(filePath: String) {
|
||||
myFixture.configureByFile(filePath)
|
||||
val document = myFixture.getEditor().getDocument()
|
||||
val data = ExpectedHighlightingData(document, false, false, true, false, myFixture.getFile())
|
||||
data.init()
|
||||
|
||||
val caret = document.getText().indexOf(CARET_TAG)
|
||||
assert(caret != -1, "Caret marker '$CARET_TAG' expected")
|
||||
|
||||
WriteCommandAction.runWriteCommandAction(myFixture.getProject()) {
|
||||
document.deleteString(caret, caret + CARET_TAG.length())
|
||||
}
|
||||
|
||||
getEditor().getCaretModel().moveToOffset(caret)
|
||||
|
||||
myFixture.testAction(HighlightUsagesAction())
|
||||
val highlighters = myFixture.getEditor().getMarkupModel().getAllHighlighters()
|
||||
|
||||
val infos = highlighters.map { highlighter ->
|
||||
var startOffset = highlighter.getStartOffset()
|
||||
var endOffset = highlighter.getEndOffset()
|
||||
|
||||
if (startOffset > caret) startOffset += CARET_TAG.length()
|
||||
if (endOffset > caret) endOffset += CARET_TAG.length()
|
||||
|
||||
HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(startOffset, endOffset).create()
|
||||
}
|
||||
|
||||
data.checkResult(infos, StringBuilder(document.getText()).insert(caret, CARET_TAG).toString())
|
||||
}
|
||||
|
||||
|
||||
|
||||
override fun getProjectDescriptor() = JetLightProjectDescriptor.INSTANCE
|
||||
override fun getTestDataPath() = ""
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.kotlin.idea.highlighter;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/testData/usageHighlighter")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class UsageHighlightingTestGenerated extends AbstractUsageHighlightingTest {
|
||||
public void testAllFilesPresentInUsageHighlighter() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/usageHighlighter"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("localVal.kt")
|
||||
public void testLocalVal() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/usageHighlighter/localVal.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user