Skip to content

Commit

Permalink
Added few checks and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fan87 committed Jun 19, 2022
1 parent 9a78daf commit 891ed6c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/kotlin/me/fan87/regbex/Regbex.kt
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,20 @@ class Regbex {
if (it is IntInsnNode) {
return@thenCustomCheck it.operand == number
}
if (it is LdcInsnNode) {
return@thenCustomCheck it.cst == number
}
return@thenCustomCheck false
}
}

/**
* Expect a Ldc node with value [any]
*/
fun thenLdc(any: Any) {
thenCustomCheck { it is LdcInsnNode && it == any }
}


}

Expand Down
38 changes: 38 additions & 0 deletions src/test/kotlin/GreedyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,42 @@ class GreedyTest {
assertTrue(matcher.next(0))
}

@Test
internal fun greedyTestC() {
val instructions = InsnList().apply {
add(LdcInsnNode("A"))
add(LdcInsnNode("B"))
add(LdcInsnNode("C"))
}

val matcher = RegbexPattern {
thenLdcString()
thenOptional {
thenLdcStringEqual("B")
}
thenLdcString()
}.matcher(instructions)

assertTrue(matcher.next(0))
}

@Test
internal fun greedyTestD() {
val instructions = InsnList().apply {
add(LdcInsnNode("A"))
add(LdcInsnNode("B"))
add(LdcInsnNode("C"))
}

val matcher = RegbexPattern {
thenLdcString()
thenOptional {
thenLdcStringEqual("C")
}
thenLdcString()
}.matcher(instructions)

assertTrue(matcher.next(0))
}

}

0 comments on commit 891ed6c

Please sign in to comment.