diff --git a/src/main/kotlin/org/virtuslab/pulumikotlin/codegen/step2intermediate/PulumiName.kt b/src/main/kotlin/org/virtuslab/pulumikotlin/codegen/step2intermediate/PulumiName.kt index b2d847a55..c6a4409aa 100644 --- a/src/main/kotlin/org/virtuslab/pulumikotlin/codegen/step2intermediate/PulumiName.kt +++ b/src/main/kotlin/org/virtuslab/pulumikotlin/codegen/step2intermediate/PulumiName.kt @@ -204,6 +204,7 @@ data class PulumiName( } fun toResourceFunctionName(namingFlags: NamingFlags): String { + require(namingFlags.language == Kotlin) val resourceName = toResourceName(namingFlags) val numberOfCaps = resourceName.takeWhile { it.isUpperCase() || it.isDigit() }.count() return if (numberOfCaps == resourceName.length) { diff --git a/src/test/kotlin/org/virtuslab/pulumikotlin/codegen/step2intermediate/PulumiNameTest.kt b/src/test/kotlin/org/virtuslab/pulumikotlin/codegen/step2intermediate/PulumiNameTest.kt index b1fc5db0b..566effbd2 100644 --- a/src/test/kotlin/org/virtuslab/pulumikotlin/codegen/step2intermediate/PulumiNameTest.kt +++ b/src/test/kotlin/org/virtuslab/pulumikotlin/codegen/step2intermediate/PulumiNameTest.kt @@ -564,13 +564,28 @@ internal class PulumiNameTest { // when val pulumiName = PulumiName.from(token, namingConfiguration) - val namingFlags = NamingFlags(Root, Resource, Input, Java) + val namingFlags = NamingFlags(Root, Resource, Input, Kotlin) val resourceFunctionName = pulumiName.toResourceFunctionName(namingFlags) // then assertEquals("organizationPolicy", resourceFunctionName) } + @Test + fun `a resource function name starting with a two-letter acronym is decapitalized correctly`() { + // given + val token = "provider:module:VMwareCluster" + val namingConfiguration = PulumiNamingConfiguration.create(providerName = "provider") + + // when + val pulumiName = PulumiName.from(token, namingConfiguration) + val namingFlags = NamingFlags(Root, Resource, Input, Kotlin) + val resourceFunctionName = pulumiName.toResourceFunctionName(namingFlags) + + // then + assertEquals("vMwareCluster", resourceFunctionName) + } + @Test fun `a resource function name starting with a three-letter acronym is decapitalized correctly`() { // given @@ -579,7 +594,7 @@ internal class PulumiNameTest { // when val pulumiName = PulumiName.from(token, namingConfiguration) - val namingFlags = NamingFlags(Root, Resource, Input, Java) + val namingFlags = NamingFlags(Root, Resource, Input, Kotlin) val resourceFunctionName = pulumiName.toResourceFunctionName(namingFlags) // then @@ -594,7 +609,7 @@ internal class PulumiNameTest { // when val pulumiName = PulumiName.from(token, namingConfiguration) - val namingFlags = NamingFlags(Root, Resource, Input, Java) + val namingFlags = NamingFlags(Root, Resource, Input, Kotlin) val resourceFunctionName = pulumiName.toResourceFunctionName(namingFlags) // then @@ -609,7 +624,7 @@ internal class PulumiNameTest { // when val pulumiName = PulumiName.from(token, namingConfiguration) - val namingFlags = NamingFlags(Root, Resource, Input, Java) + val namingFlags = NamingFlags(Root, Resource, Input, Kotlin) val resourceFunctionName = pulumiName.toResourceFunctionName(namingFlags) // then diff --git a/src/test/kotlin/org/virtuslab/pulumikotlin/codegen/utils/StringUtilsKtTest.kt b/src/test/kotlin/org/virtuslab/pulumikotlin/codegen/utils/StringUtilsKtTest.kt index 1da41b1f7..eb8796801 100644 --- a/src/test/kotlin/org/virtuslab/pulumikotlin/codegen/utils/StringUtilsKtTest.kt +++ b/src/test/kotlin/org/virtuslab/pulumikotlin/codegen/utils/StringUtilsKtTest.kt @@ -28,8 +28,23 @@ internal class StringUtilsKtTest { } @Test - fun `should turn the expected number of character lowercase`() { - assertEquals("sslCertificate", "SSLCertificate".lowercaseBefore(3)) + fun `should do nothing when trying to turn all characters before index=0 lowercase`() { + assertEquals("ABCD", "ABCD".lowercaseBefore(index = 0)) + } + + @Test + fun `should turn all characters before index=1 lowercase`() { + assertEquals("aBCD", "ABCD".lowercaseBefore(index = 1)) + } + + @Test + fun `should turn all characters before index=3 lowercase`() { + assertEquals("abcD", "ABCD".lowercaseBefore(index = 3)) + } + + @Test + fun `should turn all characters before index=4 to lower case in a string with 4 characters`() { + assertEquals("abcd", "ABCD".lowercaseBefore(index = 4)) } @Suppress("unused")