Skip to content

Commit

Permalink
feat(go): preserve casing of enum member names (#2598)
Browse files Browse the repository at this point in the history
As suggested in aws/aws-cdk-rfcs#292, using `_` to separate the constant
name from the type name, and preserving the constant's casing results in
an API that is slightly more readable, and less prone to namespace
collisions.
  • Loading branch information
RomainMuller authored Feb 25, 2021
1 parent 6747f12 commit efdc165
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 59 deletions.
14 changes: 7 additions & 7 deletions packages/@jsii/go-runtime/jsii-calc-test/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,20 @@ func TestAllTypes(t *testing.T) {

func TestEnumUnmarshal(t *testing.T) {
actual := calc.EnumDispenser_RandomStringLikeEnum()
if actual != calc.StringEnumB {
if actual != calc.StringEnum_B {
t.Errorf("Expected StringEnum.B. Actual: %s", actual)
}
}

func TestEnumRoundtrip(t *testing.T) {
allTypes := calc.NewAllTypes()
actual := allTypes.EnumMethod(calc.StringEnumA)
if actual != calc.StringEnumA {
actual := allTypes.EnumMethod(calc.StringEnum_A)
if actual != calc.StringEnum_A {
t.Errorf("Expected StringEnum.A. Actual: %s", actual)
}

actual = allTypes.EnumMethod(calc.StringEnumC)
if actual != calc.StringEnumC {
actual = allTypes.EnumMethod(calc.StringEnum_C)
if actual != calc.StringEnum_C {
t.Errorf("Expected StringEnum.C. Actual: %s", actual)
}
}
Expand All @@ -184,9 +184,9 @@ func TestOptionalEnums(t *testing.T) {
t.Error("Expected value to be nil")
}

allTypes.SetOptionalEnumValue(calc.StringEnumB)
allTypes.SetOptionalEnumValue(calc.StringEnum_B)
actual = allTypes.GetOptionalEnumValue()
if actual != calc.StringEnumB {
if actual != calc.StringEnum_B {
t.Errorf("Expected StringEnum.B. Actual: %s", actual)
}

Expand Down
4 changes: 2 additions & 2 deletions packages/jsii-pacmak/lib/targets/go/types/enum.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodeMaker, toPascalCase } from 'codemaker';
import { CodeMaker } from 'codemaker';
import { EnumType, EnumMember } from 'jsii-reflect';

import { EmitContext } from '../emit-context';
Expand Down Expand Up @@ -59,7 +59,7 @@ class GoEnumMember {
public readonly rawValue: string;

public constructor(private readonly parent: Enum, entry: EnumMember) {
this.name = `${parent.name}${toPascalCase(entry.name)}`;
this.name = `${parent.name}_${entry.name}`;
this.rawValue = entry.name;
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit efdc165

Please sign in to comment.