diff --git a/src/main/kotlin/me/fan87/regbex/Regbex.kt b/src/main/kotlin/me/fan87/regbex/Regbex.kt index 511604b..0ee2b4c 100644 --- a/src/main/kotlin/me/fan87/regbex/Regbex.kt +++ b/src/main/kotlin/me/fan87/regbex/Regbex.kt @@ -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 } + } + } diff --git a/src/test/kotlin/GreedyTest.kt b/src/test/kotlin/GreedyTest.kt index 2d3b646..0c4ec50 100644 --- a/src/test/kotlin/GreedyTest.kt +++ b/src/test/kotlin/GreedyTest.kt @@ -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)) + } + } \ No newline at end of file