[kotlin] Update test data to make highlighted elements more clear

#KTIJ-26412

GitOrigin-RevId: c9b2290ac5b0e56944f5dbe142c7f38b9f62fc1b
This commit is contained in:
Vladimir Dolzhenko
2023-08-01 14:59:22 +00:00
committed by intellij-monorepo-bot
parent 5c748aea41
commit 704a8ec254
46 changed files with 200 additions and 266 deletions
@@ -33,24 +33,29 @@ public class K2HighlightExitPointsTestGenerated extends AbstractK2HighlightExitP
runTest("../idea/tests/testData/exitPoints/anonymousFunction2.kt");
}
@TestMetadata("functionNameIdentifier.kt")
public void testFunctionNameIdentifier() throws Exception {
runTest("../idea/tests/testData/exitPoints/functionNameIdentifier.kt");
@TestMetadata("funKeyword.kt")
public void testFunKeyword() throws Exception {
runTest("../idea/tests/testData/exitPoints/funKeyword.kt");
}
@TestMetadata("functionNameIdentifier2.kt")
public void testFunctionNameIdentifier2() throws Exception {
runTest("../idea/tests/testData/exitPoints/functionNameIdentifier2.kt");
@TestMetadata("funKeyword2.kt")
public void testFunKeyword2() throws Exception {
runTest("../idea/tests/testData/exitPoints/funKeyword2.kt");
}
@TestMetadata("functionNameIdentifier3.kt")
public void testFunctionNameIdentifier3() throws Exception {
runTest("../idea/tests/testData/exitPoints/functionNameIdentifier3.kt");
@TestMetadata("funKeyword3.kt")
public void testFunKeyword3() throws Exception {
runTest("../idea/tests/testData/exitPoints/funKeyword3.kt");
}
@TestMetadata("functionNameIdentifier31.kt")
public void testFunctionNameIdentifier31() throws Exception {
runTest("../idea/tests/testData/exitPoints/functionNameIdentifier31.kt");
@TestMetadata("funKeyword31.kt")
public void testFunKeyword31() throws Exception {
runTest("../idea/tests/testData/exitPoints/funKeyword31.kt");
}
@TestMetadata("funName.kt")
public void testFunName() throws Exception {
runTest("../idea/tests/testData/exitPoints/funName.kt");
}
@TestMetadata("getter.kt")
@@ -2,24 +2,41 @@
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.HighlightUsagesHandler
import com.intellij.codeInsight.highlighting.highlightUsages
import com.intellij.openapi.application.ReadAction
import com.intellij.openapi.editor.colors.EditorColors
import com.intellij.openapi.editor.colors.EditorColorsManager
import com.intellij.openapi.project.DumbService
import com.intellij.psi.PsiElement
import com.intellij.refactoring.suggested.range
import com.intellij.testFramework.ExpectedHighlightingData
import com.intellij.util.concurrency.AppExecutorUtil
import org.jetbrains.kotlin.idea.test.InTextDirectivesUtils
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.test.extractMarkerOffset
import java.util.concurrent.Callable
abstract class AbstractHighlightExitPointsTest : KotlinLightCodeInsightFixtureTestCase() {
companion object {
// Not standard <caret> to leave it in text after configureByFile and remove manually after collecting highlighting information
const val CARET_TAG = "~"
}
open fun doTest(unused: String) {
myFixture.configureByFile(fileName())
val editor = myFixture.editor
val document = myFixture.editor.document
val data = ExpectedHighlightingData(document, false, false, true, false)
data.init()
val caret = document.extractMarkerOffset(project, CARET_TAG)
assert(caret != -1) { "Caret marker '${CARET_TAG}' expected" }
editor.caretModel.moveToOffset(caret)
val customHandler =
HighlightUsagesHandler.createCustomHandler<PsiElement>(editor, myFixture.file)
@@ -34,13 +51,23 @@ abstract class AbstractHighlightExitPointsTest : KotlinLightCodeInsightFixtureTe
})
}
val text = myFixture.file.text
val expectedToBeHighlighted = InTextDirectivesUtils.findLinesWithPrefixesRemoved(text, "//HIGHLIGHTED:")
val searchResultsTextAttributes =
EditorColorsManager.getInstance().globalScheme.getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES)
val highlighters = editor.markupModel.allHighlighters
.filter { it.textAttributes == searchResultsTextAttributes }
val actual = highlighters.map { text.substring(it.startOffset, it.endOffset) }
assertEquals(expectedToBeHighlighted, actual)
val ranges = editor.markupModel.allHighlighters
.filter { it.textAttributesKey == EditorColors.SEARCH_RESULT_ATTRIBUTES }
.mapNotNull { it.range }
val infos = ranges.toHashSet()
.map {
var startOffset = it.startOffset
var endOffset = it.endOffset
if (startOffset > caret) startOffset += CARET_TAG.length
if (endOffset > caret) endOffset += CARET_TAG.length
HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION)
.range(startOffset, endOffset)
.create()
}
data.checkResult(myFixture.file, infos, StringBuilder(document.text).insert(caret, CARET_TAG).toString())
}
}
@@ -33,24 +33,29 @@ public class HighlightExitPointsTestGenerated extends AbstractHighlightExitPoint
runTest("testData/exitPoints/anonymousFunction2.kt");
}
@TestMetadata("functionNameIdentifier.kt")
public void testFunctionNameIdentifier() throws Exception {
runTest("testData/exitPoints/functionNameIdentifier.kt");
@TestMetadata("funKeyword.kt")
public void testFunKeyword() throws Exception {
runTest("testData/exitPoints/funKeyword.kt");
}
@TestMetadata("functionNameIdentifier2.kt")
public void testFunctionNameIdentifier2() throws Exception {
runTest("testData/exitPoints/functionNameIdentifier2.kt");
@TestMetadata("funKeyword2.kt")
public void testFunKeyword2() throws Exception {
runTest("testData/exitPoints/funKeyword2.kt");
}
@TestMetadata("functionNameIdentifier3.kt")
public void testFunctionNameIdentifier3() throws Exception {
runTest("testData/exitPoints/functionNameIdentifier3.kt");
@TestMetadata("funKeyword3.kt")
public void testFunKeyword3() throws Exception {
runTest("testData/exitPoints/funKeyword3.kt");
}
@TestMetadata("functionNameIdentifier31.kt")
public void testFunctionNameIdentifier31() throws Exception {
runTest("testData/exitPoints/functionNameIdentifier31.kt");
@TestMetadata("funKeyword31.kt")
public void testFunKeyword31() throws Exception {
runTest("testData/exitPoints/funKeyword31.kt");
}
@TestMetadata("funName.kt")
public void testFunName() throws Exception {
runTest("testData/exitPoints/funName.kt");
}
@TestMetadata("getter.kt")
@@ -1,10 +1,7 @@
fun foo() {
listOf(1, 2, 3, 4, 5).forEach(fun(value: Int) {
if (value == 3) <caret>return
listOf(1, 2, 3, 4, 5).forEach(<info descr="null">fun</info>(value: Int) {
if (value == 3) <info descr="null">~return</info>
print(value)
})
print(" done with anonymous function")
}
//HIGHLIGHTED: fun
//HIGHLIGHTED: return
}
@@ -1,10 +1,7 @@
fun foo() {
listOf(1, 2, 3, 4, 5).forEach(fun(value: Int) {
if (value == 3) return@<caret>forEach
listOf(1, 2, 3, 4, 5).forEach(<info descr="null">fun</info>(value: Int) {
if (value == 3) <info descr="null">return@~forEach</info>
print(value)
})
print(" done with anonymous function")
}
//HIGHLIGHTED: fun
//HIGHLIGHTED: return@forEach
}
@@ -0,0 +1,6 @@
<info descr="null">~fun</info> test(s: String?): Int {
if (s != null) {
<info descr="null">return@test 1</info>
}
<info descr="null">return 0</info>
}
@@ -0,0 +1,4 @@
<info descr="null">fun</info>~ test(s: String?): Int =
if (s != null) {
<info descr="null">1</info>
} else <info descr="null">0</info>
@@ -1,6 +1,6 @@
fun test(s: String?): Int =
if (s != null) {
1<caret>
1~
} else 0
// no exit point highlighting as to KTIJ-26395: we should not highlight exit points on the latest statement as it interferes with variable/call/type highlighting
@@ -1,5 +1,5 @@
fun test(s: String?): Int =
if (s != null) {
val q = 0<caret>
val q = 0~
1
} else 0
@@ -0,0 +1,6 @@
fun <info descr="null">~test</info>(s: String?): Int {
if (s != null) {
return@<info descr="null">test</info> 1
}
return 0
}
@@ -1,10 +0,0 @@
fun test<caret>(s: String?): Int {
if (s != null) {
return@test 1
}
return 0
}
//HIGHLIGHTED: return@test 1
//HIGHLIGHTED: test
//HIGHLIGHTED: return 0
@@ -1,8 +0,0 @@
fun test<caret>(s: String?): Int =
if (s != null) {
1
} else 0
//HIGHLIGHTED: 1
//HIGHLIGHTED: test
//HIGHLIGHTED: 0
@@ -1,13 +1,9 @@
val Any?.foo: Int
get() {
<info descr="null">get</info>() {
this?.let {
<caret>return 1
<info descr="null">~return 1</info>
}
return 2
<info descr="null">return 2</info>
}
public inline fun <T> T.let(block: (T) -> Unit) {}
//HIGHLIGHTED: return 1
//HIGHLIGHTED: get
//HIGHLIGHTED: return 2
public inline fun <T> T.let(block: (T) -> Unit) {}
@@ -1,9 +1,6 @@
val Any?.foo: Int
get() {
return<caret> 42
<info descr="null">get</info>() {
<info descr="null">return~ 42</info>
}
public inline fun <T> T.let(block: (T) -> Unit) {}
//HIGHLIGHTED: get
//HIGHLIGHTED: return 42
public inline fun <T> T.let(block: (T) -> Unit) {}
@@ -1,9 +1,6 @@
val Any?.foo: Int
get<caret>() {
return 42
<info descr="null">get</info>~() {
<info descr="null">return 42</info>
}
public inline fun <T> T.let(block: (T) -> Unit) {}
//HIGHLIGHTED: get
//HIGHLIGHTED: return 42
public inline fun <T> T.let(block: (T) -> Unit) {}
@@ -1,13 +1,9 @@
fun foo(f: (String?) -> Int) {}
fun test() {
foo {
if (it == null) return@<caret>foo 1
<info descr="null">foo</info> {
if (it == null) <info descr="null">return@~foo 1</info>
(1+1)
if (it == "a") 2 else 0
if (it == "a") <info descr="null">2</info> else <info descr="null">0</info>
}
}
//HIGHLIGHTED: return@foo 1
//HIGHLIGHTED: foo
//HIGHLIGHTED: 2
//HIGHLIGHTED: 0
}
@@ -1,11 +1,8 @@
fun foo(f: (String?) -> Int) {}
fun test() {
foo {
if (it == null) return@<caret>foo 1
0
<info descr="null">foo</info> {
if (it == null) <info descr="null">return@~foo 1</info>
<info descr="null">0</info>
}
}
//HIGHLIGHTED: return@foo 1
//HIGHLIGHTED: foo
//HIGHLIGHTED: 0
}
@@ -3,7 +3,7 @@ fun foo(f: (String?) -> Int) {}
fun test() {
foo {
if (it != null) return@foo 1
<caret>(1+1)
~(1+1)
0
}
}
@@ -3,7 +3,7 @@ fun foo(f: (String?) -> Int) {}
fun test() {
foo {
if (it != null) return@foo 1
0<caret>
0~
}
}
// no exit point highlighting as to KTIJ-26395: we should not highlight exit points on the latest statement as it interferes with variable/call/type highlighting
@@ -3,7 +3,7 @@ fun foo(f: (String?) -> Int) {}
fun test() {
foo {
if (it == null) return@foo 1
if (it == "a") 2<caret> else 0
if (it == "a") 2~ else 0
}
}
// no exit point highlighting as to KTIJ-26395: we should not highlight exit points on the latest statement as it interferes with variable/call/type highlighting
@@ -3,6 +3,6 @@ fun foo(f: (String?) -> Int) {}
fun test() {
foo {
if (it == null) return@foo 1
if (it == "a") 2 e<caret>lse 0
if (it == "a") 2 e~lse 0
}
}
@@ -4,7 +4,7 @@ fun test() {
foo {
if (it != null) return@foo 1
if (it == "a") {
val q = 1<caret>
val q = 1~
2
} else {
0
@@ -1,16 +1,14 @@
fun foo(f: (String?) -> Int) {}
fun y(): Int = 11
fun <info descr="null">y</info>(): Int = 11
fun test() {
foo {
if (it != null) return@foo 1
if (it == "a") {
if (it == "aa") y<caret>() else 2
if (it == "aa") <info descr="null">y</info>~() else 2
} else {
0
}
}
}
// no exit point highlighting as to KTIJ-26395: we should not highlight exit points on the latest statement as it interferes with variable/call/type highlighting
//HIGHLIGHTED: y
//HIGHLIGHTED: y
// no exit point highlighting as to KTIJ-26395: we should not highlight exit points on the latest statement as it interferes with variable/call/type highlighting
@@ -1,16 +1,12 @@
fun f(a: Int): Int {
<info descr="null">fun</info> f(a: Int): Int {
if (a < 5) {
run {
<caret>return 1
<info descr="null">~return 1</info>
}
}
else {
return 2
<info descr="null">return 2</info>
}
}
inline public fun <T> run(f: () -> T): T { }
//HIGHLIGHTED: return 1
//HIGHLIGHTED: f
//HIGHLIGHTED: return 2
inline public fun <T> run(f: () -> T): T { }
@@ -1,16 +1,12 @@
fun f(a: Int): Int {
<info descr="null">fun</info> f(a: Int): Int {
if (a < 5) {
run {
return 1
<info descr="null">return 1</info>
}
}
else {
<caret>return 2
<info descr="null">~return 2</info>
}
}
inline public fun <T> run(f: () -> T): T { }
//HIGHLIGHTED: return 1
//HIGHLIGHTED: f
//HIGHLIGHTED: return 2
inline public fun <T> run(f: () -> T): T { }
@@ -1,12 +1,8 @@
fun Any?.foo(): Int {
<info descr="null">fun</info> Any?.foo(): Int {
this?.let {
<caret>return 1
<info descr="null">~return 1</info>
}
return 2
<info descr="null">return 2</info>
}
public inline fun <T> T.let(block: (T) -> Unit) {}
//HIGHLIGHTED: return 1
//HIGHLIGHTED: foo
//HIGHLIGHTED: return 2
public inline fun <T> T.let(block: (T) -> Unit) {}
@@ -1,7 +1,7 @@
fun f(a: Int): Int {
if (a < 5) {
run {
<caret>return@run 1
<info descr="null">run</info> {
<info descr="null">~return@run 1</info>
}
}
else {
@@ -9,7 +9,4 @@ fun f(a: Int): Int {
}
}
inline public fun <T> run(f: () -> T): T { }
//HIGHLIGHTED: run
//HIGHLIGHTED: return@run 1
inline public fun <T> run(f: () -> T): T { }
@@ -1,15 +1,12 @@
fun f(a: Int): Int {
<info descr="null">fun</info> f(a: Int): Int {
if (a < 5) {
run {
return@run 1
}
}
else {
<caret>return 2
<info descr="null">~return 2</info>
}
}
inline public fun <T> run(f: () -> T): T { }
//HIGHLIGHTED: f
//HIGHLIGHTED: return 2
inline public fun <T> run(f: () -> T): T { }
@@ -1,12 +1,8 @@
fun foo(x: Int): Int {
if (x == 1) return 1
listOf(1, 2, 3).map {
if (it == 2) return@map 2
return@<caret>map 3
listOf(1, 2, 3).<info descr="null">map</info> {
if (it == 2) <info descr="null">return@map 2</info>
<info descr="null">return@~map 3</info>
}
return 4
}
//HIGHLIGHTED: return@map 2
//HIGHLIGHTED: map
//HIGHLIGHTED: return@map 3
}
@@ -1,13 +1,10 @@
fun f(a: Int): Int {
if (a < 5) {
run1(fun (): Int {
<caret>return 1
run1(<info descr="null">fun</info> (): Int {
<info descr="null">~return 1</info>
})
}
return 2
}
inline public fun <T> run1(noinline f: () -> T): T { }
//HIGHLIGHTED: fun
//HIGHLIGHTED: return 1
inline public fun <T> run1(noinline f: () -> T): T { }
@@ -1,4 +1,4 @@
// KT-8042 ISE at KotlinHighlightExitPointsHandlerFactory.createHighlightUsagesHandler() on typing a function name starting with `throw`
// EA-68157
fun return<caret>
fun return~
@@ -1,4 +1,4 @@
// KT-8042 ISE at KotlinHighlightExitPointsHandlerFactory.createHighlightUsagesHandler() on typing a function name starting with `throw`
// EA-68157
fun throw<caret>
fun throw~
@@ -1,6 +1,6 @@
fun f(a: Int): Int {
fun localFun() {
<caret>return
<info descr="null">fun</info> localFun() {
<info descr="null">~return</info>
}
if (a < 5) {
@@ -9,7 +9,4 @@ fun f(a: Int): Int {
else {
return 2
}
}
//HIGHLIGHTED: localFun
//HIGHLIGHTED: return
}
@@ -1,16 +1,12 @@
fun f(a: Int): Int {
<info descr="null">fun</info> f(a: Int): Int {
fun localFun() {
return
}
if (a < 5) {
return 1
<info descr="null">return 1</info>
}
else {
<caret>return 2
<info descr="null">~return 2</info>
}
}
//HIGHLIGHTED: return 1
//HIGHLIGHTED: f
//HIGHLIGHTED: return 2
}
@@ -1,9 +1,9 @@
fun f(a: Int): Int {
fun localFun() {
<info descr="null">fun</info> localFun() {
if (a > 5) {
return
<info descr="null">return</info>
}
<caret>throw Error()
<info descr="null">~throw Error()</info>
}
if (a < 5) {
@@ -12,8 +12,4 @@ fun f(a: Int): Int {
else {
throw Exception()
}
}
//HIGHLIGHTED: return
//HIGHLIGHTED: localFun
//HIGHLIGHTED: throw Error()
}
@@ -2,15 +2,12 @@ import javax.swing.SwingUtilities
fun f(a: Int): Int {
if (a < 5) {
SwingUtilities.invokeLater(fun (): Unit {
<caret>return
SwingUtilities.invokeLater(<info descr="null">fun</info> (): Unit {
<info descr="null">~return</info>
})
return 1
}
else {
return 2
}
}
//HIGHLIGHTED: fun
//HIGHLIGHTED: return
}
@@ -1,17 +1,13 @@
import javax.swing.SwingUtilities
fun f(a: Int): Int {
<info descr="null">fun</info> f(a: Int): Int {
if (a < 5) {
SwingUtilities.invokeLater(fun (): Unit {
return
})
<caret>return 1
<info descr="null">~return 1</info>
}
else {
return 2
<info descr="null">return 2</info>
}
}
//HIGHLIGHTED: return 1
//HIGHLIGHTED: f
//HIGHLIGHTED: return 2
}
@@ -1,12 +1,8 @@
fun foo(x: Int): Int {
if (x == 1) return 1
<info descr="null">fun</info> foo(x: Int): Int {
if (x == 1) <info descr="null">return 1</info>
listOf(1, 2, 3).map {
if (it == 2) return@map 2
return@map 3
}
<caret>return 4
}
//HIGHLIGHTED: return 1
//HIGHLIGHTED: foo
//HIGHLIGHTED: return 4
<info descr="null">~return 4</info>
}
@@ -4,6 +4,6 @@ fun List<*>.func(function: List<*>.()-> Unit) {
fun test() {
return listOf(1, 2, 3).func {
this@func<caret>
this@func~
}
}
@@ -1,14 +1,9 @@
fun f(a: Int): Int {
return<caret> if (a < 5) {
<info descr="null">fun</info> f(a: Int): Int {
<info descr="null">return</info>~ if (a < 5) {
val q = 1
1
<info descr="null">1</info>
}
else {
2
<info descr="null">2</info>
}
}
//HIGHLIGHTED: return
//HIGHLIGHTED: f
//HIGHLIGHTED: 1
//HIGHLIGHTED: 2
}
@@ -1,20 +1,14 @@
fun yy(): Int = 5
fun f(a: Int): Int {
return<caret> try {
<info descr="null">fun</info> f(a: Int): Int {
<info descr="null">return</info>~ try {
val q = a * a
q
<info descr="null">q</info>
} catch (e: Exception) {
0
<info descr="null">0</info>
} catch (e: Throwable) {
-1
<info descr="null">-1</info>
} finally {
println()
}
}
//HIGHLIGHTED: return
//HIGHLIGHTED: f
//HIGHLIGHTED: 0
//HIGHLIGHTED: q
//HIGHLIGHTED: -1
@@ -1,20 +1,14 @@
fun yy(): Int = 5
fun f(a: Int): Int {
return<caret> when {
<info descr="null">fun</info> f(a: Int): Int {
<info descr="null">return</info>~ when {
a < 0 -> {
val q = 1
2 * 2
<info descr="null">2 * 2</info>
}
a > 0 -> {
2 * (2 + 2)
<info descr="null">2 * (2 + 2)</info>
}
else -> yy()
else -> <info descr="null">yy()</info>
}
}
//HIGHLIGHTED: return
//HIGHLIGHTED: f
//HIGHLIGHTED: 2 * (2 + 2)
//HIGHLIGHTED: 2 * 2
//HIGHLIGHTED: yy()
}
@@ -1,12 +1,8 @@
fun f(a: Int): Int {
<info descr="null">fun</info> f(a: Int): Int {
if (a < 5) {
<caret>return 1
<info descr="null">~return 1</info>
}
else {
return 2
<info descr="null">return 2</info>
}
}
//HIGHLIGHTED: return 1
//HIGHLIGHTED: f
//HIGHLIGHTED: return 2
}
@@ -1,12 +1,8 @@
fun f(a: Int): Int {
<info descr="null">fun</info> f(a: Int): Int {
if (a < 5) {
return 1
<info descr="null">return 1</info>
}
else {
<caret>throw Error()
<info descr="null">~throw Error()</info>
}
}
//HIGHLIGHTED: return 1
//HIGHLIGHTED: f
//HIGHLIGHTED: throw Error()
}
@@ -1,12 +1,8 @@
fun f(a: Int): Int {
<info descr="null">fun</info> f(a: Int): Int {
if (a < 5) {
<caret>return 1
<info descr="null">~return 1</info>
}
else {
throw Error()
<info descr="null">throw Error()</info>
}
}
//HIGHLIGHTED: return 1
//HIGHLIGHTED: f
//HIGHLIGHTED: throw Error()
}
@@ -1,4 +1,4 @@
fun <info descr="null">test</info>~(s: String?): Int {
<info descr="null">fun</info>~ test(s: String?): Int {
if (s != null) {
<info descr="null">return@<info descr="null">test</info> 1</info>
}