Skip to content

Commit

Permalink
Remove tag handling without identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy committed Nov 13, 2019
1 parent 55061cf commit be91749
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ func TestDecoder(t *testing.T) {
{
"a: 1",
struct {
B int "a"
B int `yaml:"a"`
}{1},
},

Expand Down
28 changes: 14 additions & 14 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,78 +212,78 @@ func TestEncoder(t *testing.T) {
{
"a: 1\n",
struct {
A int "a,omitempty"
B int "b,omitempty"
A int `yaml:"a,omitempty"`
B int `yaml:"b,omitempty"`
}{1, 0},
},
{
"{}\n",
struct {
A int "a,omitempty"
B int "b,omitempty"
A int `yaml:"a,omitempty"`
B int `yaml:"b,omitempty"`
}{0, 0},
},

{
"a: {x: 1}\n",
struct {
A *struct{ X, y int } "a,omitempty,flow"
A *struct{ X, y int } `yaml:"a,omitempty,flow"`
}{&struct{ X, y int }{1, 2}},
},

{
"{}\n",
struct {
A *struct{ X, y int } "a,omitempty,flow"
A *struct{ X, y int } `yaml:"a,omitempty,flow"`
}{nil},
},

{
"a: {x: 0}\n",
struct {
A *struct{ X, y int } "a,omitempty,flow"
A *struct{ X, y int } `yaml:"a,omitempty,flow"`
}{&struct{ X, y int }{}},
},

{
"a: {x: 1}\n",
struct {
A struct{ X, y int } "a,omitempty,flow"
A struct{ X, y int } `yaml:"a,omitempty,flow"`
}{struct{ X, y int }{1, 2}},
},
{
"{}\n",
struct {
A struct{ X, y int } "a,omitempty,flow"
A struct{ X, y int } `yaml:"a,omitempty,flow"`
}{struct{ X, y int }{0, 1}},
},
{
"a: 1.0\n",
struct {
A float64 "a,omitempty"
B float64 "b,omitempty"
A float64 `yaml:"a,omitempty"`
B float64 `yaml:"b,omitempty"`
}{1, 0},
},

// Flow flag
{
"a: [1, 2]\n",
struct {
A []int "a,flow"
A []int `yaml:"a,flow"`
}{[]int{1, 2}},
},
{
"a: {b: c, d: e}\n",
&struct {
A map[string]string "a,flow"
A map[string]string `yaml:"a,flow"`
}{map[string]string{"b": "c", "d": "e"}},
},
{
"a: {b: c, d: e}\n",
struct {
A struct {
B, D string
} "a,flow"
} `yaml:"a,flow"`
}{struct{ B, D string }{"c", "e"}},
},

Expand Down
3 changes: 0 additions & 3 deletions struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ type StructField struct {

func structField(field reflect.StructField) *StructField {
tag := field.Tag.Get(StructTagName)
if tag == "" && strings.Index(string(field.Tag), ":") < 0 {
tag = string(field.Tag)
}
fieldName := strings.ToLower(field.Name)
options := strings.Split(tag, ",")
if len(options) > 0 {
Expand Down

0 comments on commit be91749

Please sign in to comment.