Skip to content

Commit f3b0fed

Browse files
committed
Made assertion repairs only run when regex contains assertions.
1 parent 7874c1d commit f3b0fed

3 files changed

Lines changed: 22 additions & 14 deletions

File tree

core/src/main/kotlin/org/evomaster/core/parser/GeneRegexJavaVisitor.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class GeneRegexJavaVisitor(val sourceRegex: String, val externalRegexFlags: Rege
6060
*/
6161
private var currentFlags = externalRegexFlags
6262

63+
private var hasAssertions = false
64+
6365
/**
6466
* Builds DisjunctionListRxGenes from a disjunction context, returns null if disjunction is unsatisfiable.
6567
*/
@@ -127,7 +129,8 @@ class GeneRegexJavaVisitor(val sourceRegex: String, val externalRegexFlags: Rege
127129
disjList,
128130
sourceRegex,
129131
RegexType.JVM,
130-
externalRegexFlags = externalRegexFlags
132+
externalRegexFlags = externalRegexFlags,
133+
hasAssertions = hasAssertions
131134
)
132135

133136
return VisitResult(gene)
@@ -257,6 +260,7 @@ class GeneRegexJavaVisitor(val sourceRegex: String, val externalRegexFlags: Rege
257260
rejectIfNestedAssertion(ctx.assertion())
258261
val innerDisjList = buildDisjunctionList(assertionCtx.disjunction())
259262
val assertionGene = AssertionRxGene(innerDisjList)
263+
hasAssertions = true
260264
res.genes.add(assertionGene)
261265
}
262266
return res

core/src/main/kotlin/org/evomaster/core/search/gene/regex/RegexGene.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class RegexGene(
3737
*/
3838
var fixedValue: String? = null,
3939
var usingFixedValue: Boolean = false,
40-
val externalRegexFlags: RegexFlags = RegexFlags()
40+
val externalRegexFlags: RegexFlags = RegexFlags(),
41+
val hasAssertions: Boolean = false
4142
) : CompositeFixedGene(name, disjunctions) {
4243

4344

@@ -75,9 +76,11 @@ class RegexGene(
7576
if (pattern!!.matcher(disjunctions.getValueAsPrintableString()).find()) {
7677
return
7778
}
78-
disjunctions.attemptAssertionRepair(randomness)
79-
if (pattern.matcher(disjunctions.getValueAsPrintableString()).find()) {
80-
return
79+
if (hasAssertions) {
80+
disjunctions.attemptAssertionRepair(randomness)
81+
if (pattern.matcher(disjunctions.getValueAsPrintableString()).find()) {
82+
return
83+
}
8184
}
8285
}
8386

core/src/main/kotlin/org/evomaster/core/utils/MultiCharacterRange.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,18 @@ class MultiCharacterRange internal constructor(val ranges: List<CharacterRange>)
208208
* Check if [c] is contained in this [MultiCharacterRange].
209209
*/
210210
fun contains(c: Char): Boolean {
211-
if (isEmpty) return false
211+
if (isEmpty) {
212+
return false
213+
}
212214
// binary search as MultiCharacterRange's ranges are ordered and non-overlapping
213-
return ranges.binarySearch { (start, end) ->
214-
if(c in start..end) {
215-
0
216-
} else if (c < start) {
217-
-1
218-
} else {
219-
1
215+
val index = ranges.binarySearch { (start, end) ->
216+
when {
217+
c < start -> 1 // Target is before this range, search left
218+
c > end -> -1 // Target is after this range, search right
219+
else -> 0 // Target is inside this range, match
220220
}
221-
} >= 0
221+
}
222+
return index >= 0
222223
}
223224

224225
val isEmpty: Boolean get() = ranges.isEmpty()

0 commit comments

Comments
 (0)