[Spec tests] Add tests for kotlin.Nothing and kotlin.Unit built-in types

This commit is contained in:
anastasiia.spaseeva
2019-11-18 18:20:27 +03:00
parent 52ac8d788d
commit bf50edee17
16 changed files with 727 additions and 50 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: 1
* DESCRIPTION: todo
*/
fun foo(): Nothing {
throw Exception()
}
fun box() {
try {
foo()
} catch (e: Exception) {
return "OK"
}
return "NOK"
}
@@ -0,0 +1,14 @@
{
"1": {
"pos": {
"1": [
{
"specVersion": "0.1-213",
"casesNumber": 0,
"description": "todo",
"unexpectedBehaviour": false
}
]
}
}
}
@@ -0,0 +1,31 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, built-in-types-and-their-semantics, kotlin.unit -> paragraph 1 -> sentence 1
* NUMBER: 1
* DESCRIPTION: todo
*/
fun foo1() {
return Unit
}
fun foo2(): Unit {
return Unit
}
fun foo3(): Unit {
}
fun box(){
val u1 = foo1()
val u2 = foo2()
val u3 = foo3()
if (u1 === u2 && u1 === u3 && u2 === u3) {
return ( "OK")
}
return ( "NOK")
}
@@ -0,0 +1,14 @@
{
"1": {
"pos": {
"1": [
{
"specVersion": "0.1-213",
"casesNumber": 0,
"description": "todo",
"unexpectedBehaviour": false
}
]
}
}
}
@@ -0,0 +1,21 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: type-system, type-kinds, built-in-types, kotlin.nothing -> paragraph 1 -> sentence 1
* NUMBER: 1
* DESCRIPTION: todo
*/
fun box() {
val b : Any? = null
try {
val a: Int
a = b!!
} catch (e: NullPointerException) {
return "OK"
}
return "NOK"
}
@@ -0,0 +1,26 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: type-system, type-kinds, built-in-types, kotlin.nothing -> paragraph 1 -> sentence 1
* NUMBER: 2
* DESCRIPTION: todo
*/
fun foo(s: String?): String {
val data = s ?: throw IllegalArgumentException("not null string is expected");
}
fun box() {
val result = "NOK"
val b = foo("")
try {
val a = foo(null)
} catch (e: IllegalArgumentException) {
result = "OK"
}
return result
}
@@ -0,0 +1,20 @@
{
"1": {
"pos": {
"1": [
{
"specVersion": "0.1-213",
"casesNumber": 0,
"description": "todo",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-213",
"casesNumber": 0,
"description": "todo",
"unexpectedBehaviour": false
}
]
}
}
}
@@ -0,0 +1,72 @@
// !LANGUAGE: +NewInference
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, built-in-types-and-their-semantics, kotlin.unit -> paragraph 1 -> sentence 1
* NUMBER: 1
* DESCRIPTION: Check of Unit type
* HELPERS: checkType
*/
// TESTCASE NUMBER: 1
fun foo() {
val proc = "case 1"
}
class Case1() {
checkType<Unit>(foo())
}
// TESTCASE NUMBER: 2
fun case2foo(m: String, bar: (m: String) -> Unit) {
bar(m)
}
class Case2Boo {
fun buz(m: String) {
val proc = "case 2"
}
}
class Case2() {
val boo = Case2Boo()
val res = case2foo("s", boo::buz)
checkType<Unit>(res)
}
// TESTCASE NUMBER: 3
interface Processable<T> {
fun process(): T
}
class Processor : Processable<Unit> {
override fun process() {
val proc = "case 3"
}
}
class Case3() {
val p1 = Processor().process()
checkType<Unit>(p1)
}
// TESTCASE NUMBER: 4
class Case4() {
val p2 = object : Processable<Unit> {
override fun process() {
val proc = "case 4"
}
}
checkType<Unit>(p2)
}
@@ -0,0 +1,14 @@
{
"1": {
"pos": {
"1": [
{
"specVersion": "0.1-213",
"casesNumber": 4,
"description": "Check of Unit type",
"unexpectedBehaviour": false
}
]
}
}
}
@@ -0,0 +1,20 @@
// !LANGUAGE: +NewInference
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: type-system, type-kinds, built-in-types, kotlin.nothing -> paragraph 1 -> sentence 2
* NUMBER: 1
* DESCRIPTION: Check of Nothing type
* HELPERS: checkType
*/
// TESTCASE NUMBER: 1
class Case1(val nothing: Nothing)
fun case1() {
val res = Case1(Nothing())
}
@@ -0,0 +1,44 @@
// !LANGUAGE: +NewInference
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: type-system, type-kinds, built-in-types, kotlin.nothing -> paragraph 1 -> sentence 1
* NUMBER: 1
* DESCRIPTION: Check of Nothing type is a subtype of any types
* HELPERS: checkType
*/
class NothingWrapper() {
val data: Nothing
}
class CustomClass
// TESTCASE NUMBER: 1
fun case1(wrapper: NothingWrapper) {
checkSubtype<Any>(wrapper.data)
checkSubtype<Function<Nothing>>(wrapper.data)
checkSubtype<Int>(wrapper.data)
checkSubtype<Short>(wrapper.data)
checkSubtype<Byte>(wrapper.data)
checkSubtype<Long>(wrapper.data)
checkSubtype<kotlin.Array>(wrapper.data)
checkSubtype<CustomClass>(wrapper.data)
}
// TESTCASE NUMBER: 2
fun case2(wrapper: NothingWrapper) {
checkSubtype<MutableList<out Nothing>>(wrapper.data)
checkSubtype<MutableList<in String>>(wrapper.data)
checkSubtype<MutableList<Any?>>(wrapper.data)
checkSubtype<String>(wrapper.data)
checkSubtype<in CustomClass>(wrapper.data)
checkSubtype<out CustomClass>(wrapper.data)
}
@@ -0,0 +1,46 @@
// !LANGUAGE: +NewInference
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-213
* PLACE: type-system, type-kinds, built-in-types, kotlin.nothing -> paragraph 1 -> sentence 2
* NUMBER: 1
* DESCRIPTION: Check of Nothing as a subtype of any type
* HELPERS: checkType
*/
// TESTCASE NUMBER: 1
class Case1() {
val data: Nothing = TODO()
}
fun case1(c: Case1) {
checkSubtype<Int>(c.data)
checkSubtype<Function<Nothing>>(c.data)
}
// TESTCASE NUMBER: 2
class Case2 {
var data: String
}
fun case2(c: Case2) {
val testValue = c.data ?: throw IllegalArgumentException("data required")
testValue checkType { check<Nothing>() }
}
// TESTCASE NUMBER: 3
class Case3 {
val dataFunction = fail("fail msg")
}
fun fail(msg: String): Nothing {
throw new Exception (msg)
}
fun case3(c: Case3) {
val testValue = c.dataFunction()
checkType<Nothing>(testValue)
}
@@ -0,0 +1,32 @@
{
"1": {
"neg": {
"2": [
{
"specVersion": "0.1-213",
"casesNumber": 1,
"description": "Check of Nothing type",
"unexpectedBehaviour": false
}
]
},
"pos": {
"2": [
{
"specVersion": "0.1-213",
"casesNumber": 3,
"description": "Check of Nothing as a subtype of any type",
"unexpectedBehaviour": false
}
],
"1": [
{
"specVersion": "0.1-213",
"casesNumber": 2,
"description": "Check of Nothing type is a subtype of any types",
"unexpectedBehaviour": false
}
]
}
}
}