Skip to content

Commit

Permalink
update decapitalization mechanism
Browse files Browse the repository at this point in the history
Signed-off-by: Julia Plewa <jplewa@virtuslab.com>
  • Loading branch information
jplewa committed Jul 19, 2023
1 parent 1f235bf commit b302703
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,10 @@ data class PulumiName(

fun toResourceFunctionName(namingFlags: NamingFlags): String {
val resourceName = toResourceName(namingFlags)
val numberOfCaps = resourceName.takeWhile { it.isUpperCase() }.count()
return if (numberOfCaps > 1) {
val numberOfCaps = resourceName.takeWhile { it.isUpperCase() || it.isDigit() }.count()
return if (numberOfCaps == resourceName.length) {
resourceName.lowercase()
} else if (numberOfCaps > 1) {
resourceName.lowercaseBefore(numberOfCaps - 1)
} else {
resourceName.decapitalize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,21 @@ internal class PulumiNameTest {
assertEquals("iamBinding", resourceFunctionName)
}

@Test
fun `a resource function name that is a three-letter acronym is decapitalized correctly`() {
// given
val token = "provider:module:CRL"
val namingConfiguration = PulumiNamingConfiguration.create(providerName = "provider")

// when
val pulumiName = PulumiName.from(token, namingConfiguration)
val namingFlags = NamingFlags(Root, Resource, Input, Java)
val resourceFunctionName = pulumiName.toResourceFunctionName(namingFlags)

// then
assertEquals("crl", resourceFunctionName)
}

@Test
fun `a resource function name starting with a two-letter acronym and number is decapitalized correctly`() {
// given
Expand All @@ -598,6 +613,6 @@ internal class PulumiNameTest {
val resourceFunctionName = pulumiName.toResourceFunctionName(namingFlags)

// then
assertEquals("eC2Fleet", resourceFunctionName)
assertEquals("ec2Fleet", resourceFunctionName)
}
}

0 comments on commit b302703

Please sign in to comment.