From b612ce6bfc081b3c28e78e536b8ef8331bcfbf6a Mon Sep 17 00:00:00 2001 From: Ian Wahbe Date: Mon, 17 Oct 2022 09:43:23 -0700 Subject: [PATCH] Don't remove existing capitals in python names --- ...gen-go-python--handle-hyphenated-names.yaml | 4 ++++ pkg/codegen/python/utilities.go | 2 +- pkg/codegen/python/utilities_test.go | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 changelog/pending/20221017--sdkgen-go-python--handle-hyphenated-names.yaml diff --git a/changelog/pending/20221017--sdkgen-go-python--handle-hyphenated-names.yaml b/changelog/pending/20221017--sdkgen-go-python--handle-hyphenated-names.yaml new file mode 100644 index 000000000000..43ac9f52516f --- /dev/null +++ b/changelog/pending/20221017--sdkgen-go-python--handle-hyphenated-names.yaml @@ -0,0 +1,4 @@ +changes: +- type: fix + scope: sdkgen/go,python + description: Handle hypheneated names in go and python diff --git a/pkg/codegen/python/utilities.go b/pkg/codegen/python/utilities.go index 6f5325b9a99d..911bded0e697 100644 --- a/pkg/codegen/python/utilities.go +++ b/pkg/codegen/python/utilities.go @@ -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) } diff --git a/pkg/codegen/python/utilities_test.go b/pkg/codegen/python/utilities_test.go index 313df023733b..4fc5c0ff812f 100644 --- a/pkg/codegen/python/utilities_test.go +++ b/pkg/codegen/python/utilities_test.go @@ -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" @@ -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)) + }) + } +}