Skip to content

Commit

Permalink
Don't remove existing capitals in python names
Browse files Browse the repository at this point in the history
  • Loading branch information
iwahbe committed Oct 17, 2022
1 parent cf8e8f1 commit b612ce6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
@@ -0,0 +1,4 @@
changes:
- type: fix
scope: sdkgen/go,python
description: Handle hypheneated names in go and python
2 changes: 1 addition & 1 deletion pkg/codegen/python/utilities.go
Expand Up @@ -197,6 +197,6 @@ func pythonCase(s string) string {
underscores += "_"
return true
})
c := cgstrings.Camel(noUnderscores)
c := cgstrings.Unhyphenate(noUnderscores)
return underscores + cgstrings.UppercaseFirst(c)
}
18 changes: 18 additions & 0 deletions pkg/codegen/python/utilities_test.go
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/blang/semver"
"github.com/stretchr/testify/assert"

"github.com/hashicorp/hcl/v2"
"github.com/pulumi/pulumi/pkg/v3/codegen/hcl2/syntax"
Expand Down Expand Up @@ -101,3 +102,20 @@ func TestMakePyPiVersion(t *testing.T) {
})
}
}

func TestPythonCase(t *testing.T) {
t.Parallel()

tests := []struct{ input, expected string }{
{"FOOBarInput", "FOOBarInput"},
{"foo-bar", "FooBar"},
}

for _, tt := range tests {
tt := tt
t.Run(tt.input, func(t *testing.T) {
t.Parallel()
assert.Equal(t, tt.expected, pythonCase(tt.input))
})
}
}

0 comments on commit b612ce6

Please sign in to comment.