[java] Fix unit tests

This commit is contained in:
Andreas Dangel committed 2022-11-04 17:25:12 +01:00
1 parent 346dcd30ba
commit b6d33d8473
3 files changed
+71 -26

No files matched your search

@@ -213,7 +213,7 @@ class ASTEnumConstantTest : ParserTestSpec({
it::getModifiers shouldBe modifiers {
it.explicitModifiers should beEmpty()
it.effectiveModifiers.shouldContainExactly(PUBLIC, STATIC, FINAL)
it.effectiveModifiers.shouldContainExactly(setOf(PUBLIC, STATIC, FINAL))
}
it::getVarId shouldBe variableId("B") {
@@ -60,13 +60,13 @@ class TypeEqualityTest : FunSpec({
fun canBeWildCardBound(t: JTypeMirror) = !(t.isPrimitive || t is JWildcardType)
forAll(ts.allTypesGen, ts.allTypesGen) { t, s ->
canBeWildCardBound(t) implies {
(canBeWildCardBound(t) && canBeWildCardBound(s)) implies {
(t == s) == (`?` extends t == `?` extends s)
}
}
forAll(ts.allTypesGen, ts.allTypesGen) { t, s ->
canBeWildCardBound(t) implies {
(canBeWildCardBound(t) && canBeWildCardBound(s)) implies {
(t == s) == (`?` `super` t == `?` `super` s)
}
}
@@ -16,7 +16,7 @@ class ConditionalTypeTest : FunSpec({}) {
private val tested = mutableMapOf<TypePair, JTypeMirror>()
fun test(t1: JTypeMirror, t2: JTypeMirror, expected: JTypeMirror) {
private fun runTest(t1: JTypeMirror, t2: JTypeMirror, expected: JTypeMirror) {
val key = TypePair(t1, t2)
if (key in tested && tested[key] != expected)
throw AssertionError("Already tested $t1 : $t2 against ${tested[key]}, doesn't match $expected")
@@ -24,9 +24,7 @@ class ConditionalTypeTest : FunSpec({}) {
tested[key] = expected
test("$t1 : $t2 => $expected") {
PolyResolution.computeStandaloneConditionalType(testTypeSystem, t1, t2) shouldBe expected
}
PolyResolution.computeStandaloneConditionalType(testTypeSystem, t1, t2) shouldBe expected
}
@@ -41,21 +39,64 @@ class ConditionalTypeTest : FunSpec({}) {
context("Tests for conditional expressions") {
// we need a suspend fun
prims.checkAll {
test(it, it, it)
test(it.box(), it, it)
test(it, it.box(), it)
test(it.box(), it.box(), it.box())
test(ts.NULL_TYPE, it, ts.lub(ts.NULL_TYPE, it.box()))
test(it, ts.NULL_TYPE, ts.lub(it.box(), ts.NULL_TYPE))
test(it.box(), ts.NULL_TYPE, it.box())
test("Primitive Types") {
prims.checkAll {
runTest(it, it, it)
}
}
refTypes.checkAll {
test(it, it, it)
test(ts.NULL_TYPE, it, it)
test(it, ts.NULL_TYPE, it)
test("Primitive Types with left one boxed") {
prims.checkAll {
runTest(it.box(), it, it)
}
}
test("Primitive Types with right one boxed") {
prims.checkAll {
runTest(it, it.box(), it)
}
}
test("Primitive Types all boxed") {
prims.checkAll {
runTest(it.box(), it.box(), it.box())
}
}
test("Primitive Types with left one null") {
prims.checkAll {
runTest(ts.NULL_TYPE, it, ts.lub(ts.NULL_TYPE, it.box()))
}
}
test("Primitive Types with right one null") {
prims.checkAll {
runTest(it, ts.NULL_TYPE, ts.lub(it.box(), ts.NULL_TYPE))
}
}
test("Primitive Types with null and boxed") {
prims.checkAll {
runTest(it.box(), ts.NULL_TYPE, it.box())
}
}
test("Reference Types") {
refTypes.checkAll {
runTest(it, it, it)
}
}
test("Reference Types with left one null") {
refTypes.checkAll {
runTest(ts.NULL_TYPE, it, it)
}
}
test("Reference Types with right one null") {
refTypes.checkAll {
runTest(it, ts.NULL_TYPE, it)
}
}
val shortOnes =
@@ -65,7 +106,9 @@ class ConditionalTypeTest : FunSpec({}) {
}
shortOnes.forEach { (a, b) -> test(a, b, ts.SHORT) }
test("Short Types (BYTE, SHORT)") {
shortOnes.forEach { (a, b) -> runTest(a, b, ts.SHORT) }
}
val allPrims: List<JTypeMirror> = (prims.values + prims.values.map { it.box() })
@@ -74,13 +117,15 @@ class ConditionalTypeTest : FunSpec({}) {
.filter { (a, b) -> a != b }
.filter { (a, b) -> a.isNumeric && b.isNumeric }
bnpOnes.forEach { (a, b) ->
test(a, b, bnp(a, b))
test("Binary Numeric Promotion") {
bnpOnes.forEach { (a, b) -> runTest(a, b, bnp(a, b)) }
}
(allPrims - ts.BOOLEAN - ts.BOOLEAN.box()).forEach {
test(it, ts.BOOLEAN, ts.lub(it.box(), ts.BOOLEAN.box()))
test(ts.BOOLEAN, it, ts.lub(it.box(), ts.BOOLEAN.box()))
test("Boolean") {
(allPrims - ts.BOOLEAN - ts.BOOLEAN.box()).forEach {
runTest(it, ts.BOOLEAN, ts.lub(it.box(), ts.BOOLEAN.box()))
runTest(ts.BOOLEAN, it, ts.lub(it.box(), ts.BOOLEAN.box()))
}
}
}
}