Add 'not linked' kind of spec tests

This commit is contained in:
victor.petukhov
2018-08-28 19:06:59 +03:00
parent 841bb4f253
commit ecf8b88c4c
72 changed files with 1140 additions and 928 deletions
@@ -0,0 +1,29 @@
/*
KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
SECTION: when-expression
PARAGRAPH: 11
SENTENCE: [1] It has an else entry;
NUMBER: 1
DESCRIPTION: Check when exhaustive via else entry (when without bound value).
*/
// CASE DESCRIPTION: Checking for exhaustive 'when' (several value check branches and 'else' branch).
fun case_1(value: Int): String = when {
value == 0 -> ""
value > 0 && value <= 10 -> ""
value > 10 && value <= 100 -> ""
value > 100 -> ""
else -> ""
}
// CASE DESCRIPTION: Checking for exhaustive 'when' (value check branch and 'else' branch).
fun case_2(): String = when {
true -> ""
else -> ""
}
// CASE DESCRIPTION: Checking for exhaustive 'when' (only 'else' branch).
fun case_3(): String = when {
else -> ""
}
@@ -0,0 +1,40 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION
/*
KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
SECTION: when-expression
PARAGRAPH: 11
SENTENCE: [1] It has an else entry;
NUMBER: 2
DESCRIPTION: Check when exhaustive via else entry (when with bound value).
*/
// CASE DESCRIPTION: Checking for exhaustive 'when' (several branches).
fun case_1(value: Int): String = when (value) {
0 -> ""
1 -> ""
2 -> ""
3 -> ""
else -> ""
}
// CASE DESCRIPTION: Checking for exhaustive 'when' (value check branch and 'else' branch).
fun case_2(value: Boolean): String = when (value) {
true -> ""
else -> ""
}
/*
CASE DESCRIPTION: Checking for exhaustive 'when' with constant bound value (value check branch and 'else' branch).
NOTE: for potential bound value constant analysys.
*/
fun case_3(): String = when (true) {
true -> ""
else -> ""
}
// CASE DESCRIPTION: Checking for exhaustive 'when' (only 'else' branch).
fun case_4(value: Int): String = when(value) {
else -> ""
}
@@ -0,0 +1,76 @@
// !WITH_ENUM_CLASSES
// !WITH_SEALED_CLASSES
/*
KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
SECTION: when-expression
PARAGRAPH: 11
SENTENCE: [1] It has an else entry;
NUMBER: 3
DESCRIPTION: Check when exhaustive via else entry (when with bound value, redundant else).
*/
// CASE DESCRIPTION: Checking for redundant 'else' branch (all enum values covered).
fun case_1(value: _EnumClass): String = when (value) {
_EnumClass.EAST -> ""
_EnumClass.NORTH -> ""
_EnumClass.SOUTH -> ""
_EnumClass.WEST -> ""
<!REDUNDANT_ELSE_IN_WHEN!>else<!> -> ""
}
// CASE DESCRIPTION: Checking for redundant 'else' branch (all enum values and null value covered).
fun case_2(value: _EnumClass?): String = when (value) {
_EnumClass.EAST -> ""
_EnumClass.NORTH -> ""
_EnumClass.SOUTH -> ""
_EnumClass.WEST -> ""
null -> ""
<!REDUNDANT_ELSE_IN_WHEN!>else<!> -> ""
}
// CASE DESCRIPTION: Checking for redundant 'else' branch (both boolean value covered).
fun case_3(value: Boolean): String = when (value) {
true -> ""
false -> ""
<!REDUNDANT_ELSE_IN_WHEN!>else<!> -> ""
}
// CASE DESCRIPTION: Checking for redundant 'else' branch (both boolean value and null value covered).
fun case_4(value: Boolean?): String = when (value) {
true -> ""
false -> ""
null -> ""
<!REDUNDANT_ELSE_IN_WHEN!>else<!> -> ""
}
// CASE DESCRIPTION: Checking for redundant 'else' branch (all sealed class subtypes covered).
fun case_5(value: _SealedClass): String = when (value) {
is _SealedChild1 -> ""
is _SealedChild2 -> ""
is _SealedChild3 -> ""
<!REDUNDANT_ELSE_IN_WHEN!>else<!> -> ""
}
// CASE DESCRIPTION: Checking for redundant 'else' branch (all sealed class subtypes and null value covered).
fun case_6(value: _SealedClass?): String = when (value) {
is _SealedChild1 -> ""
is _SealedChild2 -> ""
is _SealedChild3 -> ""
null -> ""
<!REDUNDANT_ELSE_IN_WHEN!>else<!> -> ""
}
// CASE DESCRIPTION: Checking for redundant 'else' branch (sealed class itself covered).
fun case_7(value: _SealedClassSingle): String = when (value) {
<!USELESS_IS_CHECK!>is _SealedClassSingle<!> -> ""
<!REDUNDANT_ELSE_IN_WHEN!>else<!> -> ""
}
// CASE DESCRIPTION: Checking for redundant 'else' branch (sealed class itself and null value covered).
fun case_8(value: _SealedClassSingle?): String = when (value) {
is _SealedClassSingle -> ""
null -> ""
<!REDUNDANT_ELSE_IN_WHEN!>else<!> -> ""
}
@@ -0,0 +1,21 @@
/*
KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
SECTION: when-expression
PARAGRAPH: 11
SENTENCE: [3] The bound expression is of type kotlin.Boolean and the conditions contain both:
NUMBER: 1
DESCRIPTION: Check when exhaustive via boolean bound value and evaluating to value true and false.
*/
// CASE DESCRIPTION: Checking for exhaustive 'when' (both boolean value covered).
fun case_1(value: Boolean): String = when (value) {
true -> ""
false -> ""
}
// CASE DESCRIPTION: Checking for exhaustive 'when' (both boolean value as complex expression covered).
fun case_2(value: Boolean): String = when (value) {
true && false && ((true || false)) || true && !!!false && !!!true -> ""
true && false && ((true || false)) || true && !!!false -> ""
}
@@ -0,0 +1,66 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION
// !WITH_SEALED_CLASSES
/*
KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
SECTION: when-expression
PARAGRAPH: 11
SENTENCE: [6] The bound valueession is of a sealed class type and all its possible subtypes are covered using type test conditions of this valueession;
NUMBER: 1
DESCRIPTION: Check when exhaustive when possible subtypes of the sealed class are covered.
*/
// CASE DESCRIPTION: Checking for exhaustive 'when' (all sealed class subtypes covered).
fun case_1(value: _SealedClass): Int = when (value) {
is _SealedChild1 -> <!DEBUG_INFO_SMARTCAST!>value<!>.number
is _SealedChild2 -> <!DEBUG_INFO_SMARTCAST!>value<!>.e1 + <!DEBUG_INFO_SMARTCAST!>value<!>.e2
is _SealedChild3 -> <!DEBUG_INFO_SMARTCAST!>value<!>.m1 + <!DEBUG_INFO_SMARTCAST!>value<!>.m2
}
// CASE DESCRIPTION: Checking for exhaustive 'when' (single sealed class subtypes covered).
fun case_2(value: _SealedClass): String = when (value) {
<!USELESS_IS_CHECK!>is _SealedClass<!> -> ""
}
// CASE DESCRIPTION: Checking for exhaustive 'when' (all sealed class subtypes with methods covered).
fun case_3(value: _SealedClassWithMethods): String = when (value) {
is _SealedWithMethodsChild1 -> <!DEBUG_INFO_SMARTCAST!>value<!>.m1()
is _SealedWithMethodsChild2 -> <!DEBUG_INFO_SMARTCAST!>value<!>.m2()
is _SealedWithMethodsChild3 -> <!DEBUG_INFO_SMARTCAST!>value<!>.m3()
}
// CASE DESCRIPTION: Checking for exhaustive 'when' (all objects covered using implicit equality operator).
fun case_4(value: _SealedClassWithObjects): String = when (value) {
_SealedWithObjectsChild1 -> ""
_SealedWithObjectsChild2 -> ""
_SealedWithObjectsChild3 -> ""
}
// CASE DESCRIPTION: Checking for exhaustive 'when' (all subtypes and objects covered).
fun case_5(value: _SealedClassMixed): String = when (value) {
is _SealedMixedChild1 -> ""
is _SealedMixedChild2 -> ""
is _SealedMixedChild3 -> ""
_SealedMixedChildObject1 -> ""
_SealedMixedChildObject2 -> ""
_SealedMixedChildObject3 -> ""
}
/*
CASE DESCRIPTION: Checking for exhaustive 'when' (all subtypes and objects (using type checking operator) covered).
DISCUSSION: is it correct that objects can be checked using the type checking operator?
*/
fun case_6(value: _SealedClassMixed): String = when (value) {
is _SealedMixedChild1 -> ""
is _SealedMixedChild2 -> ""
is _SealedMixedChild3 -> ""
is _SealedMixedChildObject1 -> ""
is _SealedMixedChildObject2 -> ""
is _SealedMixedChildObject3 -> ""
}
// CASE DESCRIPTION: Checking for exhaustive 'when' on the empty sealed class (without subtypes).
fun case_7(value: _SealedClassEmpty): String = when (value) {
else -> ""
}
@@ -0,0 +1,24 @@
// !WITH_ENUM_CLASSES
/*
KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
SECTION: when-expression
PARAGRAPH: 11
SENTENCE: [7] The bound expression is of an Enum classes type and all enumerated values are checked for equality using constant conditions;
NUMBER: 1
DESCRIPTION: Check when exhaustive when all enumerated values are checked.
*/
// CASE DESCRIPTION: Checking for exhaustive 'when' (all enum values covered).
fun case_1(dir: _EnumClass): String = when (dir) {
_EnumClass.EAST -> ""
_EnumClass.NORTH -> ""
_EnumClass.SOUTH -> ""
_EnumClass.WEST -> ""
}
// CASE DESCRIPTION: Checking for exhaustive 'when' (single enum value covered).
fun case_2(value: _EnumClassSingle): String = when (value) {
_EnumClassSingle.EVERYTHING -> ""
}
@@ -0,0 +1,23 @@
/*
KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
SECTION: when-expression
PARAGRAPH: 11
SENTENCE: [8] The bound expression is of a nullable type and one of the cases above is met for its non-nullable counterpart and, in addition, there is a condition containing literal null.
NUMBER: 1
DESCRIPTION: Check when exhaustive when boolean values are checked and contains a null check.
*/
// CASE DESCRIPTION: Checking for exhaustive 'when' (both boolean values and null value covered).
fun case_1(value: Boolean?): String = when (value) {
true -> ""
false -> ""
null -> ""
}
// CASE DESCRIPTION: Checking for exhaustive 'when' (both boolean values as complex expressions and null value covered).
fun case_2(value: Boolean?): String = when (value) {
true && false && ((true || false)) || true && !!!false && !!!true -> ""
true && false && ((true || false)) || true && !!!false -> ""
null -> ""
}
@@ -0,0 +1,26 @@
// !WITH_ENUM_CLASSES
/*
KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
SECTION: when-expression
PARAGRAPH: 11
SENTENCE: [8] The bound expression is of a nullable type and one of the cases above is met for its non-nullable counterpart and, in addition, there is a condition containing literal null.
NUMBER: 2
DESCRIPTION: Check when exhaustive when enumerated values are checked and contains a null check.
*/
// CASE DESCRIPTION: Checking for exhaustive 'when' (both enum values and null value covered).
fun case_1(dir: _EnumClass?): String = when (dir) {
_EnumClass.EAST -> ""
_EnumClass.NORTH -> ""
_EnumClass.SOUTH -> ""
_EnumClass.WEST -> ""
null -> ""
}
// CASE DESCRIPTION: Checking for exhaustive 'when' (single enum value and null value covered).
fun case_2(value: _EnumClassSingle?): String = when (value) {
_EnumClassSingle.EVERYTHING -> ""
null -> ""
}
@@ -0,0 +1,66 @@
// !WITH_SEALED_CLASSES
/*
KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
SECTION: when-expression
PARAGRAPH: 11
SENTENCE: [8] The bound expression is of a nullable type and one of the cases above is met for its non-nullable counterpart and, in addition, there is a condition containing literal null.
NUMBER: 3
DESCRIPTION: Check when exhaustive when possible subtypes of the sealed class are covered and contains a null check.
*/
// CASE DESCRIPTION: Checking for exhaustive 'when' (all sealed class subtypes and null value covered).
fun case_1(expr: _SealedClass?): Int = when (expr) {
is _SealedChild1 -> <!DEBUG_INFO_SMARTCAST!>expr<!>.number
is _SealedChild2 -> <!DEBUG_INFO_SMARTCAST!>expr<!>.e1 + <!DEBUG_INFO_SMARTCAST!>expr<!>.e2
is _SealedChild3 -> <!DEBUG_INFO_SMARTCAST!>expr<!>.m1 + <!DEBUG_INFO_SMARTCAST!>expr<!>.m2
null -> 0
}
// CASE DESCRIPTION: Checking for exhaustive 'when' (sealed class itself and null value covered).
fun case_2(expr: _SealedClass?): String = when (expr) {
is _SealedClass -> ""
null -> ""
}
// CASE DESCRIPTION: Checking for exhaustive 'when' (all sealed class with methods subtypes and null value covered).
fun case_3(expr: _SealedClassWithMethods?): String = when (expr) {
is _SealedWithMethodsChild1 -> <!DEBUG_INFO_SMARTCAST!>expr<!>.m1()
is _SealedWithMethodsChild2 -> <!DEBUG_INFO_SMARTCAST!>expr<!>.m2()
is _SealedWithMethodsChild3 -> <!DEBUG_INFO_SMARTCAST!>expr<!>.m3()
null -> ""
}
// CASE DESCRIPTION: Checking for exhaustive 'when' (all objects covered using implicit equality operator and null value covered).
fun case_4(expr: _SealedClassWithObjects?): String = when (expr) {
_SealedWithObjectsChild1 -> ""
_SealedWithObjectsChild2 -> ""
_SealedWithObjectsChild3 -> ""
null -> ""
}
// CASE DESCRIPTION: Checking for exhaustive 'when' (all subtypes and objects covered + null value covered).
fun case_5(value: _SealedClassMixed?): String = when (value) {
is _SealedMixedChild1 -> ""
is _SealedMixedChild2 -> ""
is _SealedMixedChild3 -> ""
_SealedMixedChildObject1 -> ""
_SealedMixedChildObject2 -> ""
_SealedMixedChildObject3 -> ""
null -> ""
}
/*
CASE DESCRIPTION: Checking for exhaustive 'when' (all subtypes and objects (using type checking operator) covered + null value covered).
DISCUSSION: is it correct that objects can be checked using the type checking operator?
*/
fun case_6(value: _SealedClassMixed?): String = when (value) {
is _SealedMixedChild1 -> ""
is _SealedMixedChild2 -> ""
is _SealedMixedChild3 -> ""
is _SealedMixedChildObject1 -> ""
is _SealedMixedChildObject2 -> ""
is _SealedMixedChildObject3 -> ""
null -> ""
}