Skip to content

Commit

Permalink
enum: properly prefix validation function name (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodaine authored Oct 30, 2018
1 parent 1e3afd7 commit e143189
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
7 changes: 5 additions & 2 deletions templates/cc/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,12 @@ func (fns CCFuncs) output(file pgs.File, ext string) string {
}

func (fns CCFuncs) Type(f pgs.Field) pgsgo.TypeName {
typ := fns.Context.Type(f)

if f.Type().IsEnum() {
return pgsgo.TypeName(pgsgo.PGGUpperCamelCase(f.Type().Enum().Name()))
parts := strings.Split(typ.String(), ".")
typ = pgsgo.TypeName(parts[len(parts)-1])
}

return fns.Context.Type(f)
return typ
}
2 changes: 1 addition & 1 deletion tests/harness/cases/enums.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ message EnumAliasIn { TestEnumAlias val = 1 [(validate.rules).enum = { in: [0, 2
message EnumNotIn { TestEnum val = 1 [(validate.rules).enum = { not_in: [1]}];}
message EnumAliasNotIn { TestEnumAlias val = 1 [(validate.rules).enum = { not_in: [1]}]; }

message EnumExternal { other_package.Enumerated val = 1 [(validate.rules).enum.defined_only = true]; }
message EnumExternal { other_package.Embed.Enumerated val = 1 [(validate.rules).enum.defined_only = true]; }
6 changes: 4 additions & 2 deletions tests/harness/cases/other_package/embed.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ option go_package = "other_package";
import "validate/validate.proto";

// Validate message embedding across packages.
message Embed { int64 val = 1 [(validate.rules).int64.gt = 0]; }
message Embed {
int64 val = 1 [(validate.rules).int64.gt = 0];

enum Enumerated { VALUE = 0; }
enum Enumerated { VALUE = 0; }
}
2 changes: 1 addition & 1 deletion tests/harness/executor/cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ var enumCases = []TestCase{
{"enum alias - not in - invalid", &cases.EnumAliasNotIn{Val: cases.TestEnumAlias_B}, false},
{"enum alias - not in - invalid (alias)", &cases.EnumAliasNotIn{Val: cases.TestEnumAlias_BETA}, false},

{"enum external - defined_only - valid", &cases.EnumExternal{Val: other_package.Enumerated_VALUE}, true},
{"enum external - defined_only - valid", &cases.EnumExternal{Val: other_package.Embed_VALUE}, true},
{"enum external - defined_only - invalid", &cases.EnumExternal{Val: math.MaxInt32}, false},
}

Expand Down

0 comments on commit e143189

Please sign in to comment.