[Spec tests] Add spec tests for kotlin.Nothing, kotlin.Unit, reference equality and cast expressions

This commit is contained in:
anastasiia.spaseeva
2019-11-18 18:20:27 +03:00
parent bf50edee17
commit 44d0a99875
31 changed files with 1194 additions and 32 deletions
@@ -0,0 +1,23 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, built-in-types-and-their-semantics, kotlin.nothing-1 -> paragraph 1 -> sentence 1
* NUMBER: 10
* DESCRIPTION: ckeck a common type of String and Nothing is String
*/
fun box(): String {
var name: Any? = null
val men = arrayListOf(Man("Phill"), Man())
loop@ for (i in men) {
name = i.name ?: break@loop
}
if (name is String?) return "OK"
return "NOK"
}
private class Man(var name: String? = null) {}
@@ -0,0 +1,21 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, built-in-types-and-their-semantics, kotlin.nothing-1 -> paragraph 1 -> sentence 1
* NUMBER: 2
* DESCRIPTION:
*/
fun box(): String {
try {
exit()
} catch (e: NullPointerException) {
return "OK"
}
return "NOK"
}
fun exit(): Nothing = null!!
@@ -0,0 +1,23 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, built-in-types-and-their-semantics, kotlin.nothing-1 -> paragraph 1 -> sentence 1
* NUMBER: 3
* DESCRIPTION:
*/
fun box(): String {
val bar = ::exit
try {
bar()
} catch (e: NotImplementedError) {
return "OK"
}
return "NOK"
}
private fun exit(): Nothing = TODO()
@@ -0,0 +1,25 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, built-in-types-and-their-semantics, kotlin.nothing-1 -> paragraph 1 -> sentence 1
* NUMBER: 4
* DESCRIPTION:
*/
fun box(): String {
val bar = ::exit
try {
bar(enter())
} catch (e: NotImplementedError) {
return "OK"
}
return "NOK"
}
private fun exit(x: () -> Any?): Nothing = throw Exception(x().toString())
private fun enter(): Nothing = TODO()
@@ -0,0 +1,30 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, built-in-types-and-their-semantics, kotlin.nothing-1 -> paragraph 1 -> sentence 1
* NUMBER: 5
* DESCRIPTION:
*/
fun box(): String {
val person = Person("Elvis")
person.name
try {
person.name = null
person.name ?: throwException("Name is required")
} catch (e: IllegalArgumentException) {
return "OK"
}
return "NOK"
}
class Person(var name: String?) {}
fun throwException(m: String): Nothing {
throw IllegalArgumentException(m)
}
@@ -0,0 +1,36 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, built-in-types-and-their-semantics, kotlin.nothing-1 -> paragraph 1 -> sentence 1
* NUMBER: 6
* DESCRIPTION:
*/
fun box(): String {
val info = Info<String>()
info.getData { "text " }
val infoUseless = InfoUseless()
try {
infoUseless.getData { throw IllegalArgumentException() }
} catch (e: IllegalArgumentException) {
return "OK"
}
return "NOK"
}
interface Infoable<T> {
fun getData(d: () -> T): T
}
open class Info<T : CharSequence> : Infoable<T> {
override fun getData(d: () -> T): T {
return d()
}
}
class InfoUseless : Info<Nothing>() {}
@@ -0,0 +1,33 @@
// WITH_RUNTIME
// FULL_JDK
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, built-in-types-and-their-semantics, kotlin.nothing-1 -> paragraph 1 -> sentence 1
* NUMBER: 7
* DESCRIPTION:
*/
import java.util.*
fun box() : String{
val deque1 = ArrayDeque<Any>()
val deque2 = ArrayDeque<Any>()
deque1.add { throw IllegalArgumentException() }
deque1.add { throw NullPointerException() }
deque1.add { TODO() }
move(deque1, deque2)
val v = deque2.first as () -> Nothing
try {
v.invoke()
} catch (e: NotImplementedError) {
return "OK"
}
return "NOK"
}
fun <T> move(from: ArrayDeque<out T>, to: ArrayDeque<in T>) {
to.add(from.last())
}
@@ -0,0 +1,37 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, built-in-types-and-their-semantics, kotlin.nothing-1 -> paragraph 1 -> sentence 1
* NUMBER: 8
* DESCRIPTION:
*/
fun box(): String {
val c = Class()
try {
val a: () -> Nothing = c.data
a.invoke()
} catch (e: IllegalArgumentException) {
try {
val d: () -> Nothing = c.value
d()
} catch (e: NotImplementedError) {
return "OK"
}
}
return "NOK"
}
open class Class() {
var data: () -> Nothing = { throwException("data") as Nothing }
val value: () -> Nothing
get() = { TODO() as Nothing }
}
private fun throwException(m: String): Any {
throw IllegalArgumentException(m)
}
@@ -0,0 +1,52 @@
// WITH_RUNTIME
// FULL_JDK
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, built-in-types-and-their-semantics, kotlin.nothing-1 -> paragraph 1 -> sentence 1
* NUMBER: 9
* DESCRIPTION:
*/
fun box(): String {
try {
val city = City()
} catch (e: NotImplementedError) {
val city = City("", 1)
city.country
try {
city.lakeConsumer()
} catch (e: NotImplementedError) {
try {
city.streetsConsumer.stream().forEach { street -> street.invoke() }
} catch (e: IllegalArgumentException) {
try {
val city = City("", 2) { "lake" }
city.streetsConsumer[3].invoke()
} catch (e: UnsupportedOperationException) {
return "OK"
}
}
}
}
return "NOK"
}
class City(val name: String = "", val index: Any = TODO()) {
var country: String = "Rus"
var lakeConsumer: () -> String
var streetsConsumer: MutableList<() -> String>
init {
lakeConsumer = { TODO() }
streetsConsumer = mutableListOf({ "x" }, { "y" }, { throw IllegalArgumentException() })
}
constructor(name: String, index: Any, lakeConsumer: () -> String) : this(name, index) {
this.lakeConsumer = lakeConsumer
this.streetsConsumer.add { throw UnsupportedOperationException() }
}
}
@@ -5,7 +5,61 @@
{
"specVersion": "0.1-213",
"casesNumber": 0,
"description": "todo",
"description": "",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-213",
"casesNumber": 0,
"description": "",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-213",
"casesNumber": 0,
"description": "",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-213",
"casesNumber": 0,
"description": "",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-213",
"casesNumber": 0,
"description": "ckeck a common type of String and Nothing is String",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-213",
"casesNumber": 0,
"description": "",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-213",
"casesNumber": 0,
"description": "",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-213",
"casesNumber": 0,
"description": "",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-213",
"casesNumber": 0,
"description": "",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-213",
"casesNumber": 0,
"description": "check kotlin.Nothing by throwing the exception",
"unexpectedBehaviour": false
}
]
@@ -0,0 +1,30 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, cast-expression -> paragraph 1 -> sentence 1
* NUMBER: 1
* DESCRIPTION: check of the cast operators as or as?
*/
fun box(): String {
val c = Class()
if (c.data !is () -> Nothing) return "NOK"
val e1 : () -> Nothing = c.exception as () -> Nothing as? () -> Nothing ?: return "NOK"
val v = c.value as () -> Nothing as? () -> Nothing ?: return "NOK"
return "OK"
}
open class Class() {
var data: () -> Nothing = { throwException("boo") as Nothing }
var exception: () -> CharSequence = { throwException("foo") as String }
val value: () -> Any
get() = { TODO() as Nothing }
}
private fun throwException(m: String): Any {
throw IllegalArgumentException(m)
}
@@ -0,0 +1,14 @@
{
"1": {
"pos": {
"1": [
{
"specVersion": "0.1-213",
"casesNumber": 0,
"description": " check of the cast operators as or as?",
"unexpectedBehaviour": false
}
]
}
}
}
@@ -0,0 +1,28 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, equality-expressions, reference-equality-expressions -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, built-in-types-and-their-semantics, kotlin.unit -> paragraph 1 -> sentence 1
* NUMBER: 1
* DESCRIPTION: check if two values are equal (===) by reference
*/
fun box(): String {
val u1 = foo1()
val u2 = foo2()
if (u1 === u2) {
return ("OK")
}
return ("NOK")
}
fun foo1() {
return Unit
}
fun foo2(): Unit {
return Unit
}
@@ -0,0 +1,22 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, equality-expressions, reference-equality-expressions -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, built-in-types-and-their-semantics, kotlin.unit -> paragraph 1 -> sentence 1,
* expressions, equality-expressions, reference-equality-expressions -> paragraph 3 -> sentence 3
* expressions, equality-expressions, reference-equality-expressions -> paragraph 2 -> sentence 1
* NUMBER: 2
* DESCRIPTION: check if two values are equal (===) by reference
*/
fun box(): String {
val u1 = "foo"
val u2 = "foo"
if (u1 === u2) {
return ("OK")
}
return ("NOK")
}
@@ -0,0 +1,20 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, equality-expressions, reference-equality-expressions -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, built-in-types-and-their-semantics, kotlin.unit -> paragraph 1 -> sentence 1
* NUMBER: 3
* DESCRIPTION: check if two values are non-equal (!==) by reference
*/
fun box(): String {
val u1 = "boo"
val u2 = "foo"
if (u1 !== u2) {
return ("OK")
}
return ("NOK")
}
@@ -0,0 +1,24 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, equality-expressions, reference-equality-expressions -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, built-in-types-and-their-semantics, kotlin.unit -> paragraph 1 -> sentence 1
* NUMBER: 4
* DESCRIPTION: check if values are non-equal (!==) by reference
*/
fun box(): String {
val u1 = "foo"
val byteArray = "foo".toByteArray(Charsets.UTF_8)
val u2 = byteArray.toString()
val u3 = byteArray.toString()
if (u1 !== u2 && u1 !== u3 && u2 !== u3 &&
u2 !== u1 && u3 !== u1 && u3 !== u2
) {
return ("OK")
}
return ("NOK")
}
@@ -0,0 +1,29 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, equality-expressions, reference-equality-expressions -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, built-in-types-and-their-semantics, kotlin.unit -> paragraph 1 -> sentence 1
* NUMBER: 5
* DESCRIPTION: two values are equal (===) or non-equal (!==) by reference
*/
fun box(): String {
val c1 = c
val c2 = c
val v1 = v
val v2 = v
if (c2 === c1 && c1 === c2 && c1 === c && c2 === c &&
v2 === v1 && v1 === v2 && v1 === v && v2 === v &&
v2 === c1 && v1 === c2 && v1 === c && v2 === c &&
c2 === v1 && c1 === v2 && c1 === v && c2 === v
) {
return ("OK")
}
return ("NOK")
}
const val c = 1000
const val v = 1000
@@ -0,0 +1,24 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, equality-expressions, reference-equality-expressions -> paragraph 1 -> sentence 3
* RELEVANT PLACES: expressions, built-in-types-and-their-semantics, kotlin.unit -> paragraph 1 -> sentence 1
* NUMBER: 1
* DESCRIPTION: check equallity by refference via constructor
*/
fun box(): String {
val u2 = mutableListOf<Int>(1, 2, 3)
val u3 = u1
if (u1 !== u2 && u1 === u3
) {
return ("OK")
}
return ("NOK")
}
val u1 = mutableListOf<Int>(1, 2, 3)
@@ -0,0 +1,23 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, type-checking-and-containment-checking-expressions, type-checking-expression -> paragraph 1 -> sentence 3
* NUMBER: 1
* DESCRIPTION:checks whether the runtime type of E is not a subtype of T for !is operator.
*/
fun box(): String {
val bar = ::boo
val bar1 = ::exit
if (bar !is () -> Nothing && bar1 !is (Nothing) -> Nothing) return "NOK"
return "OK"
}
private fun boo(): Nothing = TODO()
private fun exit(x: () -> Any?): Nothing = throw Exception(x().toString())
private fun enter(): Nothing = TODO()
@@ -0,0 +1,23 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, type-checking-and-containment-checking-expressions, type-checking-expression -> paragraph 1 -> sentence 3
* NUMBER: 2
* DESCRIPTION:checks whether the runtime type of EE is a subtype of TT for is operator
*/
fun box(): String {
val bar = ::boo
val bar1 = ::exit
if (bar is () -> Nothing && bar1 is (Nothing) -> Nothing) return "OK"
return "NOK"
}
private fun boo(): Nothing = TODO()
private fun exit(x: () -> Any?): Nothing = throw Exception(x().toString())
private fun enter(): Nothing = TODO()
@@ -0,0 +1,20 @@
{
"1": {
"pos": {
"3": [
{
"specVersion": "0.1-213",
"casesNumber": 0,
"description": "checks whether the runtime type of E is not a subtype of T for !is operator.",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-213",
"casesNumber": 0,
"description": "checks whether the runtime type of EE is a subtype of TT for is operator",
"unexpectedBehaviour": false
}
]
}
}
}
@@ -9,11 +9,10 @@
* DESCRIPTION: todo
*/
fun box() {
val b : Any? = null
fun box(): String {
val b : Nothing?= null
try {
val a: Int
a = b!!
val a: Int = b!!
} catch (e: NullPointerException) {
return "OK"
}