-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from moznion/do_not_panic_when_struct_prop_doe…
…s_not_have_tag Make the code generation not panic when the struct property doesn't have a tag
- Loading branch information
Showing
5 changed files
with
62 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package tests | ||
|
||
// see: https://github.com/moznion/go-json-ice/issues/24 | ||
// | ||
//go:generate sh -c "$(cd ./\"$(git rev-parse --show-cdup)\" || exit; pwd)/dist/json-ice_test --type=Issue24Struct" | ||
type Issue24Struct struct { | ||
Foo string `json:"foo"` | ||
Bar string | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package tests | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// see: https://github.com/moznion/go-json-ice/issues/24 | ||
func TestMarshalIssue24StructAsJSON(t *testing.T) { | ||
given := &Issue24Struct{ | ||
Foo: "foo", | ||
Bar: "bar", | ||
} | ||
|
||
serialized, err := MarshalIssue24StructAsJSON(given) | ||
assert.NoError(t, err) | ||
|
||
var got Issue24Struct | ||
err = json.Unmarshal(serialized, &got) | ||
assert.NoError(t, err) | ||
assert.EqualValues(t, Issue24Struct{ | ||
Foo: "foo", | ||
// `Bar` should be dropped because this property doesn't have a tag for JSON serialization. | ||
}, got) | ||
} |