Skip to content

Commit 9d08eca

Browse files
committed
Javadocs and default char for safeVariableName
1 parent 7ab8319 commit 9d08eca

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

core/src/main/kotlin/org/evomaster/core/llm/Prompts.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ object Prompts {
9999
return Pair(VALUE_BASED_ON_NAME_FAILURE, error)
100100
}
101101

102+
/**
103+
* Used for prompting an LLM to return a new test case name
104+
* @param targetLanguage the target language of the test case, used by the LLM to return a name following naming conventions of the language
105+
* @param remainingNameChars the maximum amount of chars the returned test case name should have
106+
* @param generatedNames set of already returned names from the LLM to avoid duplication of names
107+
* @param testLines test case content to feed the LLM context for generating a test case name
108+
*
109+
* @return [Pair] containing the system prompt with all the scaffolding and rules as first and the user message with the current test information as second.
110+
*/
102111
fun getPromptForTestCaseName(targetLanguage: String, remainingNameChars: Int, generatedNames: MutableSet<String>, testLines: String): Pair<String,String>{
103112
val userMessage = """Your input is
104113
[targetLanguage]:$targetLanguage"

core/src/main/kotlin/org/evomaster/core/output/TestWriterUtils.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ object TestWriterUtils {
127127

128128
/**
129129
* Some character shouldn't be used for variable names, as it would lead to compilation/runtime errors.
130-
* Those are replaced with safe ones
130+
* Those are replaced with [replacementChar], which by default is '_'.
131131
*/
132-
fun safeVariableName(name: String): String {
132+
fun safeVariableName(name: String, replacementChar: String = "_"): String {
133133

134-
val safe = name.replace(Regex("[^0-9a-zA-Z_]"), "_")
134+
val safe = name.replace(Regex("[^0-9a-zA-Z_]"), replacementChar)
135135
val first = safe.codePointAt(0)
136136
if(first >= '0'.code && first <= '9'.code ) {
137137
//can't start a variable name with a number

core/src/main/kotlin/org/evomaster/core/output/naming/LlmServiceTestCaseNamingStrategy.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,9 @@ class LlmServiceTestCaseNamingStrategy(
4545
return newName
4646
}
4747

48-
// LLM is sometimes returning names as "\n\ntheNewName" so we need to fix that.
49-
// Also, some tests were ending as "200__" so we remove any trailing underscores.
48+
// LLM is sometimes returning names as "\n\ntheNewName_" so we need to fix that and return "theNewName".
5049
private fun sanitizeName(testName: String): String {
51-
var safeName = TestWriterUtils.safeVariableName(testName.trim().replace("\n", ""))
52-
while (safeName.endsWith("_")) {
53-
safeName = safeName.substringBeforeLast("_")
54-
}
55-
return safeName
50+
return TestWriterUtils.safeVariableName(testName.trim().replace("\n", ""), "")
5651
}
5752

5853
private fun getNewName(test: TestCase): String {

0 commit comments

Comments
 (0)