Add test methods and data for uncommon cases

Uncommon means mostly that aren't present in raw fir builder data
This commit is contained in:
Ivan Cilcic
2019-08-15 13:45:22 +03:00
committed by Mikhail Glukhikh
parent 8047aa22a4
commit aebe8c36f5
15 changed files with 474 additions and 0 deletions
@@ -486,4 +486,10 @@ fun main(args: Array<String>) {
model("rawBuilder", testMethod = "doFirBuilderDataTest")
}
}
testGroup("compiler/visualizer/tests", "compiler/visualizer/testData") {
testClass<AbstractPsiVisualizer>("PsiVisualizerForUncommonCasesGenerated") {
model("uncommonCases/testFiles", testMethod = "doUncommonCasesTest")
}
}
}
@@ -0,0 +1,89 @@
package p
class A {
// Int Int
// │ │
val aProp = 10
}
class B {
// Int Int
// │ │
val bProp = 1
}
fun foo(a: Int, b: Int): Int {
// fun <T, R> with(A, A.() -> Int): Int
// │ constructor A()
// │ │ with@0
// │ │ │
with(A()) {
// this@0
// val (A).aProp: Int
// │
aProp
// fun <T, R> with(B, B.() -> Int): Int
// │ constructor B()
// │ │ with@1
// │ │ │
with(B()) {
// this@0
// val (A).aProp: Int
// │
aProp
// this@1
// val (B).bProp: Int
// │
bProp
// this@0
// val (A).aProp: Int
// │
aProp
}
}
// fun <T, R> with(A, A.() -> Int): Int
// │ constructor A()
// │ │ with@0
// │ │ │
with(A()) {
// this@0
// val (A).aProp: Int
// │
aProp
// fun <T, R> with(B, B.() -> Int): Int
// │ constructor B()
// │ │ with@1
// │ │ │
with(B()) {
// this@0
// val (A).aProp: Int
// │
aProp
// this@1
// val (B).bProp: Int
// │
bProp
}
// fun <T, R> with(B, B.() -> Int): Int
// │ constructor B()
// │ │ with@1
// │ │ │
with(B()) {
// this@0
// val (A).aProp: Int
// │
aProp
// this@1
// val (B).bProp: Int
// │
bProp
}
}
// foo.a: Int
// │
return a
}
@@ -0,0 +1,33 @@
package org.jetbrains.kotlin.test
// collections/List<Int>
// │ fun <T> collections/listOf(vararg Int): collections/List<Int>
// │ │ Int
// │ │ │ Int
// │ │ │ │ Int
// │ │ │ │ │
val listOfInt = listOf(1, 2, 3)
// java/util/ArrayList<Int>
// │ package java
// │ │ constructor util/ArrayList<E : Any!>()
// │ │ │
val javaList = java.util.ArrayList<Int>()
// package java
// │ package java/util
// │ │
fun move(): java.util.ArrayList<Int> {
// val listOfInt: collections/List<Int>
// │
for (elem in listOfInt) {
// val javaList: java/util/ArrayList<Int>
// │ fun (java/util/ArrayList<Int>).add(Int): Boolean
// │ │ val move.elem: Int
// │ │ │
javaList.add(elem)
}
// val javaList: java/util/ArrayList<Int>
// │
return javaList
}
@@ -0,0 +1,81 @@
package org.jetbrains.kotlin.test
// Int Int
// │ │
val p1 = 10
// Double Double
// │ │
val p2: Double = 1.0
// Float Float
// │ │
val p3: Float = 2.5f
// String
// │
val p4 = "some string"
// Double
// │ val p1: Int
// │ │ fun (Int).plus(Double): Double
// │ │ │ val p2: Double
// │ │ │ │
val p5 = p1 + p2
// Double
// │ val p1: Int
// │ │ fun (Int).times(Double): Double
// │ │ │ val p2: Double
// │ │ │ │ fun (Double).plus(Double): Double
// │ │ │ │ │ val p5: Double
// │ │ │ │ │ │ fun (Double).minus(Float): Double
// │ │ │ │ │ │ │ val p3: Float
// │ │ │ │ │ │ │ │
val p6 = p1 * p2 + (p5 - p3)
// Float
// │
val withGetter
// val p1: Int
// │ fun (Int).times(Float): Float
// │ │ val p3: Float
// │ │ │
get() = p1 * p3
// String
// │
var withSetter
// val p4: String
// │
get() = p4
// <set-withSetter>.value: String
// │
set(value) = value
// Boolean
// │
val withGetter2: Boolean
get() {
// Boolean
// │
return true
}
// String
// │
var withSetter2: String
get() = "1"
set(value) {
// var <set-withSetter2>.field: String
// │ <set-withSetter2>.value: String
// │ │ fun (String).plus(Any?): String
// │ │ │
field = value + "!"
}
// String
// │
private val privateGetter: String = "cba"
get
// String
// │
var privateSetter: String = "abc"
private set
@@ -0,0 +1,24 @@
package org.jetbrains.kotlin.test
abstract class Base<T>(var x: T) {
fun replace(newValue: T)
}
// constructor Base<T>(Int)
// │
class Derived(var x: Int): Base<Int>() {
override fun replace(newValue: Int) {
// var (Derived).x: Int
// │ Derived.replace.newValue: Int
// │ │
x = newValue
}
}
fun test() {
// constructor Derived(Int)
// │ fun (Derived).replace(Int): Unit
// │ Int │ Int
// │ │ │ │
Derived(10).replace(20)
}
@@ -0,0 +1,24 @@
interface Source<out T> {
fun nextT(): T
}
fun demo(strs: Source<String>) {
// Source<Any> demo.strs: Source<String>
// │ │
val objects: Source<Any> = strs
}
interface Comparable<in T> {
operator fun compareTo(other: T): Int
}
fun demo(x: Comparable<Number>) {
// demo.x: Comparable<Number>
// │ fun (Comparable<Number>).compareTo(Number): Int
// │ │ Double
// │ │ │
x.compareTo(1.0)
// Comparable<Double> demo.x: Comparable<Number>
// │ │
val y: Comparable<Double> = x
}
@@ -0,0 +1,28 @@
// collections/List<T> collections/List<String>
// │ │
fun <T> copyWhenGreater(list: List<T>, threshold: T): List<String>
where T : CharSequence,
T : Comparable<T> {
// copyWhenGreater.list: collections/List<T>
// │ fun <T> collections/Iterable<T>.filter((T) -> Boolean): collections/List<T>
// │ │ copyWhenGreater.<anonymous>.it: T
// │ │ │ fun (Comparable<T>).compareTo(T): Int
// │ │ │ │ copyWhenGreater.threshold: T
// │ │ │ │ │ fun <T, R> collections/Iterable<T>.map((T) -> String): collections/List<String>
// │ │ │ │ │ │ copyWhenGreater.<anonymous>.it: T
// │ │ │ │ │ │ │ fun (Any).toString(): String
// │ │ │ │ │ │ │ │
return list.filter { it > threshold }.map { it.toString() }
}
fun main() {
// collections/List<String>
// │ fun <T> collections/listOf(vararg String): collections/List<String>
// │ │
val list = listOf("1", "2", "3")
// collections/List<String>
// │ fun <T : CharSequence> copyWhenGreater(collections/List<String>, String): collections/List<String> where copyWhenGreater.T : Comparable<String>
// │ │ val main.list: collections/List<String>
// │ │ │
val copy = copyWhenGreater(list, "2")
}
@@ -0,0 +1,36 @@
package p
class A {
val aProp = 10
}
class B {
val bProp = 1
}
fun foo(a: Int, b: Int): Int {
with(A()) {
aProp
with(B()) {
aProp
bProp
aProp
}
}
with(A()) {
aProp
with(B()) {
aProp
bProp
}
with(B()) {
aProp
bProp
}
}
return a
}
@@ -0,0 +1,12 @@
package org.jetbrains.kotlin.test
val listOfInt = listOf(1, 2, 3)
val javaList = java.util.ArrayList<Int>()
fun move(): java.util.ArrayList<Int> {
for (elem in listOfInt) {
javaList.add(elem)
}
return javaList
}
@@ -0,0 +1,34 @@
package org.jetbrains.kotlin.test
val p1 = 10
val p2: Double = 1.0
val p3: Float = 2.5f
val p4 = "some string"
val p5 = p1 + p2
val p6 = p1 * p2 + (p5 - p3)
val withGetter
get() = p1 * p3
var withSetter
get() = p4
set(value) = value
val withGetter2: Boolean
get() {
return true
}
var withSetter2: String
get() = "1"
set(value) {
field = value + "!"
}
private val privateGetter: String = "cba"
get
var privateSetter: String = "abc"
private set
@@ -0,0 +1,15 @@
package org.jetbrains.kotlin.test
abstract class Base<T>(var x: T) {
fun replace(newValue: T)
}
class Derived(var x: Int): Base<Int>() {
override fun replace(newValue: Int) {
x = newValue
}
}
fun test() {
Derived(10).replace(20)
}
@@ -0,0 +1,16 @@
interface Source<out T> {
fun nextT(): T
}
fun demo(strs: Source<String>) {
val objects: Source<Any> = strs
}
interface Comparable<in T> {
operator fun compareTo(other: T): Int
}
fun demo(x: Comparable<Number>) {
x.compareTo(1.0)
val y: Comparable<Double> = x
}
@@ -0,0 +1,10 @@
fun <T> copyWhenGreater(list: List<T>, threshold: T): List<String>
where T : CharSequence,
T : Comparable<T> {
return list.filter { it > threshold }.map { it.toString() }
}
fun main() {
val list = listOf("1", "2", "3")
val copy = copyWhenGreater(list, "2")
}
@@ -48,4 +48,9 @@ abstract class AbstractPsiVisualizer: KotlinMultiFileTestWithJava<Void?, Void?>(
replacement = "fir\\psi2fir" to "visualizer"
doTest(filePath)
}
fun doUncommonCasesTest(filePath: String) {
replacement = "testFiles" to "resultFiles"
doTest(filePath)
}
}
@@ -0,0 +1,61 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.visualizer;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TargetBackend;
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("compiler/visualizer/testData/uncommonCases/testFiles")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class PsiVisualizerForUncommonCasesGenerated extends AbstractPsiVisualizer {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doUncommonCasesTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInTestFiles() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/visualizer/testData/uncommonCases/testFiles"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("innerWith.kt")
public void testInnerWith() throws Exception {
runTest("compiler/visualizer/testData/uncommonCases/testFiles/innerWith.kt");
}
@TestMetadata("lists.kt")
public void testLists() throws Exception {
runTest("compiler/visualizer/testData/uncommonCases/testFiles/lists.kt");
}
@TestMetadata("properties.kt")
public void testProperties() throws Exception {
runTest("compiler/visualizer/testData/uncommonCases/testFiles/properties.kt");
}
@TestMetadata("superTypes.kt")
public void testSuperTypes() throws Exception {
runTest("compiler/visualizer/testData/uncommonCases/testFiles/superTypes.kt");
}
@TestMetadata("variance.kt")
public void testVariance() throws Exception {
runTest("compiler/visualizer/testData/uncommonCases/testFiles/variance.kt");
}
@TestMetadata("where.kt")
public void testWhere() throws Exception {
runTest("compiler/visualizer/testData/uncommonCases/testFiles/where.kt");
}
}