Numbers are acceptable in the method name

fixes gh-518
This commit is contained in:
Marcin Grzejszczak
2018-01-16 17:19:47 +01:00
parent 470faf7523
commit 3c0dcad1d6
3 changed files with 6 additions and 6 deletions

View File

@@ -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]', '_')
}
}

View File

@@ -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"
}
}

View File

@@ -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'
}
}