Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
References #29
  • Loading branch information
Steve Moyer committed Oct 29, 2019
1 parent f642afe commit 2994ccb
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/ap/aliased_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ap_test

import "encoding/json"

type Real struct {
FieldA string `json:"fieldA"`
AP map[string]json.RawMessage `json:"*"`
}

type Alias Real

// alias := struct {
// *Alias
// }{
// Alias: (*Alias)(u),
// }

func NewZeroAlias() interface{} {
z := (Alias)(Real{})
return &z
}

func NewTestAlias() interface{} {
t := (Alias)(Real{
FieldA: "Field A",
AP: map[string]json.RawMessage{
"fieldB": json.RawMessage([]byte("\"Field B\"")),
"fieldC": json.RawMessage([]byte("\"Field C\"")),
},
})
return &t
}
24 changes: 24 additions & 0 deletions pkg/ap/anonymous_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ap_test

import "encoding/json"

func NewZeroAnonymous() interface{} {
return &struct {
*Alias
}{
Alias: (*Alias)(&Real{}),
}
}

func NewTestAnonymous() interface{} {
return struct {
Alias
}{
Alias: (Alias)(Real{
FieldA: "Field A",
AP: map[string]json.RawMessage{
"fieldB": json.RawMessage([]byte("\"Field B\"")),
"fieldC": json.RawMessage([]byte("\"Field C\"")),
}}),
}
}
2 changes: 2 additions & 0 deletions pkg/ap/jsoniter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var cases = []struct {
{"No additional properties", "noap.json", "noap.json", NewTestSimpleWithoutAP, NewZeroSimple},
{"Respects omitempty", "omitempty.json", "omitempty.json", NewTestOmitEmpty, NewZeroOmitEmpty},
{"Embedded struct with AP", "embedded.json", "embedded.json", NewTestOuter, NewZeroOuter},
{"Aliased AP", "aliased.json", "aliased.json", NewTestAlias, NewZeroAlias},
// {"Anonymous aliased AP", "anonymous.json", "anonymous.json", NewTestAnonymous, NewZeroAnonymous},
}

func TestMarshaling(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions pkg/ap/testdata/aliased.json.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"fieldA":"Field A","fieldB":"Field B","fieldC":"Field C"}
1 change: 1 addition & 0 deletions pkg/ap/testdata/anonymous.json.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"fieldA":"Field A","fieldB":"Field B","fieldC":"Field C"}

0 comments on commit 2994ccb

Please sign in to comment.