Skip to content

Commit

Permalink
✅ Fix TestHardInstanceOf
Browse files Browse the repository at this point in the history
  • Loading branch information
yhs0602 committed May 19, 2024
1 parent 502c6ea commit 3cd1df3
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/test/kotlin/AdvancedTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.yhs0602.vm.RegisterValue
import com.yhs0602.vm.executeMethod
import java.io.File
import java.io.PrintStream
import java.io.Serializable
import java.nio.file.Paths
import kotlin.jvm.internal.Intrinsics
import kotlin.test.BeforeTest
Expand Down Expand Up @@ -87,6 +88,26 @@ class AdvancedTest {
)
}

@Test
fun TestHardInstanceOf() {
testInterpreter(
"src/test/resources/advanced/",
"com.example.sample",
"InstanceOfTestKt",
"advancedInstanceOfTest",
listOf(
GeneralMockedClass(StringBuilder::class.java),
GeneralMockedClass(System::class.java),
GeneralMockedClass(Intrinsics::class.java),
GeneralMockedClass(Object::class.java),
GeneralMockedClass(PrintStream::class.java),
GeneralMockedClass(File::class.java),
GeneralMockedClass(Serializable::class.java),
GeneralMockedClass(Comparable::class.java),
)
)
}

@Test
fun TestStatic() {
testInterpreter(
Expand Down
Binary file modified src/test/resources/advanced/classes4.dex
Binary file not shown.
46 changes: 46 additions & 0 deletions src/test/resources/advanced/instanceoftest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.example.sample

import java.io.File
import java.io.Serializable

open class B

open class C: B()
Expand Down Expand Up @@ -78,5 +81,48 @@ fun testInstanceOf() {
assert((f5 as Any) !is I1)
assert(f6 is I1)

println("All tests passed!")
}

open class HardA: File("")

open class HardB: Serializable

open class HardC: Comparable<HardC> {
override fun compareTo(other: HardC): Int {
return 0
}
}

class HardD: HardA()

class HardE: HardB()

class HardF: HardC(), Serializable

fun advancedInstanceOfTest() {
val a = HardA()
val b = HardB()
val c = HardC()
val d = HardD()
val e = HardE()
val f = HardF()

assert(a is File)
assert(b is Serializable)
assert(c is Comparable<HardC>)

assert(d is HardA)
assert(d is File)
assert(d is Serializable)
assert(d is Comparable<*>)

assert(e is Serializable)
assert(e is HardB)

assert(f is Serializable)
assert(f is Comparable<HardC>)
assert(f is HardC)

println("All tests passed!")
}

0 comments on commit 3cd1df3

Please sign in to comment.