Skip to content

Commit 891ed6c

Browse files
committed
Added few checks and more tests
1 parent 9a78daf commit 891ed6c

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

src/main/kotlin/me/fan87/regbex/Regbex.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,20 @@ class Regbex {
460460
if (it is IntInsnNode) {
461461
return@thenCustomCheck it.operand == number
462462
}
463+
if (it is LdcInsnNode) {
464+
return@thenCustomCheck it.cst == number
465+
}
463466
return@thenCustomCheck false
464467
}
465468
}
466469

470+
/**
471+
* Expect a Ldc node with value [any]
472+
*/
473+
fun thenLdc(any: Any) {
474+
thenCustomCheck { it is LdcInsnNode && it == any }
475+
}
476+
467477

468478
}
469479

src/test/kotlin/GreedyTest.kt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,42 @@ class GreedyTest {
5757
assertTrue(matcher.next(0))
5858
}
5959

60+
@Test
61+
internal fun greedyTestC() {
62+
val instructions = InsnList().apply {
63+
add(LdcInsnNode("A"))
64+
add(LdcInsnNode("B"))
65+
add(LdcInsnNode("C"))
66+
}
67+
68+
val matcher = RegbexPattern {
69+
thenLdcString()
70+
thenOptional {
71+
thenLdcStringEqual("B")
72+
}
73+
thenLdcString()
74+
}.matcher(instructions)
75+
76+
assertTrue(matcher.next(0))
77+
}
78+
79+
@Test
80+
internal fun greedyTestD() {
81+
val instructions = InsnList().apply {
82+
add(LdcInsnNode("A"))
83+
add(LdcInsnNode("B"))
84+
add(LdcInsnNode("C"))
85+
}
86+
87+
val matcher = RegbexPattern {
88+
thenLdcString()
89+
thenOptional {
90+
thenLdcStringEqual("C")
91+
}
92+
thenLdcString()
93+
}.matcher(instructions)
94+
95+
assertTrue(matcher.next(0))
96+
}
97+
6098
}

0 commit comments

Comments
 (0)