Numbers are acceptable in the method name
fixes gh-518
This commit is contained in:
@@ -116,8 +116,7 @@ class NamesUtil {
|
||||
* Converts illegal characters in method names to underscores
|
||||
*/
|
||||
static String convertIllegalMethodNameChars(String methodName) {
|
||||
String result = methodName.replaceAll('^[^a-zA-Z_$]', '_')
|
||||
result = result.replaceAll('[^a-zA-Z_$0-9]', '_')
|
||||
return result
|
||||
String result = methodName.replaceAll('^[^a-zA-Z_$0-9]', '_')
|
||||
return result.replaceAll('[^a-zA-Z_$0-9]', '_')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,11 @@ class MethodBuilderSpec extends Specification {
|
||||
}
|
||||
ContractMetadata metadata = new ContractMetadata(null, false, 0, null, contractDsl)
|
||||
when:
|
||||
File stubFile = new File("5invalid-method:name.groovy")
|
||||
File stubFile = new File("invalid-method:name.groovy")
|
||||
|
||||
String methodName = MethodBuilder.methodName(metadata, stubFile, contractDsl)
|
||||
then:
|
||||
methodName.equals("_invalid_method_name")
|
||||
methodName == "invalid_method_name"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -109,6 +109,6 @@ class NamesUtilSpec extends Specification {
|
||||
given:
|
||||
String string = '10a-b c.1.0.x+d1174$dd'
|
||||
expect:
|
||||
NamesUtil.convertIllegalMethodNameChars(string) == '_0a_b_c_1_0_x_d1174$dd'
|
||||
NamesUtil.convertIllegalMethodNameChars(string) == '10a_b_c_1_0_x_d1174$dd'
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user