-
Notifications
You must be signed in to change notification settings - Fork 45
Use regex for generating string when regex pattern is found #778 #793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Markoutte
merged 1 commit into
main
from
778_Use_regex_for_generating_string_when_regex_pattern_is_found
Aug 26, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
utbot-fuzzers/src/main/kotlin/org/utbot/fuzzer/FuzzedConcreteValue.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.utbot.fuzzer | ||
|
||
import org.utbot.framework.plugin.api.ClassId | ||
|
||
/** | ||
* Object to pass concrete values to fuzzer | ||
*/ | ||
data class FuzzedConcreteValue( | ||
val classId: ClassId, | ||
val value: Any, | ||
val fuzzedContext: FuzzedContext = FuzzedContext.Unknown, | ||
) |
45 changes: 45 additions & 0 deletions
45
utbot-fuzzers/src/main/kotlin/org/utbot/fuzzer/FuzzedContext.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.utbot.fuzzer | ||
|
||
import org.utbot.framework.plugin.api.ExecutableId | ||
|
||
/** | ||
* Context is a bit of information about [FuzzedConcreteValue]'s conditions. | ||
* | ||
* For example, it can be: | ||
* | ||
* 1. Comparison operations: `a > 2` | ||
* 2. Method call: `Double.isNaN(2.0)` | ||
*/ | ||
sealed interface FuzzedContext { | ||
|
||
object Unknown : FuzzedContext | ||
|
||
class Call( | ||
val method: ExecutableId | ||
) : FuzzedContext { | ||
override fun toString(): String { | ||
return method.toString() | ||
} | ||
} | ||
|
||
enum class Comparison( | ||
val sign: String | ||
) : FuzzedContext { | ||
EQ("=="), | ||
NE("!="), | ||
GT(">"), | ||
GE(">="), | ||
LT("<"), | ||
LE("<="), | ||
; | ||
|
||
fun reverse(): Comparison = when (this) { | ||
EQ -> NE | ||
NE -> EQ | ||
GT -> LE | ||
LT -> GE | ||
LE -> GT | ||
GE -> LT | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
utbot-fuzzers/src/main/kotlin/org/utbot/fuzzer/mutators/RegexStringModelMutator.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.utbot.fuzzer.mutators | ||
|
||
import com.github.curiousoddman.rgxgen.RgxGen | ||
import org.utbot.framework.plugin.api.UtPrimitiveModel | ||
import org.utbot.fuzzer.FuzzedMethodDescription | ||
import org.utbot.fuzzer.FuzzedValue | ||
import org.utbot.fuzzer.ModelMutator | ||
import org.utbot.fuzzer.providers.RegexFuzzedValue | ||
import org.utbot.fuzzer.providers.RegexModelProvider | ||
import kotlin.random.Random | ||
import kotlin.random.asJavaRandom | ||
|
||
/** | ||
* Provides different regex value for a concrete regex pattern | ||
*/ | ||
object RegexStringModelMutator : ModelMutator { | ||
|
||
override fun mutate( | ||
description: FuzzedMethodDescription, | ||
index: Int, | ||
value: FuzzedValue, | ||
random: Random | ||
): FuzzedValue? { | ||
if (value is RegexFuzzedValue) { | ||
val string = RgxGen(value.regex).apply { | ||
setProperties(RegexModelProvider.rgxGenProperties) | ||
}.generate(random.asJavaRandom()) | ||
return RegexFuzzedValue(UtPrimitiveModel(string).mutatedFrom(value) { | ||
summary = "%var% = mutated regex ${value.regex}" | ||
}, value.regex) | ||
} | ||
return null | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Java
Comparator<T>
interface (and its counterpart in the Kotlin stdlib) hasreversed
method that returns a comparator with reverse ordering. What do you think about usingreversed()
instead ofreverse()
here? I think it could be a bit more readable (at least it would be for me -- I used to read 'reverse()` as an in-place operation on collections).