Lucaskyy 3ab42a932c refactor: Rename net.revanced to app.revanced
BREAKING CHANGE: Package name was changed from "net.revanced" to "app.revanced"
2022-03-23 19:56:37 +01:00

45 lines
1.3 KiB
Kotlin

package app.revanced.patcher.util
import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.FieldInsnNode
import org.objectweb.asm.tree.LdcInsnNode
import kotlin.test.fail
object TestUtil {
fun <T: AbstractInsnNode> assertNodeEqual(expected: T, actual: T) {
val a = expected.nodeString()
val b = actual.nodeString()
if (a != b) {
fail("expected: $a,\nactual: $b\n")
}
}
private fun AbstractInsnNode.nodeString(): String {
val sb = NodeStringBuilder()
when (this) {
// TODO(Sculas): Add more types
is LdcInsnNode -> sb
.addType("cst", cst)
is FieldInsnNode -> sb
.addType("owner", owner)
.addType("name", name)
.addType("desc", desc)
}
return "(${this::class.simpleName}): (type = $type, opcode = $opcode, $sb)"
}
}
private class NodeStringBuilder {
private val sb = StringBuilder()
fun addType(name: String, value: Any): NodeStringBuilder {
sb.append("$name = \"$value\", ")
return this
}
override fun toString(): String {
val s = sb.toString()
return s.substring(0 until s.length - 2) // remove the last ", "
}
}