Skip to content

Commit

Permalink
Merge aa38399 into 993a605
Browse files Browse the repository at this point in the history
  • Loading branch information
chengs041021 committed Mar 26, 2020
2 parents 993a605 + aa38399 commit eb1cbf3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
5 changes: 3 additions & 2 deletions codegen/type_converter.go
Expand Up @@ -807,9 +807,10 @@ func (c *TypeConverter) genStructConverter(
return err
}
case *compile.BinarySpec:
// TODO: handle override. Check if binarySpec can be optional.
for _, line := range checkOptionalNil(indent, c.uninitialized, toIdentifier, prevKeyPrefixes, c.useRecurGen) {
c.append(line)
}
c.append(toIdentifier, " = []byte(", fromIdentifier, ")")

case *compile.StructSpec:
var (
stFromPrefix = fromPrefix
Expand Down
43 changes: 43 additions & 0 deletions codegen/type_converter_test.go
Expand Up @@ -3592,3 +3592,46 @@ func TestNestedMapOfListOfMapInvalid(t *testing.T) {

assert.Error(t, err)
}

func TestConverterMapNestedBinary(t *testing.T) {
fieldMap := make(map[string]codegen.FieldMapperEntry)
fieldMap["NestedTwo.NestedNestedTwo.Two"] = codegen.FieldMapperEntry{
QualifiedName: "Two",
Override: false,
}

lines, err := convertTypes(
"Foo", "Bar",
`struct Foo {
1: optional string one
2: optional binary two
}
struct NestedBar {
1: optional NestedNestedBar nestedNestedTwo
}
struct NestedNestedBar {
1: optional binary two
}
struct Bar {
1: optional string one
2: optional NestedBar nestedTwo
}`,
nil,
fieldMap,
)

assert.NoError(t, err)
assertPrettyEqual(t, trim(`
out.One = (*string)(in.One)
if out.NestedTwo == nil {
out.NestedTwo = &structs.NestedBar{}
}
if out.NestedTwo.NestedNestedTwo == nil {
out.NestedTwo.NestedNestedTwo = &structs.NestedNestedBar{}
}
out.NestedTwo.NestedNestedTwo.Two = []byte(in.Two)
`), lines)
}

0 comments on commit eb1cbf3

Please sign in to comment.