Skip to content

Commit

Permalink
Add line and column number to MapItem instances
Browse files Browse the repository at this point in the history
  • Loading branch information
clarete committed Jul 7, 2015
1 parent f3f14c9 commit c247778
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ func (d *decoder) mappingSlice(n *node, out reflect.Value) (good bool) {
d.merge(n.children[i+1], out)
continue
}
item := MapItem{}
item := MapItem{Line: n.line, Col: n.column}
k := reflect.ValueOf(&item.Key).Elem()
if d.unmarshal(n.children[i], k) {
v := reflect.ValueOf(&item.Value).Elem()
Expand Down
2 changes: 1 addition & 1 deletion decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ var unmarshalTests = []struct {
// Ordered maps.
{
"{b: 2, a: 1, d: 4, c: 3, sub: {e: 5}}",
&yaml.MapSlice{{"b", 2}, {"a", 1}, {"d", 4}, {"c", 3}, {"sub", yaml.MapSlice{{"e", 5}}}},
&yaml.MapSlice{{"b", 2, 0, 0}, {"a", 1, 0, 0}, {"d", 4, 0, 0}, {"c", 3, 0, 0}, {"sub", yaml.MapSlice{{"e", 5, 0, 30}}, 0, 0}},
},

// Issue #39.
Expand Down
2 changes: 1 addition & 1 deletion encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ var marshalTests = []struct {

// Ordered maps.
{
&yaml.MapSlice{{"b", 2}, {"a", 1}, {"d", 4}, {"c", 3}, {"sub", yaml.MapSlice{{"e", 5}}}},
&yaml.MapSlice{{"b", 2, 0, 0}, {"a", 1, 0, 0}, {"d", 4, 0, 0}, {"c", 3, 0, 0}, {"sub", yaml.MapSlice{{"e", 5, 0, 0}}, 0, 0}},
"b: 2\na: 1\nd: 4\nc: 3\nsub:\n e: 5\n",
},

Expand Down
1 change: 1 addition & 0 deletions yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type MapSlice []MapItem
// MapItem is an item in a MapSlice.
type MapItem struct {
Key, Value interface{}
Line, Col int
}

// The Unmarshaler interface may be implemented by types to customize their
Expand Down

0 comments on commit c247778

Please sign in to comment.